From 8b74eb212fc99abcfaca8a890d78223fc7a7fcb7 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sat, 3 Aug 2024 14:08:39 +0300 Subject: [PATCH] REMOVE REQUIRE_SLOT from block todo: tooltips for BrewingKegScreen --- .../block/custom/BrewingKegBlock.java | 28 +-- .../block/entity/BrewingKegBlockEntity.java | 182 ++++++++++-------- .../{ => inventory}/ImplementedInventory.java | 12 +- .../{ => inventory}/ItemStackInventory.java | 2 +- .../screen/BrewingKegScreen.java | 42 +--- .../screen/BrewingKegScreenHandler.java | 13 -- .../ukrainian_dlight/util/FluidStack.java | 4 +- 7 files changed, 138 insertions(+), 145 deletions(-) rename src/main/java/com/megatrex4/ukrainian_dlight/block/entity/{ => inventory}/ImplementedInventory.java (92%) rename src/main/java/com/megatrex4/ukrainian_dlight/block/entity/{ => inventory}/ItemStackInventory.java (98%) diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java index ccc4006..b4ef4a6 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/custom/BrewingKegBlock.java @@ -6,6 +6,8 @@ import com.megatrex4.ukrainian_dlight.screen.renderer.FluidStackRenderer; import com.megatrex4.ukrainian_dlight.util.CompoundTagUtils; import com.megatrex4.ukrainian_dlight.util.FluidStack; +import com.nhoryzon.mc.farmersdelight.entity.block.CookingPotBlockEntity; +import com.nhoryzon.mc.farmersdelight.registry.BlockEntityTypesRegistry; import com.nhoryzon.mc.farmersdelight.registry.ParticleTypesRegistry; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -56,7 +58,6 @@ public class BrewingKegBlock extends BlockWithEntity implements BlockEntityProvi public static final int[] INGREDIENT_SLOTS = {0, 1, 2, 3, 4, 5}; public static final int CONTAINER_SLOT = 6; - public static final int REQUIRE_CONTAINER = 7; public static final int WATER_SLOT = 8; public static final int DRINKS_DISPLAY_SLOT = 9; public static final int OUTPUT_SLOT = 10; @@ -180,31 +181,30 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BrewingKegBlockEntity) { BrewingKegBlockEntity brewingKegEntity = (BrewingKegBlockEntity) blockEntity; + // Create an item stack with the block's item ItemStack itemStack = new ItemStack(this.asItem()); + // Save BlockEntity data to NBT - NbtCompound tag = brewingKegEntity.writeToNbtPublic(new NbtCompound()); // Use the public method to get NBT + NbtCompound tag = new NbtCompound(); + brewingKegEntity.writeNbt(tag); + System.out.println("Saved BlockEntityTag: " + tag.toString()); // Debug line itemStack.setSubNbt("BlockEntityTag", tag); - // Save DRINKS_DISPLAY_SLOT to NBT and remove from block entity + // Save DisplaySlot to NBT NbtCompound displaySlotTag = new NbtCompound(); brewingKegEntity.getStack(DRINKS_DISPLAY_SLOT).writeNbt(displaySlotTag); + System.out.println("Saved DisplaySlot: " + displaySlotTag.toString()); // Debug line itemStack.setSubNbt("DisplaySlot", displaySlotTag); - // Save REQUARE_CONTAINER to NBT and remove from block entity - NbtCompound requireContainerTag = new NbtCompound(); - brewingKegEntity.getStack(REQUIRE_CONTAINER).writeNbt(requireContainerTag); - itemStack.setSubNbt("requireContainer", requireContainerTag); - - // Drop items from INGREDIENT_SLOTS (0-7) and WATER_SLOT (9) + // Drop items from INGREDIENT_SLOTS, WATER_SLOT, and CONTAINER_SLOT for (int slot : BrewingKegBlockEntity.INGREDIENT_SLOTS) { - if (slot != BrewingKegBlockEntity.WATER_SLOT) { // Skip WATER_SLOT + if (slot != BrewingKegBlockEntity.WATER_SLOT) { dropSlotContents(world, pos, brewingKegEntity, slot); } } dropSlotContents(world, pos, brewingKegEntity, BrewingKegBlockEntity.WATER_SLOT); - - // Drop the OUTPUT_SLOT + dropSlotContents(world, pos, brewingKegEntity, BrewingKegBlockEntity.CONTAINER_SLOT); dropSlotContents(world, pos, brewingKegEntity, BrewingKegBlockEntity.OUTPUT_SLOT); // Spawn the item entity with the BlockEntityTag and DisplaySlot NBT @@ -217,6 +217,8 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt } + + private void dropSlotContents(World world, BlockPos pos, BrewingKegBlockEntity brewingKegEntity, int slot) { ItemStack stack = brewingKegEntity.getStack(slot); if (!stack.isEmpty()) { @@ -267,7 +269,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt return ActionResult.SUCCESS; } } else { - ItemStack requiredContainer = blockEntity.getStack(REQUIRE_CONTAINER); + ItemStack requiredContainer = blockEntity.getDrinkContainer(); if (heldItem.isOf(requiredContainer.getItem())) { ItemStack displayItem = blockEntity.getStack(DRINKS_DISPLAY_SLOT); diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java index 405add0..b735302 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/BrewingKegBlockEntity.java @@ -1,6 +1,7 @@ package com.megatrex4.ukrainian_dlight.block.entity; import com.megatrex4.ukrainian_dlight.block.custom.BrewingKegBlock; +import com.megatrex4.ukrainian_dlight.block.entity.inventory.ImplementedInventory; import com.megatrex4.ukrainian_dlight.config.ModConfig; import com.megatrex4.ukrainian_dlight.networking.ModMessages; import com.megatrex4.ukrainian_dlight.recipe.BrewingRecipe; @@ -9,7 +10,9 @@ import com.megatrex4.ukrainian_dlight.util.CompoundTagUtils; import com.megatrex4.ukrainian_dlight.util.FluidStack; +import com.nhoryzon.mc.farmersdelight.entity.block.CookingPotBlockEntity; import io.netty.buffer.Unpooled; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -28,6 +31,7 @@ import net.minecraft.fluid.Fluids; import net.minecraft.inventory.Inventories; import net.minecraft.item.Item; +import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; @@ -40,6 +44,7 @@ import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.*; import net.minecraft.world.World; @@ -50,12 +55,12 @@ public class BrewingKegBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory { private final DefaultedList inventory = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY); + public static final String TAG_KEY_COOK_RECIPES_USED = "RecipesUsed"; private long capacity; public static final int[] INGREDIENT_SLOTS = {0, 1, 2, 3, 4, 5}; public static final int CONTAINER_SLOT = 6; - public static final int REQUIRE_CONTAINER = 7; public static final int WATER_SLOT = 8; public static final int DRINKS_DISPLAY_SLOT = 9; public static final int OUTPUT_SLOT = 10; @@ -68,10 +73,12 @@ public class BrewingKegBlockEntity extends BlockEntity implements ExtendedScreen protected final PropertyDelegate propertyDelegate; + private final Object2IntOpenHashMap experienceTracker; private int progress; private int maxProgress = 200; // Adjusted to match the brewing time in the JSON private float totalExperience = 0; private Text customName; + private ItemStack drinkContainer; @@ -100,6 +107,8 @@ protected void onFinalCommit() { public BrewingKegBlockEntity(BlockPos pos, BlockState state) { super(ModBlockEntities.BREWING_KEG_BLOCK_ENTITY, pos, state); + drinkContainer = ItemStack.EMPTY; + experienceTracker = new Object2IntOpenHashMap<>(); this.capacity = ModConfig.getBrewingKegCapacity(); this.propertyDelegate = new PropertyDelegate() { @Override @@ -166,58 +175,10 @@ public boolean canExtract(int slot, ItemStack stack, Direction dir) { } - - public NbtCompound writeToNbtPublic(NbtCompound tag) { - // Call the superclass method to ensure all necessary data is written - super.writeNbt(tag); // Call super method to save base block entity data - - // Save DRINKS_DISPLAY_SLOT to NBT - NbtCompound displaySlotTag = new NbtCompound(); - this.getStack(DRINKS_DISPLAY_SLOT).writeNbt(displaySlotTag); - tag.put("DisplaySlot", displaySlotTag); - - // Save REQUIRE_CONTAINER to NBT - NbtCompound requireContainerTag = new NbtCompound(); - this.getStack(REQUIRE_CONTAINER).writeNbt(requireContainerTag); - tag.put("requireContainer", requireContainerTag); - - // Save experience - tag.putFloat("TotalExperience", totalExperience); - - NbtCompound tankContent = new NbtCompound(); - NbtCompound variant = fluidStorage.variant.toNbt(); - tankContent.put("Variant", variant); - tankContent.putLong("Capacity", fluidStorage.getCapacity()); - tankContent.putLong("Amount", fluidStorage.amount); - tag.put("TankContent", tankContent); - - // Return the modified NbtCompound - return tag; - } - - public ItemStack getDrink() { return getStack(DRINKS_DISPLAY_SLOT); } - public NbtCompound writeDrink(NbtCompound tag) { - if (getDrink().isEmpty()) { - return tag; - } - - if (customName != null) { - tag.putString(CompoundTagUtils.TAG_KEY_CUSTOM_NAME, Text.Serializer.toJson(customName)); - } - - DefaultedList drops = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY); - for (int i = 0; i < INVENTORY_SIZE; ++i) { - drops.set(i, i == DRINKS_DISPLAY_SLOT ? getStack(i) : ItemStack.EMPTY); - } - tag.put(CompoundTagUtils.TAG_KEY_INVENTORY, Inventories.writeNbt(new NbtCompound(), drops)); - - return tag; - } - public Text getName() { return customName != null ? customName : Text.translatable("gui.ukrainian_delight.brewing_keg"); @@ -233,12 +194,11 @@ public void setCustomName(Text customName) { } @Override - protected void writeNbt(NbtCompound tag) { + public void writeNbt(NbtCompound tag) { super.writeNbt(tag); Inventories.writeNbt(tag, inventory); tag.putInt("progress", progress); - // Save DRINKS_DISPLAY_SLOT NbtCompound displaySlotTag = new NbtCompound(); ItemStack displayStack = getStack(DRINKS_DISPLAY_SLOT); @@ -247,13 +207,8 @@ protected void writeNbt(NbtCompound tag) { } tag.put("DisplaySlot", displaySlotTag); - // Save requireContainer - NbtCompound requireContainerTag = new NbtCompound(); - ItemStack requireContainer = getStack(REQUIRE_CONTAINER); - if (!requireContainer.isEmpty()) { - requireContainer.writeNbt(requireContainerTag); - } - tag.put("requireContainer", requireContainerTag); + tag.put(CompoundTagUtils.TAG_KEY_CONTAINER, drinkContainer.writeNbt(new NbtCompound())); + writeInventoryNbt(tag); // Save totalExperience tag.putFloat("TotalExperience", totalExperience); @@ -268,19 +223,20 @@ protected void writeNbt(NbtCompound tag) { } + @Override public void readNbt(NbtCompound tag) { super.readNbt(tag); Inventories.readNbt(tag, inventory); progress = tag.getInt("progress"); - - // Load totalExperience if (tag.contains("TotalExperience", NbtType.FLOAT)) { totalExperience = tag.getFloat("TotalExperience"); } + drinkContainer = ItemStack.fromNbt(tag.getCompound(CompoundTagUtils.TAG_KEY_CONTAINER)); + // Load DRINKS_DISPLAY_SLOT if (tag.contains("DisplaySlot", NbtType.COMPOUND)) { NbtCompound displaySlotTag = tag.getCompound("DisplaySlot"); @@ -289,27 +245,36 @@ public void readNbt(NbtCompound tag) { setStack(DRINKS_DISPLAY_SLOT, ItemStack.EMPTY); // Ensure it's clear if no DisplaySlot is found } - // Load requireContainer - if (tag.contains("requireContainer", NbtType.COMPOUND)) { - NbtCompound requireContainerTag = tag.getCompound("requireContainer"); - setStack(REQUIRE_CONTAINER, ItemStack.fromNbt(requireContainerTag)); - } else { - setStack(REQUIRE_CONTAINER, ItemStack.EMPTY); - } - // Load water if (tag.contains("TankContent", NbtType.COMPOUND)) { NbtCompound tankContent = tag.getCompound("TankContent"); fluidStorage.variant = FluidVariant.fromNbt(tankContent.getCompound("Variant")); fluidStorage.amount = tankContent.getLong("Amount"); } + + NbtCompound compoundRecipes = tag.getCompound(TAG_KEY_COOK_RECIPES_USED); + for (String key : compoundRecipes.getKeys()) { + experienceTracker.put(new Identifier(key), compoundRecipes.getInt(key)); + } } + public NbtCompound writeDrink(NbtCompound tag) { + if (getDrink().isEmpty()) { + return tag; + } + + if (customName != null) { + tag.putString(CompoundTagUtils.TAG_KEY_CUSTOM_NAME, Text.Serializer.toJson(customName)); + } + tag.put(CompoundTagUtils.TAG_KEY_CONTAINER, drinkContainer.writeNbt(new NbtCompound())); + DefaultedList drops = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY); + for (int i = 0; i < INVENTORY_SIZE; ++i) { + drops.set(i, i == DRINKS_DISPLAY_SLOT ? getStack(i) : ItemStack.EMPTY); + } + tag.put(CompoundTagUtils.TAG_KEY_INVENTORY, Inventories.writeNbt(new NbtCompound(), drops)); - public ItemStack getItemFromLastCraft(String path) { - Item container = Items.BUCKET; - return new ItemStack(container); + return tag; } @@ -340,10 +305,11 @@ public void tick(World world, BlockPos pos, BlockState state) { if (world.isClient) { return; } + boolean dirty = false; handleWaterBucket(); - processItemTransfer(world, pos, state); processCrafting(); + processItemTransfer(world, pos, state); } @@ -351,9 +317,9 @@ private void processItemTransfer(World world, BlockPos pos, BlockState state) { ItemStack displayStack = getStack(DRINKS_DISPLAY_SLOT); ItemStack containerStack = getStack(CONTAINER_SLOT); ItemStack outputStack = getStack(OUTPUT_SLOT); - ItemStack requireContainer = getStack(REQUIRE_CONTAINER); + ItemStack requiredContainer = getDrinkContainer(); - if (!displayStack.isEmpty() && !containerStack.isEmpty() && containerStack.getItem() == requireContainer.getItem()) { + if (!displayStack.isEmpty() && !containerStack.isEmpty() && containerStack.getItem() == requiredContainer.getItem()) { if (isOutputSlotEmptyOrReceivable(outputStack)) { containerStack.decrement(1); @@ -399,6 +365,7 @@ private void spawnExperienceOrb(World world, BlockPos pos, int xpAmount) { } + private void processCrafting() { Optional match = getCurrentRecipe(); if (match.isPresent()) { @@ -414,7 +381,6 @@ private void processCrafting() { int craftedAmount = 1; if (this.craftItem(recipe, craftedAmount)) { // Provide craftedAmount here this.resetProgress(); - // Play brewing sound effect playBrewingSound(); } } else { @@ -432,6 +398,16 @@ private void playBrewingSound() { } + public ItemStack getDrinkContainer() { + if (!drinkContainer.isEmpty()) { + return drinkContainer; + } else { + return new ItemStack(getDrink().getItem().getRecipeRemainder()); + } + } + + + @@ -482,7 +458,7 @@ private boolean isOutputSlotEmptyOrReceivable(ItemStack output) { } - private void handleWaterBucket() { + public void handleWaterBucket() { ItemStack waterBucketStack = this.getStack(WATER_SLOT); if (waterBucketStack.getItem() == Items.WATER_BUCKET) { @@ -605,13 +581,11 @@ private boolean craftItem(BrewingRecipe recipe, int craftedAmount) { if (this.progress < this.maxProgress) { return false; } else { - this.progress = 0; // Ensure a copy is made to avoid side effects + this.progress = 0; ItemStack recipeOutput = recipe.craft(this, this.world.getRegistryManager()); ItemStack currentOutput = this.getStack(DRINKS_DISPLAY_SLOT); - ItemStack requireContainerItem = this.getStack(REQUIRE_CONTAINER); - requireContainerItem = recipe.getContainer().copy(); - this.setStack(REQUIRE_CONTAINER, requireContainerItem); + drinkContainer = recipe.getContainer(); if (currentOutput.isEmpty()) { this.setStack(DRINKS_DISPLAY_SLOT, recipeOutput.copy()); @@ -669,6 +643,35 @@ private void handleRecipeRemainder(BrewingRecipe recipe) { + + public ItemStack useHeldItemOnMeal(ItemStack container) { + if (isContainerValid(container) && !getDrink().isEmpty()) { + container.decrement(1); + return getDrink().split(1); + } + return ItemStack.EMPTY; + } + + private boolean doesDrinkHaveContainer(ItemStack meal) { + return !drinkContainer.isEmpty() || meal.getItem().hasRecipeRemainder(); + } + + public boolean isContainerValid(ItemStack containerItem) { + if (containerItem.isEmpty()) { + return false; + } + if (!drinkContainer.isEmpty()) { + return ItemStack.areItemsEqual(drinkContainer, containerItem); + } else { + return containerItem.isOf(getDrink().getItem().getRecipeRemainder()); + } + } + + + + + + private void extractFluid(int amount) { try (Transaction transaction = Transaction.openOuter()) { this.fluidStorage.extract(FluidVariant.of(Fluids.WATER), FluidStack.convertMbToDroplets(amount), transaction); @@ -714,4 +717,23 @@ public void trackRecipeExperience(float totalExperience) { markDirty(); } + + + private void moveDrinkToOutput() { + ItemStack dinkDisplay = getStack(DRINKS_DISPLAY_SLOT); + ItemStack finalOutput = getStack(OUTPUT_SLOT); + int mealCount = Math.min(dinkDisplay.getCount(), dinkDisplay.getMaxCount() - finalOutput.getCount()); + if (finalOutput.isEmpty()) { + setStack(OUTPUT_SLOT, dinkDisplay.split(mealCount)); + } else if (finalOutput.getItem() == dinkDisplay.getItem()) { + dinkDisplay.decrement(mealCount); + finalOutput.increment(mealCount); + } + } + + + + + + } diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/ImplementedInventory.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/inventory/ImplementedInventory.java similarity index 92% rename from src/main/java/com/megatrex4/ukrainian_dlight/block/entity/ImplementedInventory.java rename to src/main/java/com/megatrex4/ukrainian_dlight/block/entity/inventory/ImplementedInventory.java index 0967f9c..8837236 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/ImplementedInventory.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/inventory/ImplementedInventory.java @@ -1,5 +1,6 @@ -package com.megatrex4.ukrainian_dlight.block.entity; +package com.megatrex4.ukrainian_dlight.block.entity.inventory; +import com.megatrex4.ukrainian_dlight.util.CompoundTagUtils; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventories; import net.minecraft.inventory.Inventory; @@ -210,4 +211,13 @@ default void markDirty() { default boolean canPlayerUse(PlayerEntity player) { return true; } + + + default void readInventoryNbt(NbtCompound tag) { + Inventories.readNbt(tag.getCompound(CompoundTagUtils.TAG_KEY_INVENTORY), getItems()); + } + + default void writeInventoryNbt(NbtCompound tag) { + tag.put(CompoundTagUtils.TAG_KEY_INVENTORY, Inventories.writeNbt(new NbtCompound(), getItems())); + } } diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/ItemStackInventory.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/inventory/ItemStackInventory.java similarity index 98% rename from src/main/java/com/megatrex4/ukrainian_dlight/block/entity/ItemStackInventory.java rename to src/main/java/com/megatrex4/ukrainian_dlight/block/entity/inventory/ItemStackInventory.java index ba20fdf..3e6966e 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/ItemStackInventory.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/entity/inventory/ItemStackInventory.java @@ -1,4 +1,4 @@ -package com.megatrex4.ukrainian_dlight.block.entity; +package com.megatrex4.ukrainian_dlight.block.entity.inventory; import com.megatrex4.ukrainian_dlight.util.CompoundTagUtils; import com.nhoryzon.mc.farmersdelight.exception.SlotInvalidRangeException; diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java index 94d9166..460f921 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java @@ -7,6 +7,8 @@ import com.megatrex4.ukrainian_dlight.util.FluidStack; import com.megatrex4.ukrainian_dlight.util.MouseUtil; import com.mojang.blaze3d.systems.RenderSystem; +import com.nhoryzon.mc.farmersdelight.FarmersDelightMod; + import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; @@ -35,7 +37,6 @@ public class BrewingKegScreen extends HandledScreen { public static final int[] INGREDIENT_SLOTS = {0, 1, 2, 3, 4, 5}; public static final int CONTAINER_SLOT = 6; - public static final int REQUIRE_CONTAINER = 7; public static final int WATER_SLOT = 8; public static final int DRINKS_DISPLAY_SLOT = 9; public static final int OUTPUT_SLOT = 10; @@ -101,44 +102,15 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { @Override protected void drawMouseoverTooltip(DrawContext context, int mouseX, int mouseY) { - if (this.handler.getCursorStack().isEmpty() && this.focusedSlot != null) { - if (this.focusedSlot.hasStack()) { - // Check if the focused slot is DRINKS_DISPLAY_SLOT (slot ID 9) - if (this.focusedSlot.id == DRINKS_DISPLAY_SLOT) { - List tooltip = new ArrayList<>(); - - // Get the item in DRINKS_DISPLAY_SLOT (slot ID 9) - ItemStack drink = this.focusedSlot.getStack(); - Text drinkText = drink.getName(); - if (drinkText instanceof MutableText mutableName) { - tooltip.add(mutableName.formatted(drink.getRarity().formatting)); - } else { - tooltip.add(drinkText); - } - drink.getItem().appendTooltip(drink, handler.blockEntity.getWorld(), tooltip, TooltipContext.Default.BASIC); - - // Get the item in REQUIRE_CONTAINER (slot ID 7) - ItemStack containerItem = handler.blockEntity.getStack(REQUIRE_CONTAINER); - String containerName = ""; - if (!containerItem.isEmpty()) { - Item container = containerItem.getItem(); - containerName = Text.translatable(container.getTranslationKey()).getString(); - } - - // Add the localized string with the container name - tooltip.add(UkrainianDelight.i18n("tooltip.slot_item", containerName).formatted(Formatting.GRAY)); - - // Draw the tooltip - context.drawTooltip(textRenderer, tooltip, mouseX, mouseY); - } else { - // Draw the typical tooltip for all other slots - context.drawItemTooltip(textRenderer, this.focusedSlot.getStack(), mouseX, mouseY); - } - } + if (this.handler.getCursorStack().isEmpty() && this.focusedSlot != null && this.focusedSlot.hasStack()) { + //fix it + context.drawItemTooltip(textRenderer, focusedSlot.getStack(), mouseX, mouseY); } } + + protected void drawMouseoverTankTooltip(DrawContext context, int mouseX, int mouseY) { int x = (width - backgroundWidth) / 2; int y = (height - backgroundHeight) / 2; diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java index a5ee75b..2cbaafd 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java @@ -26,7 +26,6 @@ public class BrewingKegScreenHandler extends ScreenHandler { public static final int[] INGREDIENT_SLOTS = {0, 1, 2, 3, 4, 5}; public static final int CONTAINER_SLOT = 6; - public static final int REQUIRE_CONTAINER = 7; public static final int WATER_SLOT = 8; public static final int DRINKS_DISPLAY_SLOT = 9; @@ -78,18 +77,6 @@ public BrewingKegScreenHandler(int syncId, PlayerInventory playerInventory, Bloc this.addSlot(new Slot(tileEntity, CONTAINER_SLOT, 97, 59)); // Add water slot this.addSlot(new Slot(tileEntity, WATER_SLOT, 30, 59)); - // Add require container slot - this.addSlot(new Slot(tileEntity, REQUIRE_CONTAINER, 1000000000, 1000000000) { - @Override - public boolean canInsert(ItemStack stack) { - return false; - } - - @Override - public boolean canTakeItems(PlayerEntity playerEntity) { - return false; - } - }); // Add drinks display slot diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/util/FluidStack.java b/src/main/java/com/megatrex4/ukrainian_dlight/util/FluidStack.java index 7b06ce1..cb9f447 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/util/FluidStack.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/util/FluidStack.java @@ -30,10 +30,10 @@ public void setAmount(long amount) { } public static long convertDropletsToMb(long droplets) { - return droplets / 81; + return droplets / DROPLETS_PER_MILLIBUCKET; } public static long convertMbToDroplets(long millibuckets) { - return millibuckets * 81; + return millibuckets * DROPLETS_PER_MILLIBUCKET; } }