diff --git a/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreenHandler.java b/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreenHandler.java index d6eb2249..f8a00502 100644 --- a/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreenHandler.java +++ b/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreenHandler.java @@ -113,7 +113,7 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler= 4 && index < 31) { + } else if (index < 31) { if (!insertItem(itemStack2, 31, 40, false)) { return ItemStack.EMPTY; } - } else if (index >= 31 && index < 40 && !insertItem(itemStack2, 4, 31, false)) { + } else if (index < 40 && !insertItem(itemStack2, 4, 31, false)) { return ItemStack.EMPTY; } } else if (!insertItem(itemStack2, 4, 40, false)) { diff --git a/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java b/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java index c90e7f81..4367431d 100644 --- a/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java @@ -41,10 +41,7 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple @Inject(method = "canTakeOutput", at = @At("HEAD"), cancellable = true) protected void be_canTakeOutput(PlayerEntity player, boolean present, CallbackInfoReturnable info) { if (be_currentRecipe != null) { - ItemStack output = this.be_currentRecipe.craft(input, player); - if (!output.isEmpty()) { - info.setReturnValue(true); - } + info.setReturnValue(be_currentRecipe.checkHammerDurability(input, player)); } } @@ -52,6 +49,7 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple protected void be_onTakeOutput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable info) { if (be_currentRecipe != null) { this.input.getStack(0).decrement(1); + stack = be_currentRecipe.craft(input, player); this.onContentChanged(input); this.context.run((world, blockPos) -> { BlockState anvilState = world.getBlockState(blockPos); @@ -77,7 +75,9 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple RecipeManager recipeManager = this.player.world.getRecipeManager(); this.be_recipes = recipeManager.getAllMatches(AnvilRecipe.TYPE, input, player.world); if (be_recipes.size() > 0) { - this.be_currentRecipe = recipeManager.getFirstMatch(AnvilRecipe.TYPE, input, player.world).get(); + if (be_currentRecipe == null || !be_recipes.contains(be_currentRecipe)) { + this.be_currentRecipe = be_recipes.get(0); + } this.be_updateResult(); info.cancel(); } diff --git a/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java b/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java index d38a5095..eef5ce40 100644 --- a/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java @@ -28,6 +28,8 @@ import ru.betterend.registry.EndTags; import ru.betterend.util.ItemUtil; import ru.betterend.util.RecipeHelper; +import java.util.Objects; + public class AnvilRecipe implements Recipe, BetterEndRecipe { public final static String GROUP = "smithing"; @@ -71,15 +73,21 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { public ItemStack craft(Inventory craftingInventory, PlayerEntity player) { if (!player.isCreative()) { + if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY; ItemStack hammer = craftingInventory.getStack(1); - int damage = hammer.getDamage() + this.damage; - if (damage >= hammer.getMaxDamage()) return ItemStack.EMPTY; hammer.damage(this.damage, player, entity -> { entity.sendEquipmentBreakStatus(null); }); } return this.craft(craftingInventory); } + + public boolean checkHammerDurability(Inventory craftingInventory, PlayerEntity player) { + if (player.isCreative()) return true; + ItemStack hammer = craftingInventory.getStack(1); + int damage = hammer.getDamage() + this.damage; + return damage < hammer.getMaxDamage(); + } public boolean matches(Inventory craftingInventory) { ItemStack hammer = craftingInventory.getStack(1); @@ -125,7 +133,20 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { public boolean isIgnoredInRecipeBook() { return true; } - + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AnvilRecipe that = (AnvilRecipe) o; + return damage == that.damage && level == that.level && id.equals(that.id) && input.equals(that.input) && output.equals(that.output); + } + + @Override + public int hashCode() { + return Objects.hash(id, input, output, damage, level); + } + public static class Builder { private final static Builder INSTANCE = new Builder(); @@ -244,5 +265,7 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { packetBuffer.writeVarInt(recipe.level); packetBuffer.writeVarInt(recipe.damage); } + + } }