diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/UkrainianDelight.java b/src/main/java/com/megatrex4/ukrainian_dlight/UkrainianDelight.java index 2afa5ab..f7cae5c 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/UkrainianDelight.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/UkrainianDelight.java @@ -8,6 +8,7 @@ import com.megatrex4.ukrainian_dlight.item.ModItems; import com.megatrex4.ukrainian_dlight.item.ToolTipHelper; import com.megatrex4.ukrainian_dlight.networking.ModMessages; +import com.megatrex4.ukrainian_dlight.recipe.ModRecipes; import com.megatrex4.ukrainian_dlight.screen.ModScreenHandlers; import com.megatrex4.ukrainian_dlight.screen.ModScreens; import net.fabricmc.api.ModInitializer; @@ -42,6 +43,7 @@ public void onInitialize() { ModBlockEntities.registerBLockEntities(); ModScreenHandlers.registerModScreenHandlers(); ModMessages.registerS2CPackets(); + ModRecipes.registerRecipes(); ModScreens.registerScreens(); 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 5a5f0de..1549985 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 @@ -3,6 +3,7 @@ import com.megatrex4.ukrainian_dlight.block.DrinkBottleBlock; import com.megatrex4.ukrainian_dlight.networking.ModMessages; import com.megatrex4.ukrainian_dlight.recipe.BrewingRecipe; +import com.megatrex4.ukrainian_dlight.recipe.ModRecipes; import com.megatrex4.ukrainian_dlight.screen.BrewingKegScreenHandler; import com.megatrex4.ukrainian_dlight.util.FluidStack; import io.netty.buffer.Unpooled; @@ -62,6 +63,7 @@ public class BrewingKegBlockEntity extends BlockEntity implements ExtendedScreen protected final PropertyDelegate propertyDelegate; private int progress; private int maxProgress = 200; // Adjusted to match the brewing time in the JSON + private ItemStack drinkContainer = ItemStack.EMPTY; public final SingleVariantStorage fluidStorage = new SingleVariantStorage() { @Override @@ -71,9 +73,10 @@ protected FluidVariant getBlankVariant() { @Override protected long getCapacity(FluidVariant variant) { - return FluidStack.convertDropletsToMb(FluidConstants.BUCKET) * 5; // 5k mB + return FluidStack.convertDropletsToMb(FluidConstants.BUCKET) * 15; // 5k mB } + @Override protected void onFinalCommit() { markDirty(); @@ -126,6 +129,11 @@ protected void writeNbt(NbtCompound nbt) { nbt.putInt("brewing_keg.progress", progress); nbt.put("brewing_keg.fluid_variant", fluidStorage.variant.toNbt()); nbt.putLong("brewing_keg.fluid_amount", fluidStorage.amount); + + // Save drinkContainer + NbtCompound containerTag = new NbtCompound(); + drinkContainer.writeNbt(containerTag); + nbt.put("Container", containerTag); } @Override @@ -135,9 +143,15 @@ public void readNbt(NbtCompound nbt) { progress = nbt.getInt("brewing_keg.progress"); fluidStorage.variant = FluidVariant.fromNbt(nbt.getCompound("brewing_keg.fluid_variant")); fluidStorage.amount = nbt.getLong("brewing_keg.fluid_amount"); + + // Load drinkContainer + NbtCompound containerTag = nbt.getCompound("Container"); + drinkContainer = ItemStack.fromNbt(containerTag); } + + private void debugFluidLevel() { System.out.println("Fluid: " + fluidStorage.variant.getFluid().toString()); System.out.println("Amount: " + fluidStorage.amount + " mB"); @@ -168,25 +182,73 @@ public void tick(World world, BlockPos pos, BlockState state) { // Handle water bucket conversion handleWaterBucket(); - if (isOutputSlotEmptyOrReceivable()) { - if (this.hasRecipe() && hasEnoughFluid()) { - this.increaseCraftProgress(); + // Check if a crafted item is ready to be moved to the OUTPUT_SLOT + ItemStack displayStack = getStack(DRINKS_DISPLAY_SLOT); + ItemStack containerStack = getStack(CONTAINER_SLOT); + ItemStack outputStack = getStack(OUTPUT_SLOT); + + // Check if the container matches the saved drinkContainer item + if (!displayStack.isEmpty() && !containerStack.isEmpty() && containerStack.getItem() == drinkContainer.getItem()) { + // Only decrement the container if the OUTPUT_SLOT can receive more items + if (isOutputSlotEmptyOrReceivable(outputStack)) { + containerStack.decrement(1); + + if (outputStack.isEmpty()) { + setStack(OUTPUT_SLOT, new ItemStack(displayStack.getItem(), 1)); + displayStack.decrement(1); + } else if (ItemStack.canCombine(outputStack, displayStack)) { + int maxCount = outputStack.getMaxCount(); + if (outputStack.getCount() < maxCount) { + outputStack.increment(1); + displayStack.decrement(1); + } + } + + // Clear the DRINKS_DISPLAY_SLOT and drinkContainer if empty + if (displayStack.isEmpty()) { + setStack(DRINKS_DISPLAY_SLOT, ItemStack.EMPTY); + drinkContainer = ItemStack.EMPTY; + } + markDirty(world, pos, state); + } + } - if (hasCraftingFinished()) { - this.craftItem(); - extractFluid(); + Optional match = getCurrentRecipe(); + if (match.isPresent()) { + BrewingRecipe recipe = match.get(); + ItemStack output = recipe.craft(this, world.getRegistryManager()); + + if (isDisplaySlotEmptyOrReceivable(output)) { + if (this.hasRecipe() && hasEnoughFluid()) { + this.increaseCraftProgress(); + markDirty(world, pos, state); + + if (hasCraftingFinished()) { + this.craftItem(); + this.resetProgress(); + } + } else { this.resetProgress(); } } else { this.resetProgress(); + markDirty(world, pos, state); } - } else { - this.resetProgress(); - markDirty(world, pos, state); } } + + private boolean isOutputSlotEmptyOrReceivable(ItemStack output) { + ItemStack outputStack = this.getStack(OUTPUT_SLOT); + return outputStack.isEmpty() || (ItemStack.canCombine(outputStack, output) && outputStack.getCount() < outputStack.getMaxCount()); + } + + + + + + private void handleWaterBucket() { ItemStack waterBucketStack = this.getStack(WATER_SLOT); @@ -206,12 +268,6 @@ private void handleWaterBucket() { } } - private void extractFluid() { - try (Transaction transaction = Transaction.openOuter()) { - this.fluidStorage.extract(FluidVariant.of(Fluids.WATER), 500, transaction); - transaction.commit(); - } - } private static void transferFluidToFluidStorage(BrewingKegBlockEntity entity) { try(Transaction transaction = Transaction.openOuter()) { @@ -224,9 +280,15 @@ private static void transferFluidToFluidStorage(BrewingKegBlockEntity entity) { private boolean hasEnoughFluid() { - return this.fluidStorage.amount >= 500; // mB amount! + Optional match = getCurrentRecipe(); + if (match.isPresent()) { + BrewingRecipe recipe = match.get(); + return fluidStorage.amount >= recipe.getWaterAmount(); + } + return false; } + private void sendFluidPacket() { PacketByteBuf data = PacketByteBufs.create(); fluidStorage.variant.toPacket(data); @@ -247,12 +309,6 @@ private void resetProgress() { this.progress = 0; } - private void craftItem() { - this.removeStack(INGREDIENT_SLOT_1, 1); - ItemStack result = new ItemStack(DrinkBottleBlock.WINE_BOTTLE); - this.setStack(OUTPUT_SLOT, new ItemStack(result.getItem(), getStack(OUTPUT_SLOT).getCount() + result.getCount())); - } - private boolean hasCraftingFinished() { return progress >= maxProgress; } @@ -261,9 +317,86 @@ private void increaseCraftProgress() { progress++; } + private Optional getCurrentRecipe() { + if (world == null) return Optional.empty(); + return world.getRecipeManager().getFirstMatch(ModRecipes.BREWING, this, world); + } + private boolean hasRecipe() { - Optional recipe = world.getRecipeManager().getFirstMatch(BrewingRecipe.Type.INSTANCE, this, world); - return recipe.isPresent() && canInsertAmountIntoOutputSlot(recipe.get().getResult()) && canInsertItemIntoOutputSlot(recipe.get().getResult().getItem()); + Optional match = getCurrentRecipe(); + if (match.isPresent()) { + BrewingRecipe recipe = match.get(); + boolean hasWater = fluidStorage.amount >= recipe.getWaterAmount(); + return hasWater && match.get().matches(this, world); + } + return false; + } + + + private void craftItem() { + Optional match = getCurrentRecipe(); + if (match.isPresent()) { + BrewingRecipe recipe = match.get(); + ItemStack output = recipe.craft(this, world.getRegistryManager()); + + // Check if all ingredient slots have enough items + for (int i = 0; i < 6; i++) { + ItemStack ingredientStack = getStack(i); + if (ingredientStack.getCount() <= 0) { + return; // Stop crafting if any ingredient slot is empty + } + } + + // Ensure the crafting only starts if the DRINKS_DISPLAY_SLOT is empty or contains the same item + if (!getStack(DRINKS_DISPLAY_SLOT).isEmpty() && !ItemStack.canCombine(getStack(DRINKS_DISPLAY_SLOT), output)) { + return; + } + + // Check if there's enough fluid for the recipe + if (hasEnoughFluid()) { + extractFluid(recipe.getWaterAmount()); + + // Decrement ingredients + for (int i = 0; i < 6; i++) { + getStack(i).decrement(1); + } + + // Move the crafted item to the DRINKS_DISPLAY_SLOT + if (!output.isEmpty()) { + if (getStack(DRINKS_DISPLAY_SLOT).isEmpty()) { + setStack(DRINKS_DISPLAY_SLOT, new ItemStack(output.getItem(), 1)); // Only one bottle + drinkContainer = recipe.getContainer(); // Save the container item from the recipe + } else if (ItemStack.canCombine(getStack(DRINKS_DISPLAY_SLOT), output)) { + getStack(DRINKS_DISPLAY_SLOT).increment(1); // Only increment by one + } else { + // Handle case where items cannot combine but DRINKS_DISPLAY_SLOT is not empty + return; + } + } + + // Mark the block entity as dirty after crafting + markDirty(); + } + } + } + + + + + + + + + + + + + + private void extractFluid(int amount) { + try (Transaction transaction = Transaction.openOuter()) { + this.fluidStorage.extract(FluidVariant.of(Fluids.WATER), amount, transaction); + transaction.commit(); + } } private boolean canInsertItemIntoOutputSlot(Item item) { @@ -274,8 +407,9 @@ private boolean canInsertAmountIntoOutputSlot(ItemStack result) { return this.getStack(OUTPUT_SLOT).getCount() + result.getCount() <= this.getStack(OUTPUT_SLOT).getMaxCount(); } - private boolean isOutputSlotEmptyOrReceivable() { - return this.getStack(OUTPUT_SLOT).isEmpty() || this.getStack(OUTPUT_SLOT).getCount() < this.getStack(OUTPUT_SLOT).getMaxCount(); + private boolean isDisplaySlotEmptyOrReceivable(ItemStack output) { + ItemStack displayStack = this.getStack(DRINKS_DISPLAY_SLOT); + return displayStack.isEmpty() || (ItemStack.canCombine(displayStack, output) && displayStack.getCount() < displayStack.getMaxCount()); } public void syncFluidToClient() { diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipe.java b/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipe.java index 0209239..5a8b371 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipe.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipe.java @@ -4,85 +4,51 @@ import com.google.gson.JsonObject; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; -import net.minecraft.recipe.*; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; import net.minecraft.util.collection.DefaultedList; import net.minecraft.world.World; -import net.minecraft.registry.DynamicRegistryManager; + +import java.util.ArrayList; +import java.util.List; public class BrewingRecipe implements Recipe { private final Identifier id; - private final DefaultedList ingredients; private final ItemStack result; + private final DefaultedList ingredients; + private final ItemStack container; private final int brewingTime; private final float experience; - // private final int waterAmount; - private final ItemStack container; + private final int waterAmount; - public BrewingRecipe(Identifier id, DefaultedList ingredients, ItemStack result, int brewingTime, float experience, - //int waterAmount, - ItemStack container) { + public BrewingRecipe(Identifier id, ItemStack result, DefaultedList ingredients, ItemStack container, int brewingTime, float experience, int waterAmount) { this.id = id; - this.ingredients = ingredients; this.result = result; + this.ingredients = ingredients; + this.container = container; this.brewingTime = brewingTime; this.experience = experience; - // this.waterAmount = waterAmount; - this.container = container; - } - - public static BrewingRecipe fromJson(Identifier id, JsonObject json) { - JsonArray ingredientsArray = JsonHelper.getArray(json, "ingredients"); - DefaultedList ingredients = DefaultedList.ofSize(ingredientsArray.size(), Ingredient.EMPTY); - for (int i = 0; i < ingredientsArray.size(); i++) { - ingredients.set(i, Ingredient.fromJson(ingredientsArray.get(i))); - } - - ItemStack result = ShapedRecipe.outputFromJson(JsonHelper.getObject(json, "result")); - int brewingTime = JsonHelper.getInt(json, "brewingtime"); - float experience = JsonHelper.getFloat(json, "experience"); - //int waterAmount = JsonHelper.getInt(json, "water"); - ItemStack container = ShapedRecipe.outputFromJson(JsonHelper.getObject(json, "container")); - - return new BrewingRecipe(id, ingredients, result, brewingTime, experience, - //waterAmount, - container); - } - - public DefaultedList getIngredients() { - return ingredients; - } - - public ItemStack getResult() { - return result; - } - - public int getBrewingTime() { - return brewingTime; - } - - public float getExperience() { - return experience; - } - -// public int getWaterAmount() { -// return waterAmount; -// } - - public ItemStack getContainer() { - return container; + this.waterAmount = waterAmount; } @Override public boolean matches(Inventory inv, World world) { - // Implement matching logic - return false; + List remainingIngredients = new ArrayList<>(ingredients); + for (int i = 0; i < 6; i++) { + ItemStack stack = inv.getStack(i); + remainingIngredients.removeIf(ingredient -> ingredient.test(stack)); + } + return remainingIngredients.isEmpty(); } @Override public ItemStack craft(Inventory inv, DynamicRegistryManager registryManager) { - return getResult().copy(); + return result.copy(); } @Override @@ -92,7 +58,7 @@ public boolean fits(int width, int height) { @Override public ItemStack getOutput(DynamicRegistryManager registryManager) { - return getResult(); + return result; } @Override @@ -102,17 +68,32 @@ public Identifier getId() { @Override public RecipeSerializer getSerializer() { - return BrewingRecipeSerializer.INSTANCE; + return ModRecipes.BREWING_RECIPE_SERIALIZER; } @Override public RecipeType getType() { - return Type.INSTANCE; + return ModRecipes.BREWING; + } + + public ItemStack getContainer() { + return container; } - public static class Type implements RecipeType { - private Type() {} - public static final Type INSTANCE = new Type(); - public static final String ID = "brewing"; + public int getBrewingTime() { + return brewingTime; + } + + public float getExperience() { + return experience; + } + + public int getWaterAmount() { + return waterAmount; + } + + @Override + public DefaultedList getIngredients() { + return ingredients; } } diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipeSerializer.java b/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipeSerializer.java index c906234..95c3985 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipeSerializer.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/recipe/BrewingRecipeSerializer.java @@ -1,41 +1,66 @@ package com.megatrex4.ukrainian_dlight.recipe; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; +import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.recipe.RecipeType; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; +import net.minecraft.recipe.ShapedRecipe; import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; +import net.minecraft.util.collection.DefaultedList; + +import java.util.ArrayList; +import java.util.List; public class BrewingRecipeSerializer implements RecipeSerializer { @Override public BrewingRecipe read(Identifier id, JsonObject json) { - return BrewingRecipe.fromJson(id, json); + ItemStack result = ShapedRecipe.outputFromJson(JsonHelper.getObject(json, "result")); + JsonArray ingredientsArray = JsonHelper.getArray(json, "ingredients"); + DefaultedList ingredients = DefaultedList.ofSize(ingredientsArray.size(), Ingredient.EMPTY); + + for (int i = 0; i < ingredientsArray.size(); i++) { + JsonObject ingredientObject = ingredientsArray.get(i).getAsJsonObject(); + ingredients.set(i, Ingredient.fromJson(ingredientObject)); + } + + ItemStack container = ShapedRecipe.outputFromJson(JsonHelper.getObject(json, "container")); + int brewingTime = JsonHelper.getInt(json, "brewingtime"); + float experience = JsonHelper.getFloat(json, "experience"); + int waterAmount = JsonHelper.getInt(json, "water"); + + return new BrewingRecipe(id, result, ingredients, container, brewingTime, experience, waterAmount); } @Override public BrewingRecipe read(Identifier id, PacketByteBuf buf) { - // Implement packet reading logic if necessary - return null; + int size = buf.readInt(); + DefaultedList ingredients = DefaultedList.ofSize(size, Ingredient.EMPTY); + for (int i = 0; i < size; i++) { + ingredients.set(i, Ingredient.fromPacket(buf)); + } + ItemStack container = buf.readItemStack(); + ItemStack result = buf.readItemStack(); + int brewingTime = buf.readInt(); + float experience = buf.readFloat(); + int waterAmount = buf.readInt(); + return new BrewingRecipe(id, result, ingredients, container, brewingTime, experience, waterAmount); } @Override public void write(PacketByteBuf buf, BrewingRecipe recipe) { - // Implement packet writing logic if necessary - } - - public static final RecipeSerializer INSTANCE = new BrewingRecipeSerializer(); - public static final Identifier ID = new Identifier("ukrainian_dlight", "brewing"); - - public static void register() { - Registry.register(Registries.RECIPE_SERIALIZER, ID, INSTANCE); - Registry.register(Registries.RECIPE_TYPE, ID, new RecipeType() { - @Override - public String toString() { - return ID.toString(); - } - }); + buf.writeInt(recipe.getIngredients().size()); + for (Ingredient ingredient : recipe.getIngredients()) { + ingredient.write(buf); + } + buf.writeItemStack(recipe.getContainer()); + buf.writeItemStack(recipe.getOutput(null)); // The registryManager parameter is not used here. + buf.writeInt(recipe.getBrewingTime()); + buf.writeFloat(recipe.getExperience()); + buf.writeInt(recipe.getWaterAmount()); } } diff --git a/src/main/java/com/megatrex4/ukrainian_dlight/recipe/ModRecipes.java b/src/main/java/com/megatrex4/ukrainian_dlight/recipe/ModRecipes.java new file mode 100644 index 0000000..9c83a5a --- /dev/null +++ b/src/main/java/com/megatrex4/ukrainian_dlight/recipe/ModRecipes.java @@ -0,0 +1,19 @@ +package com.megatrex4.ukrainian_dlight.recipe; + +import com.megatrex4.ukrainian_dlight.UkrainianDelight; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.util.Identifier; + +public class ModRecipes { + public static final RecipeType BREWING = RecipeType.register(new Identifier("ukrainian_delight", "brewing").toString()); + public static final RecipeSerializer BREWING_RECIPE_SERIALIZER = new BrewingRecipeSerializer(); + + public static void registerRecipes() { + + Registry.register(Registries.RECIPE_SERIALIZER, new Identifier("ukrainian_delight", "brewing"), BREWING_RECIPE_SERIALIZER); + UkrainianDelight.LOGGER.info("Registering Recipes for " + UkrainianDelight.MOD_ID); + } +} 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 cbcccff..9978917 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreen.java @@ -6,9 +6,15 @@ import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.GameRenderer; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; +import java.util.List; + public class BrewingKegScreen extends HandledScreen { private static final Identifier TEXTURE = new Identifier(UkrainianDelight.MOD_ID, "textures/gui/brewing_keg_gui.png"); @@ -57,4 +63,41 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); drawMouseoverTooltip(context, mouseX, mouseY); } + + @Override + protected void drawMouseoverTooltip(DrawContext context, int mouseX, int mouseY) { + super.drawMouseoverTooltip(context, mouseX, mouseY); + + int x = (width - backgroundWidth) / 2; + int y = (height - backgroundHeight) / 2; + + if (isMouseOverTankArea(mouseX, mouseY, x, y)) { + List tooltip = getTankTooltip(); + context.drawTooltip(textRenderer, tooltip, mouseX, mouseY); + } + } + + private boolean isMouseOverTankArea(int mouseX, int mouseY, int x, int y) { + int tankX = x + 30; + int tankY = y + 12; + int tankWidth = 16; + int tankHeight = 40; + + return mouseX >= tankX && mouseX < tankX + tankWidth && mouseY >= tankY && mouseY < tankY + tankHeight; + } + + private List getTankTooltip() { + long fluidAmount = handler.fluidStack.amount; + long maxFluidAmount = handler.getCapacity(); // Ensure this method exists in your handler + MutableText fluidName = Text.translatable("block." + Registries.FLUID.getId(handler.fluidStack.fluidVariant.getFluid()).toTranslationKey()); + + if (fluidAmount > 0) { + return List.of( + fluidName, + Text.translatable("text.megatrex4.water_amount", fluidAmount, maxFluidAmount).formatted(Formatting.GRAY) + ); + } else { + return List.of(Text.translatable("text.megatrex4.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 34c4b70..8e33f41 100644 --- a/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java +++ b/src/main/java/com/megatrex4/ukrainian_dlight/screen/BrewingKegScreenHandler.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.network.PacketByteBuf; import net.minecraft.screen.ArrayPropertyDelegate; import net.minecraft.screen.PropertyDelegate; @@ -16,11 +17,29 @@ public class BrewingKegScreenHandler extends ScreenHandler { + public static final int INGREDIENT_SLOT_1 = 0; + public static final int INGREDIENT_SLOT_2 = 1; + public static final int INGREDIENT_SLOT_3 = 2; + public static final int INGREDIENT_SLOT_4 = 3; + public static final int INGREDIENT_SLOT_5 = 4; + public static final int INGREDIENT_SLOT_6 = 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 FluidStack fluidStack; private final Inventory inventory; private final PropertyDelegate propertyDelegate; public final BrewingKegBlockEntity blockEntity; + public long getCapacity() { + return blockEntity.getMaxWaterLevel(); + } + public BrewingKegScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) { this(syncId, inventory, inventory.player.getWorld().getBlockEntity(buf.readBlockPos()), new ArrayPropertyDelegate(10)); @@ -104,30 +123,65 @@ public int getScaledWaterLevel() { } @Override - public ItemStack quickMove(PlayerEntity player, int invSlot) { - ItemStack newStack = ItemStack.EMPTY; - Slot slot = this.slots.get(invSlot); - if (slot != null && slot.hasStack()) { - ItemStack originalStack = slot.getStack(); - newStack = originalStack.copy(); - if (invSlot < this.inventory.size()) { - if (!this.insertItem(originalStack, this.inventory.size(), this.slots.size(), true)) { + public ItemStack quickMove(PlayerEntity playerIn, int index) { + if (index > this.slots.size() - 1) { + return ItemStack.EMPTY; + } else { + ItemStack itemStack = ItemStack.EMPTY; + Slot slot = (Slot)this.slots.get(index); + if (slot.hasStack()) { + ItemStack slotItemStack = slot.getStack(); + itemStack = slotItemStack.copy(); + + // Adjusting the slot handling based on your custom slots + if (index == OUTPUT_SLOT) { + if (!this.insertItem(slotItemStack, 9, 45, true)) { + return ItemStack.EMPTY; + } + } else if (index > OUTPUT_SLOT) { + if (slotItemStack.getItem() == Items.BOWL && + !this.insertItem(slotItemStack, DRINKS_DISPLAY_SLOT, OUTPUT_SLOT, false) || + !this.insertItem(slotItemStack, 0, 6, false) || + !this.insertItem(slotItemStack, DRINKS_DISPLAY_SLOT, OUTPUT_SLOT, false)) { + return ItemStack.EMPTY; + } + } else if (index == WATER_SLOT && slotItemStack.getItem() == Items.WATER_BUCKET) { + // Inserting water bucket into WATER_SLOT first + if (!this.insertItem(slotItemStack, WATER_SLOT, WATER_SLOT + 1, false)) { + return ItemStack.EMPTY; + } + } else if (index == WATER_SLOT) { + // If it's not a water bucket, but it's going into WATER_SLOT, try to insert + if (!this.insertItem(slotItemStack, WATER_SLOT + 1, this.slots.size(), false)) { + return ItemStack.EMPTY; + } + } else if (!this.insertItem(slotItemStack, 9, 45, false)) { + return ItemStack.EMPTY; + } + + if (slotItemStack.isEmpty()) { + slot.setStack(ItemStack.EMPTY); + } else { + slot.markDirty(); + } + + if (slotItemStack.getCount() == itemStack.getCount()) { return ItemStack.EMPTY; } - } else if (!this.insertItem(originalStack, 0, this.inventory.size(), false)) { - return ItemStack.EMPTY; - } - if (originalStack.isEmpty()) { - slot.setStack(ItemStack.EMPTY); - } else { - slot.markDirty(); + slot.onTakeItem(playerIn, slotItemStack); } - } - return newStack; + return itemStack; + } } + + + + + + @Override public boolean canUse(PlayerEntity player) { return this.inventory.canPlayerUse(player); 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 7a66b90..b3c5f80 100644 --- a/src/main/resources/assets/ukrainian_delight/lang/en_us.json +++ b/src/main/resources/assets/ukrainian_delight/lang/en_us.json @@ -64,6 +64,9 @@ "amplifier.7": " VII", "amplifier.8": " VIII", "amplifier.9": " IX", - "amplifier.10": " X" + "amplifier.10": " X", + + "text.megatrex4.water_amount": "%d / %d mB", + "text.megatrex4.empty": "Empty" } \ No newline at end of file diff --git a/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpoop.json b/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpoop.json new file mode 100644 index 0000000..691b7aa --- /dev/null +++ b/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpoop.json @@ -0,0 +1,20 @@ +{ + "type": "ukrainian_delight:brewing", + "container": { + "item": "minecraft:glass_bottle" + }, + "brewingtime": 200, + "experience": 1.0, + "water": 100, + "ingredients": [ + { + "item": "minecraft:wheat" + }, + { + "item": "minecraft:sugar" + } + ], + "result": { + "item": "ukrainian_delight:wine_bottle" + } +} diff --git a/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpotion.json b/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpotion.json index aab2f74..787f06f 100644 --- a/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpotion.json +++ b/src/main/resources/data/ukrainian_delight/recipes/brewing/brewpotion.json @@ -1,32 +1,20 @@ { "type": "ukrainian_delight:brewing", "container": { - "item": "minecraft:glass_bottle" + "item": "ukrainian_delight:wine_bottle" }, - "brewingtime": 200, + "brewingtime": 20, "experience": 1.0, - "water": 100, + "water": 10, "ingredients": [ - { - "item": "minecraft:wheat" - }, - { - "item": "minecraft:sugar" - }, { "item": "minecraft:nether_wart" }, { "item": "minecraft:carrot" - }, - { - "tag": "minecraft:flowers" - }, - { - "tag": "minecraft:seeds" } ], "result": { - "item": "minecraft:potion" + "item": "minecraft:apple" } }