Skip to content

Commit

Permalink
try to fix screen
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed May 20, 2022
1 parent f2ef6e0 commit 654c963
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ public BaseInventoryTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState
public abstract @NotNull BaseItemStackHandler getInventory();

@Override
public void load(CompoundTag tag) {
public void load(@NotNull CompoundTag tag) {
super.load(tag);
this.getInventory().deserializeNBT(tag);
}

public void saveAdditional(CompoundTag tag) {
@Override
public void saveAdditional(@NotNull CompoundTag tag) {
super.saveAdditional(tag);
tag.merge(this.getInventory().serializeNBT());
}

@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> cap, Direction side) {
return !this.isRemoved() && cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.orEmpty(cap, this.capability) : super.getCapability(cap, side);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public BaseTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this, BlockEntity::saveWithFullMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ public void render(@NotNull PoseStack matrix, int mouseX, int mouseY, float part
this.renderComponentTooltip(matrix, tooltip, mouseX, mouseY);
}

if (mouseX > x + 89 && mouseX < x + 110 && mouseY > y + 35 && mouseY < y + 51) {
List<Component> tooltip = new ArrayList<>();

if (this.getProgress() < 1) {
tooltip.add(ModTooltips.PROGRESS_EMPTY.color(ChatFormatting.WHITE).build());
} else {

var text = new TextComponent(number(this.getProgress()) + " / " + number(this.getTimeRequired()));

tooltip.add(text);
}

this.renderComponentTooltip(matrix, tooltip, mouseX, mouseY);
}

// if (mouseX > x + 68 && mouseX < x + 79 && mouseY > y + 28 && mouseY < y + 39) {
// if (this.isEjecting()) {
// this.renderTooltip(matrix, ModTooltips.EJECTING.color(ChatFormatting.WHITE).build(), mouseX, mouseY);
Expand Down Expand Up @@ -165,7 +180,7 @@ public int getProgress() {
if (this.tile == null)
return 0;

return this.tile.getProgress();
return this.menu.getProgress();
}

public int getMaterialCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ protected void renderBg(@NotNull PoseStack pPoseStack, float pPartialTick, int p
int j = this.getGuiTop();
blit(pPoseStack, i, j, 0.0F, 0.0F, 175, 165, 255, 255);
if (this.getProgress() > 0) {
int i2 = this.getProgressBarScaled(21);
this.blit(pPoseStack, i + 100, j + 48, 176, 0, i2 + 1, 16);
int i2 = this.getProgressBarScaled(16);
this.blit(pPoseStack, i + 100, j + 47 - i2, 176, 16 - i2, 3, i2);
}
this.blit(pPoseStack, i + 100, j + 48 - getProgressBarScaled(16), 176, 16 - getProgressBarScaled(16), 1, getProgressBarScaled(16));
//this.blit(pPoseStack, i + 100, j + 48 - getProgressBarScaled(16), 176, 16 - getProgressBarScaled(16), 1, getProgressBarScaled(16));
}

public int getProgress() {
if (this.tile == null)
return 0;

return this.tile.getProgress();
return this.menu.getProgress();
}

public int getTimeRequired() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import nova.committee.avaritia.common.tile.CompressorTileEntity;
import nova.committee.avaritia.init.registry.ModMenus;
import nova.committee.avaritia.util.item.BaseItemStackHandler;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

Expand Down Expand Up @@ -60,7 +61,7 @@ public static CompressorMenu create(int windowId, Inventory playerInventory, Fun
}

@Override
public ItemStack quickMoveStack(Player player, int slotNumber) {
public @NotNull ItemStack quickMoveStack(@NotNull Player player, int slotNumber) {
var itemstack = ItemStack.EMPTY;
var slot = this.slots.get(slotNumber);

Expand Down Expand Up @@ -108,11 +109,15 @@ public ItemStack quickMoveStack(Player player, int slotNumber) {
}

@Override
public boolean stillValid(Player player) {
public boolean stillValid(@NotNull Player player) {
return this.isUsableByPlayer.apply(player);
}

public BlockPos getPos() {
return this.pos;
}

public int getProgress() {
return data.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class NeutronCollectorMenu extends AbstractContainerMenu {
private final ContainerData data;
private final BlockPos pos;

private final NeutronCollectorTile tile;

private NeutronCollectorMenu(MenuType<?> type, int id, Inventory playerInventory, FriendlyByteBuf buffer) {
this(type, id, playerInventory, p -> false, NeutronCollectorTile.createInventoryHandler(null), new SimpleContainerData(10), buffer.readBlockPos());
}
Expand All @@ -36,7 +34,6 @@ protected NeutronCollectorMenu(MenuType<?> type, int id, Inventory playerInvento
this.isUsableByPlayer = isUsableByPlayer;
this.data = data;
this.pos = pos;
this.tile = (NeutronCollectorTile) playerInventory.player.level.getBlockEntity(pos);
this.addSlot(new OutputSlot(inventory, 0, 80, 32));

for (int i = 0; i < 3; i++) {
Expand All @@ -61,7 +58,7 @@ public static NeutronCollectorMenu create(int windowId, Inventory playerInventor
}

@Override
public boolean stillValid(Player player) {
public boolean stillValid(@NotNull Player player) {
return this.isUsableByPlayer.apply(player);
}

Expand Down Expand Up @@ -112,7 +109,7 @@ public BlockPos getPos() {
return itemstack;
}

public int getTimer() {
return (int) Math.ceil(tile.getProgress() / 3600.0 * 16);
public int getProgress() {
return data.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class CompressorTileEntity extends BaseInventoryTileEntity implements Men
private int progress;
private boolean ejecting = false;

private final SimpleContainerData data = new SimpleContainerData(1);

public CompressorTileEntity(BlockPos pos, BlockState state) {
super(ModTileEntities.compressor_tile, pos, state);
this.inventory = createInventoryHandler(null);
Expand Down Expand Up @@ -88,6 +90,8 @@ public static void tick(Level level, BlockPos pos, BlockState state, CompressorT

if (tile.recipe != null) {
if (tile.materialCount >= tile.recipe.getInputCount()) {
tile.progress++;
tile.data.set(0, tile.progress);
if (tile.progress >= tile.recipe.getTimeCost()) {
var result = tile.recipe.assemble(tile.inventory);

Expand All @@ -99,10 +103,9 @@ public static void tick(Level level, BlockPos pos, BlockState state, CompressorT
if (tile.materialCount <= 0) {
tile.materialStack = ItemStack.EMPTY;
}
if (!mark)
mark = true;
}
} else {
++tile.progress;
//tile.process(tile.recipe);
}
}
}
Expand Down Expand Up @@ -143,7 +146,7 @@ public static void tick(Level level, BlockPos pos, BlockState state, CompressorT
}

@Override
public void load(CompoundTag tag) {
public void load(@NotNull CompoundTag tag) {
super.load(tag);
this.materialCount = tag.getInt("MaterialCount");
this.materialStack = ItemStack.of(tag.getCompound("MaterialStack"));
Expand All @@ -152,7 +155,7 @@ public void load(CompoundTag tag) {
}

@Override
public void saveAdditional(CompoundTag tag) {
public void saveAdditional(@NotNull CompoundTag tag) {
super.saveAdditional(tag);
tag.putInt("MaterialCount", this.materialCount);
tag.put("MaterialStack", this.materialStack.serializeNBT());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import nova.committee.avaritia.init.registry.ModTileEntities;
import nova.committee.avaritia.util.item.BaseItemStackHandler;
import nova.committee.avaritia.util.lang.Localizable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -40,7 +41,7 @@ public static BaseItemStackHandler createInventoryHandler(Runnable onContentsCha
}

@Override
public BaseItemStackHandler getInventory() {
public @NotNull BaseItemStackHandler getInventory() {
return inventory;
}

Expand All @@ -56,7 +57,7 @@ public AbstractContainerMenu createMenu(int p_createMenu_1_, Inventory p_createM
}

@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> cap, Direction side) {
return !this.remove && cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? LazyOptional.empty() : super.getCapability(cap, side);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nova.committee.avaritia.common.tile;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -34,6 +35,8 @@ public class NeutronCollectorTile extends BaseInventoryTileEntity implements Men
private final BaseItemStackHandler inventory;
private int progress;

private SimpleContainerData data = new SimpleContainerData(1);

public NeutronCollectorTile(BlockPos pos, BlockState state) {
super(ModTileEntities.neutron_collector_tile, pos, state);
this.inventory = createInventoryHandler(null);
Expand All @@ -44,7 +47,9 @@ public static void tick(Level level, BlockPos pos, BlockState state, NeutronColl
if (tile.canWork()) {
var result = tile.inventory.getStackInSlot(0);
var stack = new ItemStack(ModItems.neutron_pile);
if (++tile.progress >= PRODUCTION_TICKS) {
tile.progress++;
tile.data.set(0, tile.progress);
if (tile.progress >= PRODUCTION_TICKS) {
if (result.isEmpty()) {
tile.inventory.setStackInSlot(0, ItemHandlerHelper.copyStackWithSize(stack, 1));
} else if (result.is(ModItems.neutron_pile)) {
Expand All @@ -60,16 +65,24 @@ public static void tick(Level level, BlockPos pos, BlockState state, NeutronColl

}

public int getProgress() {
return progress;
}

public static BaseItemStackHandler createInventoryHandler(Runnable onContentsChanged) {
var inventory = new BaseItemStackHandler(1, onContentsChanged);
inventory.setOutputSlots(0);
return inventory;
}

@Override
public void load(@NotNull CompoundTag tag) {
super.load(tag);
this.progress = tag.getInt("progress");
}

@Override
public void saveAdditional(@NotNull CompoundTag tag) {
super.saveAdditional(tag);
tag.putInt("progress", progress);
}

@Override
public @NotNull BaseItemStackHandler getInventory() {
return this.inventory;
Expand All @@ -81,14 +94,14 @@ protected boolean canWork() {


@Override
public Component getDisplayName() {
public @NotNull Component getDisplayName() {
return Localizable.of("container.neutron_collector").build();
}

@Nullable
@Override
public AbstractContainerMenu createMenu(int windowId, @NotNull Inventory playerInventory, @NotNull Player player) {
return NeutronCollectorMenu.create(windowId, playerInventory, this::isUsableByPlayer, this.inventory, new SimpleContainerData(10), this.getBlockPos());
return NeutronCollectorMenu.create(windowId, playerInventory, this::isUsableByPlayer, this.inventory, data, this.getBlockPos());
}

}
2 changes: 2 additions & 0 deletions src/main/java/nova/committee/avaritia/init/ModTooltips.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ModTooltips {

public static final Tooltip CRAFTING = new Tooltip("tooltip.avaritia.crafting");

public static final Tooltip PROGRESS_EMPTY = new Tooltip("tooltip.avaritia.progress_empty");

public static Component getAddedByTooltip(String modid) {
var name = ModList.get().getModFileById(modid).getMods().get(0).getDisplayName();
return ADDED_BY.args(name).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static void tickBootsAbilities(LivingEntity entity) {
boolean sneaking = entity.isCrouching();

float speed = 0.15f * (flying ? 1.1f : 1.0f)
//* (swimming ? 1.2f : 1.0f)
* (swimming ? 1.2f : 1.0f)
* (sneaking ? 0.1f : 1.0f);

if (entity.zza > 0f) {
Expand Down Expand Up @@ -266,7 +266,7 @@ public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
}

@SubscribeEvent
public void entityContstructedEvent(EntityEvent.EntityConstructing event) {
public void entityConstructEvent(EntityEvent.EntityConstructing event) {
if (event.getEntity() instanceof LivingEntity entity) {
stripAbilities(entity);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 654c963

Please sign in to comment.