diff --git a/src/main/java/growthcraft/milk/block/MixingVatBlock.java b/src/main/java/growthcraft/milk/block/MixingVatBlock.java index 3a02a68..c1f242d 100644 --- a/src/main/java/growthcraft/milk/block/MixingVatBlock.java +++ b/src/main/java/growthcraft/milk/block/MixingVatBlock.java @@ -223,7 +223,19 @@ public BlockEntityTicker getTicker(Level level, Block protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) { if (!state.is(newState.getBlock())) { if (!level.isClientSide && level.getBlockEntity(pos) instanceof MixingVatBlockEntity vat) { - Containers.dropContents(level, pos, vat); + for(int i = 0; i < vat.getContainerSize(); ++i) { + if (i == MixingVatBlockEntity.SLOT_RESULT_TOOL) { + continue; // it's a fake/virtual slot for transferring information to screen. + } + if (i == MixingVatBlockEntity.SLOT_RESULT) { + // here's the deal: if there is a pickup-item needed (cloth), no drop. if it can be collected by hand, we drop. + if (! vat.getItem(MixingVatBlockEntity.SLOT_RESULT_TOOL).isEmpty()) { + continue; + } + } + Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), vat.getItem(i)); + } + } super.onRemove(state, level, pos, newState, movedByPiston); } diff --git a/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java b/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java index bfdd323..b7df1b8 100644 --- a/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java +++ b/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java @@ -41,7 +41,8 @@ public class MixingVatBlockEntity extends BlockEntity implements WorldlyContaine public static final int SLOT_INPUT_1 = 1; public static final int SLOT_INPUT_2 = 2; public static final int SLOT_RESULT = 3; - public static final int SLOT_COUNT = 4; + public static final int SLOT_RESULT_TOOL = 4; + public static final int SLOT_COUNT = 5; public static final int MAIN_TANK_CAPACITY = 4000; public static final int SIDE_TANK_CAPACITY = 1000; @@ -70,12 +71,12 @@ protected void onContentsChanged() { } public static void serverTick(Level level, BlockPos pos, BlockState state, MixingVatBlockEntity vat) { - if ((level.getGameTime() & 19L) == 0L) { + if ((level.getGameTime() & 19L) == 0L) { // todo: ???? updateLitState(level, pos, state); state = level.getBlockState(pos); } - Optional> match = vat.findMatch(level, state); + Optional> match = vat.findMatch(level, state); // todo: horrible perf issue here if (match.isEmpty() || !vat.activated || !vat.canOutput(match.get().value())) { if (match.isEmpty()) { vat.resetProgress(); @@ -84,11 +85,11 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Mixin } MixingVatRecipe recipe = match.get().value(); - vat.processTimeTotal = recipe.getProcessingTime(); - vat.processTime++; + vat.processTimeTotal = recipe.getProcessingTime(); // todo only needed once on start + vat.processTime++; // todo keeps inc after total if (vat.processTime >= vat.processTimeTotal) { - vat.completeRecipe(level, pos, state, recipe); - } else if ((vat.processTime & 15) == 0) { + vat.completeRecipe(level, pos, state, recipe); // todo math allows it done multiple times, relies on recipe check + } else if ((vat.processTime & 15) == 0) { // todo why? vat.setChanged(); level.sendBlockUpdated(pos, state, state, Block.UPDATE_CLIENTS); } @@ -155,6 +156,7 @@ private void completeRecipe(Level level, BlockPos pos, BlockState state, MixingV mainTank.setFluid(FluidStack.EMPTY); sideTank.setFluid(FluidStack.EMPTY); setItem(SLOT_RESULT, recipe.getResultItemStack()); + setItem(SLOT_RESULT_TOOL, recipe.getResultActivationTool()); } activated = false; processTime = 0; @@ -199,18 +201,15 @@ public boolean collectResult(Player player, ItemStack heldStack) { return false; } - Optional> match = level == null ? Optional.empty() - : level.getRecipeManager().getAllRecipesFor(GrowthcraftMilkRecipes.MIXING_VAT_TYPE.get()).stream() - .filter(holder -> ItemStack.isSameItemSameComponents(holder.value().getResultItemStack(), result)) - .findFirst(); - ItemStack tool = match.map(holder -> holder.value().getResultActivationTool()).orElse(ItemStack.EMPTY); - if (!tool.isEmpty() && !ItemStack.isSameItem(tool, heldStack)) { + ItemStack resultActivationItem = getItem(SLOT_RESULT_TOOL); + if (!resultActivationItem.isEmpty() && !ItemStack.isSameItem(resultActivationItem, heldStack)) { return false; } ItemStack toGive = result.copy(); setItem(SLOT_RESULT, ItemStack.EMPTY); - if (!tool.isEmpty() && !player.getAbilities().instabuild) { + setItem(SLOT_RESULT_TOOL, ItemStack.EMPTY); + if (!resultActivationItem.isEmpty() && !player.getAbilities().instabuild) { heldStack.shrink(1); } if (!player.addItem(toGive)) { diff --git a/src/main/java/growthcraft/milk/client/screen/MixingVatScreen.java b/src/main/java/growthcraft/milk/client/screen/MixingVatScreen.java index 2c3bd3b..9586831 100644 --- a/src/main/java/growthcraft/milk/client/screen/MixingVatScreen.java +++ b/src/main/java/growthcraft/milk/client/screen/MixingVatScreen.java @@ -1,14 +1,19 @@ package growthcraft.milk.client.screen; import growthcraft.lib.client.screen.renderer.FluidTankRenderer; +import growthcraft.milk.block.entity.MixingVatBlockEntity; import growthcraft.milk.menu.MixingVatMenu; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; import net.neoforged.neoforge.fluids.FluidStack; +import java.util.List; + public class MixingVatScreen extends AbstractContainerScreen { private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath("growthcraft_milk", "textures/gui/mixing_vat_screen.png"); @@ -123,6 +128,33 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi this.renderTooltip(graphics, mouseX, mouseY); } + @Override + protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) { + + if (this.menu.getCarried().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.index == 3 && this.hoveredSlot.hasItem()) { + // result slot + ItemStack finalizerItem = this.getMenu().getResultActivationTool(); + ItemStack resultItemStack = this.hoveredSlot.getItem(); + if (this.lastResultItem != resultItemStack.hashCode()) { + this.tooltipLines = this.getTooltipFromContainerItem(resultItemStack); + if (finalizerItem != null) { + Component finalizerText = finalizerItem.isEmpty() ? Component.translatable("message.growthcraft_milk.get_using_item_empty_hand").withStyle(Style.EMPTY.withColor(0xffffff88)) : finalizerItem.getHoverName().copy().withStyle(Style.EMPTY.withColor(0xffffff88)); + this.lastComponent = Component.translatable("message.growthcraft_milk.get_using_item", finalizerText).withStyle(Style.EMPTY.withColor(0xffddbb44)); + this.tooltipLines.add(this.lastComponent); + } + this.lastResultItem = resultItemStack.hashCode(); + } + guiGraphics.renderTooltip(this.font, tooltipLines, resultItemStack.getTooltipImage(), resultItemStack, x, y); + } + else { + // not a result slot + super.renderTooltip(guiGraphics, x, y); + } + } + private int lastResultItem = 0; + private Component lastComponent = null; + private List tooltipLines = null; + @Override protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { graphics.drawString(this.font, this.title, 8, 6, 4210752, false); diff --git a/src/main/java/growthcraft/milk/menu/MixingVatMenu.java b/src/main/java/growthcraft/milk/menu/MixingVatMenu.java index a0f40ef..37137a3 100644 --- a/src/main/java/growthcraft/milk/menu/MixingVatMenu.java +++ b/src/main/java/growthcraft/milk/menu/MixingVatMenu.java @@ -12,6 +12,7 @@ import net.minecraft.world.inventory.SimpleContainerData; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.neoforged.neoforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; @@ -106,6 +107,16 @@ public boolean mayPickup(Player player) { return false; } }); + this.addSlot(new Slot(container, MixingVatBlockEntity.SLOT_RESULT+1, 99999, 99999) { + @Override + public boolean mayPlace(ItemStack stack) { return false; } + @Override + public boolean mayPickup(Player player) { return false; } + @Override + public boolean isFake() { return true; } + @Override + public boolean isActive() { return false; } + }); int startX = 8; int startY = 84; @@ -206,4 +217,9 @@ public ItemStack quickMoveStack(Player player, int index) { } return itemstack; } + + public ItemStack getResultActivationTool() + { + return this.slots.get(MixingVatBlockEntity.SLOT_RESULT_TOOL).getItem(); + } }