Added Capability.cast, to allow avoiding unchecked casts in ICapabilityProvider.getCapability
This commit is contained in:
parent
a4d5760539
commit
08663587d4
13 changed files with 33 additions and 20 deletions
|
@ -285,7 +285,7 @@
|
|||
}
|
||||
|
||||
this.func_184602_cy();
|
||||
@@ -2626,4 +2707,27 @@
|
||||
@@ -2626,4 +2707,28 @@
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -295,6 +295,7 @@
|
|||
+ private final net.minecraftforge.items.IItemHandlerModifiable armorHandler = new net.minecraftforge.items.ItemStackHandler(field_184631_bt);
|
||||
+ private final net.minecraftforge.items.IItemHandler joinedHandler = new net.minecraftforge.items.wrapper.CombinedInvWrapper(armorHandler, handHandler);
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
if (!this.field_70170_p.field_72995_K)
|
||||
{
|
||||
p_184230_1_.func_71007_a(this);
|
||||
@@ -279,6 +280,24 @@
|
||||
@@ -279,6 +280,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ public net.minecraftforge.items.IItemHandler itemHandler = new net.minecraftforge.items.wrapper.InvWrapper(this);
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
}
|
||||
|
||||
this.field_70138_W = 1.0F;
|
||||
@@ -1793,4 +1795,20 @@
|
||||
@@ -1793,4 +1795,21 @@
|
||||
this.field_188477_b = p_i46589_2_;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
|||
+ // FORGE
|
||||
+ private net.minecraftforge.items.IItemHandler itemHandler = null; // Initialized by initHorseChest above.
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -401,7 +401,7 @@
|
|||
|
||||
if (this.func_70608_bn())
|
||||
{
|
||||
@@ -2340,6 +2447,160 @@
|
||||
@@ -2340,6 +2447,161 @@
|
||||
return (float)this.func_110148_a(SharedMonsterAttributes.field_188792_h).func_111126_e();
|
||||
}
|
||||
|
||||
|
@ -539,6 +539,7 @@
|
|||
+ new net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper(field_71071_by));
|
||||
+ private final net.minecraftforge.items.IItemHandler playerJoinedHandler = new net.minecraftforge.items.wrapper.PlayerInvWrapper(field_71071_by);
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -63,13 +63,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -362,6 +361,20 @@
|
||||
@@ -362,6 +361,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ net.minecraftforge.items.IItemHandler handlerInput = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.UP);
|
||||
+ net.minecraftforge.items.IItemHandler handlerOutput = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.DOWN);
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@@ -457,6 +458,26 @@
|
||||
@@ -457,6 +458,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ public net.minecraftforge.items.VanillaDoubleChestItemHandler doubleChestHandler;
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -432,4 +443,21 @@
|
||||
@@ -432,4 +443,22 @@
|
||||
this.field_145957_n[i] = null;
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,7 @@
|
|||
+ net.minecraftforge.items.IItemHandler handlerBottom = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.DOWN);
|
||||
+ net.minecraftforge.items.IItemHandler handlerSide = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.WEST);
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityLockable.java
|
||||
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityLockable.java
|
||||
@@ -47,4 +47,25 @@
|
||||
@@ -47,4 +47,26 @@
|
||||
{
|
||||
return (ITextComponent)(this.func_145818_k_() ? new TextComponentString(this.func_70005_c_()) : new TextComponentTranslation(this.func_70005_c_(), new Object[0]));
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
|||
+ return new net.minecraftforge.items.wrapper.InvWrapper(this);
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ @Override
|
||||
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
|
||||
+ {
|
||||
|
|
|
@ -92,6 +92,17 @@ public class Capability<T>
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this inside ICapabilityProvider.getCapability to avoid unchecked cast warnings.
|
||||
* Example: return SOME_CAPABILITY.cast(instance);
|
||||
* Use with caution;
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R> R cast(T instance)
|
||||
{
|
||||
return (R)instance;
|
||||
}
|
||||
|
||||
// INTERNAL
|
||||
private final String name;
|
||||
private final IStorage<T> storage;
|
||||
|
|
|
@ -47,12 +47,11 @@ public class CapabilityAnimation
|
|||
return capability == ANIMATION_CAPABILITY;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
|
||||
{
|
||||
if(capability == ANIMATION_CAPABILITY)
|
||||
{
|
||||
return (T)asm;
|
||||
return ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -244,12 +244,11 @@ public class ModelAnimationDebug
|
|||
return capability == CapabilityAnimation.ANIMATION_CAPABILITY;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return (T)asm;
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -338,13 +337,12 @@ public class ModelAnimationDebug
|
|||
return super.hasCapability(capability, side);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return (T)asm;
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return super.getCapability(capability, side);
|
||||
}
|
||||
|
@ -396,13 +394,12 @@ public class ModelAnimationDebug
|
|||
return super.hasCapability(capability, side);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing side)
|
||||
{
|
||||
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
|
||||
{
|
||||
return (T)asm;
|
||||
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
|
||||
}
|
||||
return super.getCapability(capability, side);
|
||||
}
|
||||
|
|
|
@ -84,10 +84,9 @@ public class NoBedSleepingTest
|
|||
return capability == SLEEP_CAP;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
return capability == SLEEP_CAP ? (T)inst : null;
|
||||
return capability == SLEEP_CAP ? SLEEP_CAP.cast(inst) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -97,11 +97,10 @@ public class TestCapabilityMod
|
|||
{
|
||||
return TEST_CAP != null && capability == TEST_CAP;
|
||||
}
|
||||
@SuppressWarnings("unchecked") //There isnt anything sane we can do about this.
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
|
||||
{
|
||||
if (TEST_CAP != null && capability == TEST_CAP) return (T)this;
|
||||
if (TEST_CAP != null && capability == TEST_CAP) return TEST_CAP.cast(this);
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue