mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 21:35:10 +00:00
New Anvil Recipe System
This commit is contained in:
1 parent
9cda5503ed
commit
48dd7bedea
15 files changed
+592
-221
No files matched your search
@@ -2,21 +2,25 @@ package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IAnvilRecipe;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.handler.data.IAnvilRecipe;
|
||||
import noppes.npcs.controllers.data.Availability;
|
||||
|
||||
public class RecipeAnvil implements IAnvilRecipe {
|
||||
public int id = -1;
|
||||
public String name = "";
|
||||
public Availability availability = new Availability();
|
||||
public boolean ignoreNBT = false;
|
||||
|
||||
public boolean ignoreRepairItemNBT = false;
|
||||
public boolean ignoreRepairMaterialNBT = false;
|
||||
public boolean ignoreRepairMaterialDamage = false;
|
||||
|
||||
public ItemStack itemToRepair;
|
||||
public ItemStack repairMaterial;
|
||||
|
||||
private int xpCost;
|
||||
private float repairPercentage;
|
||||
public int xpCost;
|
||||
public float repairPercentage;
|
||||
|
||||
private boolean isAnvil = true;
|
||||
|
||||
@@ -39,6 +43,9 @@ public class RecipeAnvil implements IAnvilRecipe {
|
||||
recipe.repairPercentage = compound.getFloat("RepairPercentage");
|
||||
recipe.itemToRepair = NoppesUtilServer.readItem(compound.getCompoundTag("ItemToRepair"));
|
||||
recipe.repairMaterial = NoppesUtilServer.readItem(compound.getCompoundTag("RepairMaterial"));
|
||||
recipe.ignoreRepairMaterialNBT = compound.getBoolean("IgnoreRepairMatNBT");
|
||||
recipe.ignoreRepairItemNBT = compound.getBoolean("IgnoreRepairItemNBT");
|
||||
recipe.ignoreRepairMaterialDamage = compound.getBoolean("IgnoreRepairMatDamage");
|
||||
recipe.isAnvil = true;
|
||||
return recipe;
|
||||
}
|
||||
@@ -50,12 +57,20 @@ public class RecipeAnvil implements IAnvilRecipe {
|
||||
compound.setTag("Availability", availability.writeToNBT(new NBTTagCompound()));
|
||||
compound.setInteger("XPCost", xpCost);
|
||||
compound.setFloat("RepairPercentage", repairPercentage);
|
||||
compound.setTag("ItemToRepair", NoppesUtilServer.writeItem(itemToRepair, new NBTTagCompound()));
|
||||
compound.setTag("RepairMaterial", NoppesUtilServer.writeItem(repairMaterial, new NBTTagCompound()));
|
||||
if(itemToRepair != null){
|
||||
compound.setTag("ItemToRepair", NoppesUtilServer.writeItem(itemToRepair, new NBTTagCompound()));
|
||||
}
|
||||
if(repairMaterial != null){
|
||||
compound.setTag("RepairMaterial", NoppesUtilServer.writeItem(repairMaterial, new NBTTagCompound()));
|
||||
}
|
||||
compound.setBoolean("IgnoreRepairMatNBT", ignoreRepairMaterialNBT);
|
||||
compound.setBoolean("IgnoreRepairItemNBT", ignoreRepairItemNBT);
|
||||
compound.setBoolean("IgnoreRepairMatDamage", ignoreRepairMaterialDamage);
|
||||
compound.setBoolean("IsAnvil", true);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getXpCost() {
|
||||
return xpCost;
|
||||
}
|
||||
@@ -65,24 +80,18 @@ public class RecipeAnvil implements IAnvilRecipe {
|
||||
return repairPercentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that both input ItemStacks are non-null and match the recipe’s defined items.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(ItemStack inputItem, ItemStack inputRepairMaterial) {
|
||||
if (inputItem == null || inputRepairMaterial == null) return false;
|
||||
if (!NoppesUtilPlayer.compareItems(this.itemToRepair, inputItem, true, false)) {
|
||||
if (!NoppesUtilPlayer.compareItems(this.itemToRepair, inputItem, true, this.ignoreRepairItemNBT)) {
|
||||
return false;
|
||||
}
|
||||
if (!NoppesUtilPlayer.compareItems(this.repairMaterial, inputRepairMaterial, false, false)) {
|
||||
if (!NoppesUtilPlayer.compareItems(this.repairMaterial, inputRepairMaterial, this.ignoreRepairMaterialDamage, this.ignoreRepairMaterialNBT)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a repaired copy of the input item by reducing its damage.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getResult(ItemStack inputItem) {
|
||||
if (inputItem == null)
|
||||
@@ -108,4 +117,35 @@ public class RecipeAnvil implements IAnvilRecipe {
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public static RecipeAnvil saveRecipe(RecipeAnvil recipe, ItemStack output, ItemStack repairMaterial) {
|
||||
if (output != null) {
|
||||
recipe.itemToRepair = output.copy();
|
||||
if (recipe.itemToRepair.isItemStackDamageable()) {
|
||||
recipe.itemToRepair.setItemDamage(0);
|
||||
}
|
||||
} else {
|
||||
recipe.itemToRepair = null;
|
||||
}
|
||||
recipe.repairMaterial = (repairMaterial == null ? null : repairMaterial.copy());
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return itemToRepair != null && repairMaterial != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a deep copy of this RecipeAnvil.
|
||||
*/
|
||||
public void copy(RecipeAnvil recipe) {
|
||||
this.id = recipe.id;
|
||||
this.name = recipe.name;
|
||||
this.availability = recipe.availability;
|
||||
this.ignoreRepairMaterialDamage = recipe.ignoreRepairMaterialDamage;
|
||||
this.ignoreRepairItemNBT = recipe.ignoreRepairItemNBT;
|
||||
this.ignoreRepairMaterialNBT = recipe.ignoreRepairMaterialNBT;
|
||||
this.repairPercentage = recipe.repairPercentage;;
|
||||
this.xpCost = recipe.xpCost;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user