This commit is contained in:
paulevsGitch 2021-01-30 11:53:42 +03:00
commit 2a0ebe4b25
3 changed files with 34 additions and 11 deletions

View file

@ -113,7 +113,7 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<In
}
protected boolean isSmeltable(ItemStack itemStack) {
return this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, new SimpleInventory(new ItemStack[]{itemStack}), this.world).isPresent();
return this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, new SimpleInventory(itemStack), this.world).isPresent();
}
public boolean isFuel(ItemStack itemStack) {
@ -141,11 +141,11 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<In
if (!this.insertItem(itemStack2, 2, 3, false)) {
return ItemStack.EMPTY;
}
} else if (index >= 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)) {

View file

@ -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<Boolean> 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<ItemStack> 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();
}

View file

@ -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<Inventory>, BetterEndRecipe {
public final static String GROUP = "smithing";
@ -71,9 +73,8 @@ public class AnvilRecipe implements Recipe<Inventory>, 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);
});
@ -81,6 +82,13 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
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);
if (hammer.isEmpty() || !EndTags.HAMMERS.contains(hammer.getItem())) {
@ -126,6 +134,19 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
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<Inventory>, BetterEndRecipe {
packetBuffer.writeVarInt(recipe.level);
packetBuffer.writeVarInt(recipe.damage);
}
}
}