Anvil craft fixes
This commit is contained in:
parent
7b1c9ec0fb
commit
4cba51a9de
3 changed files with 34 additions and 11 deletions
|
@ -113,7 +113,7 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<In
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isSmeltable(ItemStack itemStack) {
|
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) {
|
public boolean isFuel(ItemStack itemStack) {
|
||||||
|
@ -141,11 +141,11 @@ public class EndStoneSmelterScreenHandler extends AbstractRecipeScreenHandler<In
|
||||||
if (!this.insertItem(itemStack2, 2, 3, false)) {
|
if (!this.insertItem(itemStack2, 2, 3, false)) {
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
} else if (index >= 4 && index < 31) {
|
} else if (index < 31) {
|
||||||
if (!insertItem(itemStack2, 31, 40, false)) {
|
if (!insertItem(itemStack2, 31, 40, false)) {
|
||||||
return ItemStack.EMPTY;
|
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;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
} else if (!insertItem(itemStack2, 4, 40, false)) {
|
} else if (!insertItem(itemStack2, 4, 40, false)) {
|
||||||
|
|
|
@ -41,10 +41,7 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple
|
||||||
@Inject(method = "canTakeOutput", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "canTakeOutput", at = @At("HEAD"), cancellable = true)
|
||||||
protected void be_canTakeOutput(PlayerEntity player, boolean present, CallbackInfoReturnable<Boolean> info) {
|
protected void be_canTakeOutput(PlayerEntity player, boolean present, CallbackInfoReturnable<Boolean> info) {
|
||||||
if (be_currentRecipe != null) {
|
if (be_currentRecipe != null) {
|
||||||
ItemStack output = this.be_currentRecipe.craft(input, player);
|
info.setReturnValue(be_currentRecipe.checkHammerDurability(input, player));
|
||||||
if (!output.isEmpty()) {
|
|
||||||
info.setReturnValue(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +49,7 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple
|
||||||
protected void be_onTakeOutput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable<ItemStack> info) {
|
protected void be_onTakeOutput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable<ItemStack> info) {
|
||||||
if (be_currentRecipe != null) {
|
if (be_currentRecipe != null) {
|
||||||
this.input.getStack(0).decrement(1);
|
this.input.getStack(0).decrement(1);
|
||||||
|
stack = be_currentRecipe.craft(input, player);
|
||||||
this.onContentChanged(input);
|
this.onContentChanged(input);
|
||||||
this.context.run((world, blockPos) -> {
|
this.context.run((world, blockPos) -> {
|
||||||
BlockState anvilState = world.getBlockState(blockPos);
|
BlockState anvilState = world.getBlockState(blockPos);
|
||||||
|
@ -77,7 +75,9 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple
|
||||||
RecipeManager recipeManager = this.player.world.getRecipeManager();
|
RecipeManager recipeManager = this.player.world.getRecipeManager();
|
||||||
this.be_recipes = recipeManager.getAllMatches(AnvilRecipe.TYPE, input, player.world);
|
this.be_recipes = recipeManager.getAllMatches(AnvilRecipe.TYPE, input, player.world);
|
||||||
if (be_recipes.size() > 0) {
|
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();
|
this.be_updateResult();
|
||||||
info.cancel();
|
info.cancel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ import ru.betterend.registry.EndTags;
|
||||||
import ru.betterend.util.ItemUtil;
|
import ru.betterend.util.ItemUtil;
|
||||||
import ru.betterend.util.RecipeHelper;
|
import ru.betterend.util.RecipeHelper;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
||||||
|
|
||||||
public final static String GROUP = "smithing";
|
public final static String GROUP = "smithing";
|
||||||
|
@ -71,15 +73,21 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
||||||
|
|
||||||
public ItemStack craft(Inventory craftingInventory, PlayerEntity player) {
|
public ItemStack craft(Inventory craftingInventory, PlayerEntity player) {
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
|
if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY;
|
||||||
ItemStack hammer = craftingInventory.getStack(1);
|
ItemStack hammer = craftingInventory.getStack(1);
|
||||||
int damage = hammer.getDamage() + this.damage;
|
|
||||||
if (damage >= hammer.getMaxDamage()) return ItemStack.EMPTY;
|
|
||||||
hammer.damage(this.damage, player, entity -> {
|
hammer.damage(this.damage, player, entity -> {
|
||||||
entity.sendEquipmentBreakStatus(null);
|
entity.sendEquipmentBreakStatus(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this.craft(craftingInventory);
|
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) {
|
public boolean matches(Inventory craftingInventory) {
|
||||||
ItemStack hammer = craftingInventory.getStack(1);
|
ItemStack hammer = craftingInventory.getStack(1);
|
||||||
|
@ -125,7 +133,20 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
||||||
public boolean isIgnoredInRecipeBook() {
|
public boolean isIgnoredInRecipeBook() {
|
||||||
return true;
|
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 {
|
public static class Builder {
|
||||||
private final static Builder INSTANCE = new 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.level);
|
||||||
packetBuffer.writeVarInt(recipe.damage);
|
packetBuffer.writeVarInt(recipe.damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue