Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
int stirring = state.getValue(STIRRING);
int stirred = state.getValue(STIRRED);

if (player.isShiftKeyDown()) {
if (player.isShiftKeyDown() || (stirred >= STIRS_NEEDED && stirring == 0)) {
for (int i = 0; i < bowl.getContainerSize(); i++) {
ItemStack stack = bowl.getItem(i);
if (!stack.isEmpty()) {
Expand All @@ -122,21 +122,12 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
one.setCount(1);
bowl.addItemStack(one);
if (!player.isCreative()) main.shrink(1);
level.setBlock(pos, state.setValue(STIRRED, 0), 3);
return InteractionResult.SUCCESS;
}
}

if (!anyHeld) {
if (stirred >= 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ public Optional<CraftingBowlRecipe> 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<RecipeHolder<CraftingBowlRecipe>> 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<CraftingBowlRecipe> holder : recipes) {
CraftingBowlRecipe r = holder.value();
int needed = 0;
Expand All @@ -180,7 +184,8 @@ private CraftingBowlRecipe matchExact(List<RecipeHolder<CraftingBowlRecipe>> 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;
Expand Down Expand Up @@ -227,30 +232,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<CraftingBowlRecipe> recipe = be.findRecipe(level);
if (recipe.isPresent() && stirred < CraftingBowlBlock.STIRS_NEEDED) {
stirred++;
if (stirred == CraftingBowlBlock.STIRS_NEEDED) {
NonNullList<Ingredient> 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 && this.numberOfIngredientsInBowl() > 0) {
Optional<CraftingBowlRecipe> 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());
Expand Down