diff --git a/projectfiles/jar.png b/projectfiles/jars/jar.png similarity index 100% rename from projectfiles/jar.png rename to projectfiles/jars/jar.png diff --git a/projectfiles/jar_ver1.bbmodel b/projectfiles/jars/jar_ver1.bbmodel similarity index 100% rename from projectfiles/jar_ver1.bbmodel rename to projectfiles/jars/jar_ver1.bbmodel diff --git a/projectfiles/jar_ver2.bbmodel b/projectfiles/jars/jar_ver2.bbmodel similarity index 100% rename from projectfiles/jar_ver2.bbmodel rename to projectfiles/jars/jar_ver2.bbmodel diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/block/DrinkBottleBlock.java b/src/main/java/com/megatrex4/ukrainian_dlight/block/DrinkBottleBlock.java index f6134a0..a6cf574 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/block/DrinkBottleBlock.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/block/DrinkBottleBlock.java @@ -17,6 +17,7 @@ public class DrinkBottleBlock { public static final Block WINE_BOTTLE = registerBlock("wine_bottle", new BottleBlock(), new FoodComponent.Builder() .hunger(6).saturationModifier(0.6f) .statusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 3 * 20, 3), 1.0f) + .alwaysEdible() .build()); private static Block registerBlock(String name, Block block, FoodComponent foodComponent) { 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 5e4bb2e..d58e5cb 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 @@ -40,6 +40,8 @@ public class BrewingKegBlock extends BlockWithEntity implements BlockEntityProvi public static final int DRINKS_DISPLAY_SLOT = 8; public static final int OUTPUT_SLOT = 9; + public static final int REQUIRE_CONTAINER = 10; + private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 12, 16); public static final DirectionProperty FACING; @@ -95,30 +97,31 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt if (blockEntity instanceof BrewingKegBlockEntity) { BrewingKegBlockEntity brewingKegEntity = (BrewingKegBlockEntity) blockEntity; - // Create an item stack with the block's item - ItemStack itemStack = new ItemStack(this.asItem()); + // Save the ItemStack in REQUIRE_CONTAINER slot to block entity NBT + NbtCompound tag = new NbtCompound(); + ItemStack requireContainerStack = brewingKegEntity.getStack(REQUIRE_CONTAINER); + if (!requireContainerStack.isEmpty()) { + NbtCompound requireContainerTag = new NbtCompound(); + requireContainerStack.writeNbt(requireContainerTag); + tag.put("requireContainer", requireContainerTag); + } + + // Save other necessary data to the tag if needed + // Example: Save fluid variant and amount + tag.put("fluid_variant", brewingKegEntity.fluidStorage.variant.toNbt()); + tag.putLong("fluid_amount", brewingKegEntity.fluidStorage.amount); + + brewingKegEntity.writeToNbtPublic(tag); // Save updated NBT to block entity - // Save BlockEntity data to NBT - NbtCompound itemNbt = brewingKegEntity.writeToNbtPublic(new NbtCompound()); // Use the public method to get NBT - itemStack.setSubNbt("BlockEntityTag", itemNbt); + // Spawn the item entity with the Block's item and custom NBT + ItemStack itemStack = new ItemStack(this.asItem()); + itemStack.setSubNbt("BlockEntityTag", tag); // Save DRINKS_DISPLAY_SLOT to NBT and remove from block entity NbtCompound displaySlotTag = new NbtCompound(); brewingKegEntity.getStack(DRINKS_DISPLAY_SLOT).writeNbt(displaySlotTag); itemStack.setSubNbt("DisplaySlot", displaySlotTag); - // Drop items from INGREDIENT_SLOTS (0-7) and WATER_SLOT (9) - for (int slot : BrewingKegBlockEntity.INGREDIENT_SLOTS) { - if (slot != BrewingKegBlockEntity.WATER_SLOT) { // Skip WATER_SLOT - dropSlotContents(world, pos, brewingKegEntity, slot); - } - } - dropSlotContents(world, pos, brewingKegEntity, BrewingKegBlockEntity.WATER_SLOT); - - // Drop the OUTPUT_SLOT - dropSlotContents(world, pos, brewingKegEntity, BrewingKegBlockEntity.OUTPUT_SLOT); - - // Spawn the item entity with the BlockEntityTag and DisplaySlot NBT ItemEntity itemEntity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), itemStack); world.spawnEntity(itemEntity); } @@ -128,6 +131,7 @@ 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()) { 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 9cb7963..0bb746f 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 @@ -56,18 +56,15 @@ import java.util.*; public class BrewingKegBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory, ImplementedInventory { - private final DefaultedList inventory = DefaultedList.ofSize(10, ItemStack.EMPTY); + private final DefaultedList inventory = DefaultedList.ofSize(INVENTORY_SIZE, ItemStack.EMPTY); - //adds 6 input ingredients slot public static final int[] INGREDIENT_SLOTS = {0, 1, 2, 3, 4, 5}; - //adds container(like bottle of vial) input public static final int CONTAINER_SLOT = 6; - //adds 1 input slot for water - public static final int WATER_SLOT = 7; - //adds 1 output slot and display slot - public static final int DRINKS_DISPLAY_SLOT = 8; - public static final int OUTPUT_SLOT = 9; + 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; public static final int INVENTORY_SIZE = OUTPUT_SLOT + 1; @@ -187,6 +184,11 @@ public NbtCompound writeToNbtPublic(NbtCompound tag) { 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 water amount tag.putLong("fluid_amount", fluidStorage.amount); tag.put("fluid_variant", fluidStorage.variant.toNbt()); @@ -194,6 +196,7 @@ public NbtCompound writeToNbtPublic(NbtCompound tag) { // Save container tag.put(CompoundTagUtils.TAG_KEY_CONTAINER, drinkContainer.writeNbt(new NbtCompound())); + // Save experience tag.putFloat("TotalExperience", totalExperience); @@ -202,12 +205,12 @@ public NbtCompound writeToNbtPublic(NbtCompound tag) { } - public ItemStack getMeal() { + public ItemStack getDrink() { return getStack(DRINKS_DISPLAY_SLOT); } - public NbtCompound writeMeal(NbtCompound tag) { - if (getMeal().isEmpty()) { + public NbtCompound writeDrink(NbtCompound tag) { + if (getDrink().isEmpty()) { return tag; } @@ -265,6 +268,14 @@ 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); + // Save totalExperience tag.putFloat("TotalExperience", totalExperience); } @@ -299,6 +310,14 @@ public void readNbt(NbtCompound tag) { } else { 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); + } + } @@ -570,10 +589,14 @@ private boolean craftItem(BrewingRecipe recipe, int craftedAmount) { if (this.progress < this.maxProgress) { return false; } else { - this.progress = 0; - drinkContainer = recipe.getContainer().copy(); // Ensure a copy is made to avoid side effects + this.progress = 0;; // Ensure a copy is made to avoid side effects ItemStack recipeOutput = recipe.craft(this, this.world.getRegistryManager()); ItemStack currentOutput = this.getStack(DRINKS_DISPLAY_SLOT); + drinkContainer = recipe.getContainer().copy(); + // Replace REQUIRE_CONTAINER with item from drinkContainer + ItemStack requireContainerItem = this.getStack(REQUIRE_CONTAINER); + requireContainerItem = recipe.getContainer().copy(); + this.setStack(REQUIRE_CONTAINER, requireContainerItem); if (currentOutput.isEmpty()) { this.setStack(DRINKS_DISPLAY_SLOT, recipeOutput.copy()); @@ -603,6 +626,8 @@ private boolean craftItem(BrewingRecipe recipe, int craftedAmount) { } } + + private void saveLastCraftedRecipe(BrewingRecipe recipe) { // Assuming recipe.getId() gives the unique ID of the recipe String recipeId = recipe.getId().toString(); // Convert ID to String if necessary @@ -634,8 +659,8 @@ private void handleRecipeRemainder(BrewingRecipe recipe) { - private boolean doesDrinkHaveContainer(ItemStack meal) { - return !drinkContainer.isEmpty() || meal.getItem().hasRecipeRemainder(); + private boolean doesDrinkHaveContainer(ItemStack drink) { + return !drinkContainer.isEmpty() || drink.getItem().hasRecipeRemainder(); } 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 71616b4..2469cd5 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java @@ -3,8 +3,6 @@ import com.megatrex4.ukrainian_dlight.UkrainianDelight; import com.megatrex4.ukrainian_dlight.block.entity.BrewingKegBlockEntity; import com.mojang.blaze3d.systems.RenderSystem; -import com.nhoryzon.mc.farmersdelight.FarmersDelightMod; -import com.nhoryzon.mc.farmersdelight.entity.block.CookingPotBlockEntity; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.item.TooltipContext; @@ -25,6 +23,15 @@ public class BrewingKegScreen extends HandledScreen { private static final Identifier TEXTURE = new Identifier(UkrainianDelight.MOD_ID, "textures/gui/brewing_keg_gui.png"); + 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; + + public static final int INVENTORY_SIZE = OUTPUT_SLOT + 1; + public BrewingKegScreen(BrewingKegScreenHandler handler, PlayerInventory inventory, Text title) { super(handler, inventory, title); @@ -70,54 +77,42 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { renderBackground(context); super.render(context, mouseX, mouseY, delta); drawMouseoverTankTooltip(context, mouseX, mouseY); - // drawMouseoverSlotTooltip(context, mouseX, mouseY); drawMouseoverTooltip(context, mouseX, mouseY); } - - @Override protected void drawMouseoverTooltip(DrawContext context, int mouseX, int mouseY) { if (this.handler.getCursorStack().isEmpty() && this.focusedSlot != null) { - if (this.focusedSlot.id == BrewingKegBlockEntity.DRINKS_DISPLAY_SLOT && this.focusedSlot.hasStack()) { + // Check if the focused slot is DRINKS_DISPLAY_SLOT (slot ID 8) + if (this.focusedSlot.id == DRINKS_DISPLAY_SLOT && this.focusedSlot.hasStack()) { List tooltip = new ArrayList<>(); - ItemStack drink = focusedSlot.getStack(); - Text text = drink.getName(); - if (text instanceof MutableText mutableName) { + // Get the item in DRINKS_DISPLAY_SLOT (slot ID 8) + ItemStack drink = this.focusedSlot.getStack(); + Text drinkText = drink.getName(); + if (drinkText instanceof MutableText mutableName) { tooltip.add(mutableName.formatted(drink.getRarity().formatting)); } else { - tooltip.add(text); + tooltip.add(drinkText); } drink.getItem().appendTooltip(drink, handler.blockEntity.getWorld(), tooltip, TooltipContext.Default.BASIC); - String container = ""; // Declare container outside of the if block - - // Retrieve path for last crafted recipe - String lastCraftedRecipe = handler.blockEntity.getLastCraftedRecipeId(); - - // Retrieve container item based on last crafted recipe - ItemStack containerItem = handler.blockEntity.getItemFromLastCraft(lastCraftedRecipe); + // Get the item in REQUIRE_CONTAINER (slot ID 10) + ItemStack containerItem = handler.blockEntity.getStack(REQUIRE_CONTAINER); + String containerName = ""; if (!containerItem.isEmpty()) { - // Get the item from the ItemStack - Item item = containerItem.getItem(); - - // Get the translation key for the item - String translationKey = item.getTranslationKey(); - - // Get the localized name using Text.translatable - container = Text.translatable(translationKey).getString(); + Item container = containerItem.getItem(); + containerName = Text.translatable(container.getTranslationKey()).getString(); } - tooltip.add(UkrainianDelight.i18n("tooltip.slot_item", container).formatted(Formatting.GRAY)); - - // Add debugging output - System.out.println("Tooltip container: " + container); + // 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, focusedSlot.getStack(), mouseX, mouseY); + context.drawItemTooltip(textRenderer, this.focusedSlot.getStack(), mouseX, mouseY); } } } @@ -126,11 +121,6 @@ protected void drawMouseoverTooltip(DrawContext context, int mouseX, int mouseY) - - - - - protected void drawMouseoverTankTooltip(DrawContext context, int mouseX, int mouseY) { int x = (width - backgroundWidth) / 2; int y = (height - backgroundHeight) / 2; @@ -164,5 +154,4 @@ private List getTankTooltip() { return List.of(UkrainianDelight.i18n("tooltip.tank_empty")); } } - } 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 57f0531..0deb80a 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java @@ -23,9 +23,13 @@ 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 WATER_SLOT = 7; - public static final int DRINKS_DISPLAY_SLOT = 8; - public static final int OUTPUT_SLOT = 9; + 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; + + public static final int INVENTORY_SIZE = OUTPUT_SLOT + 1; public FluidStack fluidStack; private final Inventory tileEntity; @@ -37,12 +41,12 @@ public long getCapacity() { } public BrewingKegScreenHandler(int syncId, PlayerInventory tileEntity, PacketByteBuf buf) { - this(syncId, tileEntity, tileEntity.player.getWorld().getBlockEntity(buf.readBlockPos()), new ArrayPropertyDelegate(10)); + this(syncId, tileEntity, tileEntity.player.getWorld().getBlockEntity(buf.readBlockPos()), new ArrayPropertyDelegate(INVENTORY_SIZE)); } public BrewingKegScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity, PropertyDelegate arrayPropertyDelegate) { super(ModScreenHandlers.BREWING_KEG_SCREEN_HANDLER, syncId); - checkSize(((Inventory) blockEntity), 10); + checkSize(((Inventory) blockEntity), INVENTORY_SIZE); this.tileEntity = ((Inventory) blockEntity); tileEntity.onOpen(playerInventory.player); @@ -64,7 +68,20 @@ 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 display slot + // Add require container slot + this.addSlot(new Slot(tileEntity, REQUIRE_CONTAINER, 10, 10) { + @Override + public boolean canInsert(ItemStack stack) { + return false; + } + + @Override + public boolean canTakeItems(PlayerEntity playerEntity) { + return false; + } + }); + + // Add drinks display slot this.addSlot(new Slot(tileEntity, DRINKS_DISPLAY_SLOT, 131, 28) { @Override public boolean canInsert(ItemStack stack) { @@ -130,10 +147,10 @@ public ItemStack quickMove(PlayerEntity playerIn, int index) { return ItemStack.EMPTY; } } else if (index > OUTPUT_SLOT) { - if (slotItemStack.getItem() == Items.BOWL && - !this.insertItem(slotItemStack, DRINKS_DISPLAY_SLOT, OUTPUT_SLOT, false) || + if (slotItemStack.getItem() == Items.GLASS_BOTTLE && + !this.insertItem(slotItemStack, DRINKS_DISPLAY_SLOT, REQUIRE_CONTAINER, false) || !this.insertItem(slotItemStack, 0, 6, false) || - !this.insertItem(slotItemStack, DRINKS_DISPLAY_SLOT, OUTPUT_SLOT, false)) { + !this.insertItem(slotItemStack, DRINKS_DISPLAY_SLOT, REQUIRE_CONTAINER, false)) { return ItemStack.EMPTY; } } else if (index == WATER_SLOT && slotItemStack.getItem() == Items.WATER_BUCKET) { diff --git a/src/main/resources/assets/ukrainian_delight/lang/en_us.json b/src/main/resources/assets/ukrainian_delight/lang/en_us.json index 5423158..2a65390 100644 --- a/src/main/resources/assets/ukrainian_delight/lang/en_us.json +++ b/src/main/resources/assets/ukrainian_delight/lang/en_us.json @@ -69,9 +69,6 @@ "ukrainian_delight.tooltip.water_amount": "%d / %d mB", "ukrainian_delight.tooltip.tank_empty": "Empty", - "ukrainian_delight.tooltip.slot_empty": "Slot is empty", - "ukrainian_delight.tooltip.slot_item": "Poured into %s", - - "ukrainian_delight.container.brewing_keg.served_on": "Served on %s" + "ukrainian_delight.tooltip.slot_item": "Poured into %s" } \ No newline at end of file