From f25fd3b655f2713f257e7410943fb96a09aa325b Mon Sep 17 00:00:00 2001 From: khoidauminh Date: Thu, 26 Feb 2026 22:54:27 +0700 Subject: [PATCH 1/2] Crafting Bowl: Simplify implemenation --- .../renderer/block/CraftingBowlRenderer.java | 2 +- .../core/block/CraftingBowlBlock.java | 15 ++------- .../block/entity/CraftingBowlBlockEntity.java | 33 +++++-------------- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/common/src/main/java/net/satisfy/farm_and_charm/client/renderer/block/CraftingBowlRenderer.java b/common/src/main/java/net/satisfy/farm_and_charm/client/renderer/block/CraftingBowlRenderer.java index da76a14f..07d899d6 100644 --- a/common/src/main/java/net/satisfy/farm_and_charm/client/renderer/block/CraftingBowlRenderer.java +++ b/common/src/main/java/net/satisfy/farm_and_charm/client/renderer/block/CraftingBowlRenderer.java @@ -43,7 +43,7 @@ public void render(CraftingBowlBlockEntity be, float f, PoseStack pose, MultiBuf pose.mulPose(Axis.XP.rotationDegrees(180)); pose.translate(0.5f, -1.5f, -0.5f); - ResourceLocation tex = be.getStirringProgress() >= CraftingBowlBlock.STIRS_NEEDED + ResourceLocation tex = be.getStirringProgress() > CraftingBowlBlock.STIRS_NEEDED ? ResourceLocation.fromNamespaceAndPath(FarmAndCharm.MOD_ID, "textures/entity/crafting_bowl_full.png") : ResourceLocation.fromNamespaceAndPath(FarmAndCharm.MOD_ID, "textures/entity/crafting_bowl.png"); diff --git a/common/src/main/java/net/satisfy/farm_and_charm/core/block/CraftingBowlBlock.java b/common/src/main/java/net/satisfy/farm_and_charm/core/block/CraftingBowlBlock.java index c35a24af..0032ed3d 100644 --- a/common/src/main/java/net/satisfy/farm_and_charm/core/block/CraftingBowlBlock.java +++ b/common/src/main/java/net/satisfy/farm_and_charm/core/block/CraftingBowlBlock.java @@ -103,7 +103,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder= STIRS_NEEDED && stirring == 0)) { for (int i = 0; i < bowl.getContainerSize(); i++) { ItemStack stack = bowl.getItem(i); if (!stack.isEmpty()) { @@ -122,21 +122,12 @@ protected void createBlockStateDefinition(StateDefinition.Builder= STIRS_NEEDED && stirring == 0) { - ItemStack out = bowl.getItem(4); - if (!out.isEmpty()) { - popResource(level, pos, out); - bowl.setItem(4, ItemStack.EMPTY); - level.setBlock(pos, state.setValue(STIRRED, 0), 3); - bowl.setChanged(); - return InteractionResult.SUCCESS; - } - } + if (!anyHeld || !bowl.canAddItem()) { if (level instanceof ServerLevel server) { RandomSource r = server.random; for (int i = 0; i < 4; i++) { diff --git a/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java b/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java index 4b4d4447..04fd82f2 100644 --- a/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java +++ b/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java @@ -227,30 +227,15 @@ public void tick(Level level, BlockPos pos, BlockState state, CraftingBowlBlockE if (!level.isClientSide && state.getBlock() instanceof CraftingBowlBlock) { int stirred = state.getValue(CraftingBowlBlock.STIRRED); if (stirring > 0) { - Optional recipe = be.findRecipe(level); - if (recipe.isPresent() && stirred < CraftingBowlBlock.STIRS_NEEDED) { - stirred++; - if (stirred == CraftingBowlBlock.STIRS_NEEDED) { - NonNullList ings = recipe.get().getIngredients(); - boolean[] used = new boolean[4]; - for (Ingredient ing : ings) { - if (ing.isEmpty()) continue; - for (int i = 0; i < 4; i++) { - if (!used[i] && ing.test(be.getItem(i))) { - ItemStack stack = be.getItem(i); - ItemStack remainder = getRemainderItem(stack); - stack.shrink(1); - if (stack.isEmpty()) be.setItem(i, ItemStack.EMPTY); - if (!remainder.isEmpty()) { - double ox = level.random.nextDouble() * 0.7D + 0.15D; - double oy = level.random.nextDouble() * 0.7D + 0.15D; - double oz = level.random.nextDouble() * 0.7D + 0.15D; - level.addFreshEntity(new ItemEntity(level, pos.getX() + ox, pos.getY() + oy, pos.getZ() + oz, remainder)); - } - used[i] = true; - break; - } - } + if (stirred < CraftingBowlBlock.STIRS_NEEDED) stirred += 1; + if (stirred == CraftingBowlBlock.STIRS_NEEDED) { + Optional recipe = be.findRecipe(level); + if (recipe.isPresent()) { + stirred += 1; + for (int i = 0; i < 4; i++) { + ItemStack stack = be.getItem(i); + ItemStack remainder = getRemainderItem(stack); + be.setItem(i, remainder); } ItemStack resultItem = recipe.get().getResultItem(level.registryAccess()).copy(); resultItem.setCount(recipe.get().getOutputCount()); From 516f183b762ce93c2f2a7143c93471cd0bb0cb9f Mon Sep 17 00:00:00 2001 From: khoidauminh Date: Fri, 27 Feb 2026 08:52:45 +0700 Subject: [PATCH 2/2] Crafting bowl: Additionally only check if it is not empty --- .../block/entity/CraftingBowlBlockEntity.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java b/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java index 04fd82f2..c28664e3 100644 --- a/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java +++ b/common/src/main/java/net/satisfy/farm_and_charm/core/block/entity/CraftingBowlBlockEntity.java @@ -162,13 +162,17 @@ public Optional findRecipe(Level level) { return Optional.ofNullable(matchExact(all)); } + private int numberOfIngredientsInBowl() { + int num = 0; + if (!this.getItem(0).isEmpty()) num += 1; + if (!this.getItem(1).isEmpty()) num += 1; + if (!this.getItem(2).isEmpty()) num += 1; + if (!this.getItem(3).isEmpty()) num += 1; + return num; + } + private CraftingBowlRecipe matchExact(List> recipes) { - ItemStack[] inputs = new ItemStack[4]; - int present = 0; - for (int i = 0; i < 4; i++) { - inputs[i] = this.getItem(i); - if (!inputs[i].isEmpty()) present++; - } + int present = this.numberOfIngredientsInBowl(); for (RecipeHolder holder : recipes) { CraftingBowlRecipe r = holder.value(); int needed = 0; @@ -180,7 +184,8 @@ private CraftingBowlRecipe matchExact(List> rec if (ing.isEmpty()) continue; boolean matched = false; for (int i = 0; i < 4; i++) { - if (!used[i] && !inputs[i].isEmpty() && ing.test(inputs[i])) { + ItemStack item = this.getItem(i); + if (!used[i] && !item.isEmpty() && ing.test(item)) { used[i] = true; matched = true; break; @@ -228,7 +233,7 @@ public void tick(Level level, BlockPos pos, BlockState state, CraftingBowlBlockE int stirred = state.getValue(CraftingBowlBlock.STIRRED); if (stirring > 0) { if (stirred < CraftingBowlBlock.STIRS_NEEDED) stirred += 1; - if (stirred == CraftingBowlBlock.STIRS_NEEDED) { + if (stirred == CraftingBowlBlock.STIRS_NEEDED && this.numberOfIngredientsInBowl() > 0) { Optional recipe = be.findRecipe(level); if (recipe.isPresent()) { stirred += 1;