312 lines
12 KiB
Diff
312 lines
12 KiB
Diff
--- ../src-base/minecraft/net/minecraft/item/ItemStack.java
|
|
+++ ../src-work/minecraft/net/minecraft/item/ItemStack.java
|
|
@@ -47,7 +47,7 @@
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
-public final class ItemStack
|
|
+public final class ItemStack implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
|
|
{
|
|
public static final ItemStack field_190927_a = new ItemStack((Item)null);
|
|
public static final DecimalFormat field_111284_a = new DecimalFormat("#.##");
|
|
@@ -63,6 +63,10 @@
|
|
private Block field_179550_j;
|
|
private boolean field_179551_k;
|
|
|
|
+ private net.minecraftforge.fml.common.registry.RegistryDelegate<Item> delegate;
|
|
+ private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
|
|
+ private NBTTagCompound capNBT;
|
|
+
|
|
public ItemStack(Block p_i1876_1_)
|
|
{
|
|
this((Block)p_i1876_1_, 1);
|
|
@@ -88,8 +92,10 @@
|
|
this((Item)p_i1880_1_, p_i1880_2_, 0);
|
|
}
|
|
|
|
- public ItemStack(Item p_i1881_1_, int p_i1881_2_, int p_i1881_3_)
|
|
+ public ItemStack(Item p_i1881_1_, int p_i1881_2_, int p_i1881_3_){ this(p_i1881_1_, p_i1881_2_, p_i1881_3_, null); }
|
|
+ public ItemStack(Item p_i1881_1_, int p_i1881_2_, int p_i1881_3_, @Nullable NBTTagCompound capNBT)
|
|
{
|
|
+ this.capNBT = capNBT;
|
|
this.field_151002_e = p_i1881_1_;
|
|
this.field_77991_e = p_i1881_3_;
|
|
this.field_77994_a = p_i1881_2_;
|
|
@@ -100,6 +106,7 @@
|
|
}
|
|
|
|
this.func_190923_F();
|
|
+ this.forgeInit();
|
|
}
|
|
|
|
private void func_190923_F()
|
|
@@ -109,6 +116,7 @@
|
|
|
|
public ItemStack(NBTTagCompound p_i47263_1_)
|
|
{
|
|
+ this.capNBT = p_i47263_1_.func_74764_b("ForgeCaps") ? p_i47263_1_.func_74775_l("ForgeCaps") : null;
|
|
this.field_151002_e = Item.func_111206_d(p_i47263_1_.func_74779_i("id"));
|
|
this.field_77994_a = p_i47263_1_.func_74771_c("Count");
|
|
this.field_77991_e = Math.max(0, p_i47263_1_.func_74765_d("Damage"));
|
|
@@ -124,11 +132,12 @@
|
|
}
|
|
|
|
this.func_190923_F();
|
|
+ this.forgeInit();
|
|
}
|
|
|
|
public boolean func_190926_b()
|
|
{
|
|
- return this == field_190927_a ? true : (this.field_151002_e != null && this.field_151002_e != Item.func_150898_a(Blocks.field_150350_a) ? (this.field_77994_a <= 0 ? true : this.field_77991_e < -32768 || this.field_77991_e > 65535) : true);
|
|
+ return this == field_190927_a ? true : (getItemRaw() != null && getItemRaw() != Item.func_150898_a(Blocks.field_150350_a) ? (this.field_77994_a <= 0 ? true : this.field_77991_e < -32768 || this.field_77991_e > 65535) : true);
|
|
}
|
|
|
|
public static void func_189868_a(DataFixer p_189868_0_)
|
|
@@ -148,11 +157,12 @@
|
|
|
|
public Item func_77973_b()
|
|
{
|
|
- return this.field_190928_g ? Item.func_150898_a(Blocks.field_150350_a) : this.field_151002_e;
|
|
+ return this.field_190928_g || this.delegate == null ? Item.func_150898_a(Blocks.field_150350_a) : this.delegate.get();
|
|
}
|
|
|
|
public EnumActionResult func_179546_a(EntityPlayer p_179546_1_, World p_179546_2_, BlockPos p_179546_3_, EnumHand p_179546_4_, EnumFacing p_179546_5_, float p_179546_6_, float p_179546_7_, float p_179546_8_)
|
|
{
|
|
+ if (!p_179546_2_.field_72995_K) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, p_179546_1_, p_179546_2_, p_179546_3_, p_179546_5_, p_179546_6_, p_179546_7_, p_179546_8_, p_179546_4_);
|
|
EnumActionResult enumactionresult = this.func_77973_b().func_180614_a(p_179546_1_, p_179546_2_, p_179546_3_, p_179546_4_, p_179546_5_, p_179546_6_, p_179546_7_, p_179546_8_);
|
|
|
|
if (enumactionresult == EnumActionResult.SUCCESS)
|
|
@@ -163,6 +173,19 @@
|
|
return enumactionresult;
|
|
}
|
|
|
|
+ public EnumActionResult onItemUseFirst(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
|
|
+ {
|
|
+ // copy of onitemuse but for onitemusefirst
|
|
+ EnumActionResult enumactionresult = this.func_77973_b().onItemUseFirst(playerIn, worldIn, pos, side, hitX, hitY, hitZ, hand);
|
|
+
|
|
+ if (enumactionresult == EnumActionResult.SUCCESS)
|
|
+ {
|
|
+ playerIn.func_71029_a(StatList.func_188057_b(this.field_151002_e));
|
|
+ }
|
|
+
|
|
+ return enumactionresult;
|
|
+ }
|
|
+
|
|
public float func_150997_a(IBlockState p_150997_1_)
|
|
{
|
|
return this.func_77973_b().func_150893_a(this, p_150997_1_);
|
|
@@ -190,12 +213,18 @@
|
|
p_77955_1_.func_74782_a("tag", this.field_77990_d);
|
|
}
|
|
|
|
+ if (this.capabilities != null)
|
|
+ {
|
|
+ NBTTagCompound cnbt = this.capabilities.serializeNBT();
|
|
+ if (!cnbt.func_82582_d()) p_77955_1_.func_74782_a("ForgeCaps", cnbt);
|
|
+ }
|
|
+
|
|
return p_77955_1_;
|
|
}
|
|
|
|
public int func_77976_d()
|
|
{
|
|
- return this.func_77973_b().func_77639_j();
|
|
+ return this.func_77973_b().getItemStackLimit(this);
|
|
}
|
|
|
|
public boolean func_77985_e()
|
|
@@ -205,7 +234,7 @@
|
|
|
|
public boolean func_77984_f()
|
|
{
|
|
- return this.field_190928_g ? false : (this.field_151002_e.func_77612_l() <= 0 ? false : !this.func_77942_o() || !this.func_77978_p().func_74767_n("Unbreakable"));
|
|
+ return this.field_190928_g ? false : (this.field_151002_e.getMaxDamage(this) <= 0 ? false : !this.func_77942_o() || !this.func_77978_p().func_74767_n("Unbreakable"));
|
|
}
|
|
|
|
public boolean func_77981_g()
|
|
@@ -215,32 +244,27 @@
|
|
|
|
public boolean func_77951_h()
|
|
{
|
|
- return this.func_77984_f() && this.field_77991_e > 0;
|
|
+ return this.func_77984_f() && func_77973_b().isDamaged(this);
|
|
}
|
|
|
|
public int func_77952_i()
|
|
{
|
|
- return this.field_77991_e;
|
|
+ return func_77973_b().getDamage(this);
|
|
}
|
|
|
|
public int func_77960_j()
|
|
{
|
|
- return this.field_77991_e;
|
|
+ return func_77973_b().getMetadata(this);
|
|
}
|
|
|
|
public void func_77964_b(int p_77964_1_)
|
|
{
|
|
- this.field_77991_e = p_77964_1_;
|
|
-
|
|
- if (this.field_77991_e < 0)
|
|
- {
|
|
- this.field_77991_e = 0;
|
|
- }
|
|
+ func_77973_b().setDamage(this, p_77964_1_);
|
|
}
|
|
|
|
public int func_77958_k()
|
|
{
|
|
- return this.func_77973_b().func_77612_l();
|
|
+ return this.func_77973_b().getMaxDamage(this);
|
|
}
|
|
|
|
public boolean func_96631_a(int p_96631_1_, Random p_96631_2_)
|
|
@@ -272,8 +296,8 @@
|
|
}
|
|
}
|
|
|
|
- this.field_77991_e += p_96631_1_;
|
|
- return this.field_77991_e > this.func_77958_k();
|
|
+ func_77964_b(func_77952_i() + p_96631_1_); //Redirect through Item's callback if applicable.
|
|
+ return func_77952_i() > func_77958_k();
|
|
}
|
|
}
|
|
|
|
@@ -322,7 +346,7 @@
|
|
|
|
public boolean func_150998_b(IBlockState p_150998_1_)
|
|
{
|
|
- return this.func_77973_b().func_150897_b(p_150998_1_);
|
|
+ return this.func_77973_b().canHarvestBlock(p_150998_1_, this);
|
|
}
|
|
|
|
public boolean func_111282_a(EntityPlayer p_111282_1_, EntityLivingBase p_111282_2_, EnumHand p_111282_3_)
|
|
@@ -332,7 +356,7 @@
|
|
|
|
public ItemStack func_77946_l()
|
|
{
|
|
- ItemStack itemstack = new ItemStack(this.field_151002_e, this.field_77994_a, this.field_77991_e);
|
|
+ ItemStack itemstack = new ItemStack(this.field_151002_e, this.field_77994_a, this.field_77991_e, this.capabilities != null ? this.capabilities.serializeNBT() : null);
|
|
|
|
if (this.field_77990_d != null)
|
|
{
|
|
@@ -344,7 +368,7 @@
|
|
|
|
public static boolean func_77970_a(ItemStack p_77970_0_, ItemStack p_77970_1_)
|
|
{
|
|
- return p_77970_0_.func_190926_b() && p_77970_1_.func_190926_b() ? true : (!p_77970_0_.func_190926_b() && !p_77970_1_.func_190926_b() ? (p_77970_0_.field_77990_d == null && p_77970_1_.field_77990_d != null ? false : p_77970_0_.field_77990_d == null || p_77970_0_.field_77990_d.equals(p_77970_1_.field_77990_d)) : false);
|
|
+ return p_77970_0_.func_190926_b() && p_77970_1_.func_190926_b() ? true : (!p_77970_0_.func_190926_b() && !p_77970_1_.func_190926_b() ? (p_77970_0_.field_77990_d == null && p_77970_1_.field_77990_d != null ? false : (p_77970_0_.field_77990_d == null || p_77970_0_.field_77990_d.equals(p_77970_1_.field_77990_d)) && p_77970_0_.areCapsCompatible(p_77970_1_)) : false);
|
|
}
|
|
|
|
public static boolean func_77989_b(ItemStack p_77989_0_, ItemStack p_77989_1_)
|
|
@@ -354,7 +378,7 @@
|
|
|
|
private boolean func_77959_d(ItemStack p_77959_1_)
|
|
{
|
|
- return this.field_77994_a != p_77959_1_.field_77994_a ? false : (this.func_77973_b() != p_77959_1_.func_77973_b() ? false : (this.field_77991_e != p_77959_1_.field_77991_e ? false : (this.field_77990_d == null && p_77959_1_.field_77990_d != null ? false : this.field_77990_d == null || this.field_77990_d.equals(p_77959_1_.field_77990_d))));
|
|
+ return this.field_77994_a != p_77959_1_.field_77994_a ? false : (this.func_77973_b() != p_77959_1_.func_77973_b() ? false : (this.field_77991_e != p_77959_1_.field_77991_e ? false : (this.field_77990_d == null && p_77959_1_.field_77990_d != null ? false : (this.field_77990_d == null || this.field_77990_d.equals(p_77959_1_.field_77990_d)) && this.areCapsCompatible(p_77959_1_))));
|
|
}
|
|
|
|
public static boolean func_179545_c(ItemStack p_179545_0_, ItemStack p_179545_1_)
|
|
@@ -758,6 +782,7 @@
|
|
}
|
|
}
|
|
|
|
+ net.minecraftforge.event.ForgeEventFactory.onItemTooltip(this, p_82840_1_, list, p_82840_2_);
|
|
return list;
|
|
}
|
|
|
|
@@ -869,7 +894,7 @@
|
|
}
|
|
else
|
|
{
|
|
- multimap = this.func_77973_b().func_111205_h(p_111283_1_);
|
|
+ multimap = this.func_77973_b().getAttributeModifiers(p_111283_1_, this);
|
|
}
|
|
|
|
return multimap;
|
|
@@ -982,6 +1007,53 @@
|
|
}
|
|
}
|
|
|
|
+ @Override
|
|
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
|
|
+ {
|
|
+ return this.field_190928_g || this.capabilities == null ? false : this.capabilities.hasCapability(capability, facing);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ @Nullable
|
|
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
|
|
+ {
|
|
+ return this.field_190928_g || this.capabilities == null ? null : this.capabilities.getCapability(capability, facing);
|
|
+ }
|
|
+
|
|
+ public void deserializeNBT(NBTTagCompound nbt)
|
|
+ {
|
|
+ // TODO do this better while respecting new rules
|
|
+ final ItemStack itemStack = new ItemStack(nbt);
|
|
+ this.field_77990_d = itemStack.field_77990_d;
|
|
+ this.capNBT = itemStack.capNBT;
|
|
+ }
|
|
+
|
|
+ public NBTTagCompound serializeNBT()
|
|
+ {
|
|
+ NBTTagCompound ret = new NBTTagCompound();
|
|
+ this.func_77955_b(ret);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ public boolean areCapsCompatible(ItemStack other)
|
|
+ {
|
|
+ if (this.capabilities == null)
|
|
+ {
|
|
+ if (other.capabilities == null)
|
|
+ {
|
|
+ return true;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ return other.capabilities.areCompatible(null);
|
|
+ }
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ return this.capabilities.areCompatible(other.capabilities);
|
|
+ }
|
|
+ }
|
|
+
|
|
@SideOnly(Side.CLIENT)
|
|
public int func_190921_D()
|
|
{
|
|
@@ -1013,4 +1085,28 @@
|
|
{
|
|
this.func_190917_f(-p_190918_1_);
|
|
}
|
|
+
|
|
+ /**
|
|
+ * Set up forge's ItemStack additions.
|
|
+ */
|
|
+ private void forgeInit()
|
|
+ {
|
|
+ Item item = getItemRaw();
|
|
+ if (item != null)
|
|
+ {
|
|
+ this.delegate = item.delegate;
|
|
+ net.minecraftforge.common.capabilities.ICapabilityProvider provider = item.initCapabilities(this, this.capNBT);
|
|
+ this.capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(item, this, provider);
|
|
+ if (this.capNBT != null && this.capabilities != null) this.capabilities.deserializeNBT(this.capNBT);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Internal call to get the actual item, not the delegate.
|
|
+ * In all other methods, FML replaces calls to this.item with the item delegate.
|
|
+ */
|
|
+ private Item getItemRaw()
|
|
+ {
|
|
+ return this.field_151002_e;
|
|
+ }
|
|
}
|