Move reach distance to an attribute (#4331)

This commit is contained in:
Vincent Lee 2017-10-31 13:16:22 -05:00 committed by LexManos
parent 94c8534a83
commit 6d946fa088
7 changed files with 151 additions and 76 deletions

View file

@ -95,7 +95,17 @@
this.field_78776_a.func_147118_V().func_147682_a(new PositionedSoundRecord(soundtype.func_185846_f(), SoundCategory.NEUTRAL, (soundtype.func_185843_a() + 1.0F) / 8.0F, soundtype.func_185847_b() * 0.5F, p_180512_1_));
}
@@ -350,7 +361,7 @@
@@ -326,7 +337,8 @@
public float func_78757_d()
{
- return this.field_78779_k.func_77145_d() ? 5.0F : 4.5F;
+ float attrib = (float) field_78776_a.field_71439_g.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e();
+ return this.field_78779_k.func_77145_d() ? attrib : attrib - 0.5F;
}
public void func_78765_e()
@@ -350,7 +362,7 @@
if (!this.field_85183_f.func_190926_b() && !itemstack.func_190926_b())
{
@ -104,7 +114,7 @@
}
return p_178893_1_.equals(this.field_178895_c) && flag;
@@ -382,13 +393,34 @@
@@ -382,13 +394,34 @@
}
else
{
@ -141,7 +151,7 @@
}
if (!flag && itemstack.func_77973_b() instanceof ItemBlock)
@@ -404,7 +436,7 @@
@@ -404,7 +437,7 @@
this.field_78774_b.func_147297_a(new CPacketPlayerTryUseItemOnBlock(p_187099_3_, p_187099_4_, p_187099_6_, f, f1, f2));
@ -150,7 +160,7 @@
{
if (itemstack.func_190926_b())
{
@@ -430,14 +462,20 @@
@@ -430,14 +463,20 @@
{
int i = itemstack.func_77960_j();
int j = itemstack.func_190916_E();
@ -172,7 +182,7 @@
}
}
}
@@ -466,6 +504,8 @@
@@ -466,6 +505,8 @@
}
else
{
@ -181,7 +191,7 @@
int i = itemstack.func_190916_E();
ActionResult<ItemStack> actionresult = itemstack.func_77957_a(p_187101_2_, p_187101_1_, p_187101_3_);
ItemStack itemstack1 = actionresult.func_188398_b();
@@ -473,6 +513,10 @@
@@ -473,6 +514,10 @@
if (itemstack1 != itemstack || itemstack1.func_190916_E() != i)
{
p_187101_1_.func_184611_a(p_187101_3_, itemstack1);
@ -192,7 +202,7 @@
}
return actionresult.func_188397_a();
@@ -509,6 +553,9 @@
@@ -509,6 +554,9 @@
this.func_78750_j();
Vec3d vec3d = new Vec3d(p_187102_3_.field_72307_f.field_72450_a - p_187102_2_.field_70165_t, p_187102_3_.field_72307_f.field_72448_b - p_187102_2_.field_70163_u, p_187102_3_.field_72307_f.field_72449_c - p_187102_2_.field_70161_v);
this.field_78774_b.func_147297_a(new CPacketUseEntity(p_187102_2_, p_187102_4_, vec3d));

View file

@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/entity/player/EntityPlayer.java
+++ ../src-work/minecraft/net/minecraft/entity/player/EntityPlayer.java
@@ -96,6 +96,11 @@
@@ -96,6 +96,12 @@
@SuppressWarnings("incomplete-switch")
public abstract class EntityPlayer extends EntityLivingBase
{
@ -8,11 +8,20 @@
+ protected java.util.HashMap<Integer, BlockPos> spawnChunkMap = new java.util.HashMap<Integer, BlockPos>();
+ protected java.util.HashMap<Integer, Boolean> spawnForcedMap = new java.util.HashMap<Integer, Boolean>();
+ public float eyeHeight = this.getDefaultEyeHeight();
+ public static final net.minecraft.entity.ai.attributes.IAttribute REACH_DISTANCE = new net.minecraft.entity.ai.attributes.RangedAttribute(null, "generic.reachDistance", 5.0D, 0.0D, 1024.0D).func_111112_a(true);
+
private static final DataParameter<Float> field_184829_a = EntityDataManager.<Float>func_187226_a(EntityPlayer.class, DataSerializers.field_187193_c);
private static final DataParameter<Integer> field_184830_b = EntityDataManager.<Integer>func_187226_a(EntityPlayer.class, DataSerializers.field_187192_b);
protected static final DataParameter<Byte> field_184827_bp = EntityDataManager.<Byte>func_187226_a(EntityPlayer.class, DataSerializers.field_187191_a);
@@ -180,6 +185,7 @@
@@ -165,6 +171,7 @@
this.func_110148_a(SharedMonsterAttributes.field_111263_d).func_111128_a(0.10000000149011612D);
this.func_110140_aT().func_111150_b(SharedMonsterAttributes.field_188790_f);
this.func_110140_aT().func_111150_b(SharedMonsterAttributes.field_188792_h);
+ this.func_110140_aT().func_111150_b(REACH_DISTANCE);
}
protected void func_70088_a()
@@ -180,6 +187,7 @@
public void func_70071_h_()
{
@ -20,7 +29,7 @@
this.field_70145_X = this.func_175149_v();
if (this.func_175149_v())
@@ -367,6 +373,7 @@
@@ -367,6 +375,7 @@
this.func_70105_a(f, f1);
}
}
@ -28,7 +37,7 @@
}
public int func_82145_z()
@@ -454,11 +461,11 @@
@@ -454,11 +463,11 @@
this.field_71109_bG = 0.0F;
this.func_71015_k(this.field_70165_t - d0, this.field_70163_u - d1, this.field_70161_v - d2);
@ -42,7 +51,7 @@
}
}
}
@@ -609,11 +616,15 @@
@@ -609,11 +618,15 @@
public void func_70645_a(DamageSource p_70645_1_)
{
@ -58,7 +67,7 @@
if ("Notch".equals(this.func_70005_c_()))
{
this.func_146097_a(new ItemStack(Items.field_151034_e, 1), true, false);
@@ -625,6 +636,9 @@
@@ -625,6 +638,9 @@
this.field_71071_by.func_70436_m();
}
@ -68,7 +77,7 @@
if (p_70645_1_ != null)
{
this.field_70159_w = (double)(-MathHelper.func_76134_b((this.field_70739_aP + this.field_70177_z) * 0.017453292F) * 0.1F);
@@ -675,13 +689,24 @@
@@ -675,13 +691,24 @@
@Nullable
public EntityItem func_71040_bB(boolean p_71040_1_)
{
@ -95,7 +104,7 @@
}
@Nullable
@@ -741,14 +766,22 @@
@@ -741,14 +768,22 @@
public ItemStack func_184816_a(EntityItem p_184816_1_)
{
@ -119,7 +128,7 @@
if (f > 1.0F)
{
int i = EnchantmentHelper.func_185293_e(this);
@@ -798,12 +831,13 @@
@@ -798,12 +833,13 @@
f /= 5.0F;
}
@ -135,7 +144,7 @@
}
public static void func_189806_a(DataFixer p_189806_0_)
@@ -863,6 +897,17 @@
@@ -863,6 +899,17 @@
this.field_82248_d = p_70037_1_.func_74767_n("SpawnForced");
}
@ -153,7 +162,7 @@
this.field_71100_bB.func_75112_a(p_70037_1_);
this.field_71075_bZ.func_75095_b(p_70037_1_);
@@ -896,6 +941,7 @@
@@ -896,6 +943,7 @@
p_70014_1_.func_74768_a("XpTotal", this.field_71067_cb);
p_70014_1_.func_74768_a("XpSeed", this.field_175152_f);
p_70014_1_.func_74768_a("Score", this.func_71037_bA());
@ -161,7 +170,7 @@
if (this.field_71077_c != null)
{
@@ -905,6 +951,27 @@
@@ -905,6 +953,27 @@
p_70014_1_.func_74757_a("SpawnForced", this.field_82248_d);
}
@ -189,7 +198,7 @@
this.field_71100_bB.func_75117_b(p_70014_1_);
this.field_71075_bZ.func_75091_a(p_70014_1_);
p_70014_1_.func_74782_a("EnderItems", this.field_71078_a.func_70487_g());
@@ -922,6 +989,7 @@
@@ -922,6 +991,7 @@
public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_)
{
@ -197,7 +206,7 @@
if (this.func_180431_b(p_70097_1_))
{
return false;
@@ -974,7 +1042,7 @@
@@ -974,7 +1044,7 @@
{
super.func_190629_c(p_190629_1_);
@ -206,7 +215,7 @@
{
this.func_190777_m(true);
}
@@ -1002,14 +1070,16 @@
@@ -1002,14 +1072,16 @@
protected void func_184590_k(float p_184590_1_)
{
@ -224,7 +233,7 @@
if (enumhand == EnumHand.MAIN_HAND)
{
@@ -1045,7 +1115,10 @@
@@ -1045,7 +1117,10 @@
{
if (!this.func_180431_b(p_70665_1_))
{
@ -236,7 +245,7 @@
p_70665_2_ = this.func_70672_c(p_70665_1_, p_70665_2_);
float f = p_70665_2_;
p_70665_2_ = Math.max(p_70665_2_ - this.func_110139_bj(), 0.0F);
@@ -1115,6 +1188,8 @@
@@ -1115,6 +1190,8 @@
}
else
{
@ -245,7 +254,7 @@
ItemStack itemstack = this.func_184586_b(p_190775_2_);
ItemStack itemstack1 = itemstack.func_190926_b() ? ItemStack.field_190927_a : itemstack.func_77946_l();
@@ -1124,7 +1199,10 @@
@@ -1124,7 +1201,10 @@
{
itemstack.func_190920_e(itemstack1.func_190916_E());
}
@ -257,7 +266,7 @@
return EnumActionResult.SUCCESS;
}
else
@@ -1140,6 +1218,7 @@
@@ -1140,6 +1220,7 @@
{
if (itemstack.func_190926_b() && !this.field_71075_bZ.field_75098_d)
{
@ -265,7 +274,7 @@
this.func_184611_a(p_190775_2_, ItemStack.field_190927_a);
}
@@ -1165,6 +1244,7 @@
@@ -1165,6 +1246,7 @@
public void func_71059_n(Entity p_71059_1_)
{
@ -273,7 +282,7 @@
if (p_71059_1_.func_70075_an())
{
if (!p_71059_1_.func_85031_j(this))
@@ -1203,9 +1283,11 @@
@@ -1203,9 +1285,11 @@
boolean flag2 = flag && this.field_70143_R > 0.0F && !this.field_70122_E && !this.func_70617_f_() && !this.func_70090_H() && !this.func_70644_a(MobEffects.field_76440_q) && !this.func_184218_aH() && p_71059_1_ instanceof EntityLivingBase;
flag2 = flag2 && !this.func_70051_ag();
@ -286,7 +295,7 @@
}
f = f + f1;
@@ -1332,10 +1414,12 @@
@@ -1332,10 +1416,12 @@
if (!itemstack1.func_190926_b() && entity instanceof EntityLivingBase)
{
@ -299,7 +308,7 @@
this.func_184611_a(EnumHand.MAIN_HAND, ItemStack.field_190927_a);
}
}
@@ -1384,7 +1468,7 @@
@@ -1384,7 +1470,7 @@
if (this.field_70146_Z.nextFloat() < f)
{
@ -308,7 +317,7 @@
this.func_184602_cy();
this.field_70170_p.func_72960_a(this, (byte)30);
}
@@ -1442,6 +1526,8 @@
@@ -1442,6 +1528,8 @@
public EntityPlayer.SleepResult func_180469_a(BlockPos p_180469_1_)
{
@ -317,7 +326,7 @@
EnumFacing enumfacing = (EnumFacing)this.field_70170_p.func_180495_p(p_180469_1_).func_177229_b(BlockHorizontal.field_185512_D);
if (!this.field_70170_p.field_72995_K)
@@ -1484,8 +1570,9 @@
@@ -1484,8 +1572,9 @@
this.func_192030_dh();
this.func_70105_a(0.2F, 0.2F);
@ -329,7 +338,7 @@
float f1 = 0.5F + (float)enumfacing.func_82601_c() * 0.4F;
float f = 0.5F + (float)enumfacing.func_82599_e() * 0.4F;
this.func_175139_a(enumfacing);
@@ -1532,13 +1619,14 @@
@@ -1532,13 +1621,14 @@
public void func_70999_a(boolean p_70999_1_, boolean p_70999_2_, boolean p_70999_3_)
{
@ -347,7 +356,7 @@
if (blockpos == null)
{
@@ -1547,6 +1635,10 @@
@@ -1547,6 +1637,10 @@
this.func_70107_b((double)((float)blockpos.func_177958_n() + 0.5F), (double)((float)blockpos.func_177956_o() + 0.1F), (double)((float)blockpos.func_177952_p() + 0.5F));
}
@ -358,7 +367,7 @@
this.field_71083_bS = false;
@@ -1565,15 +1657,16 @@
@@ -1565,15 +1659,16 @@
private boolean func_175143_p()
{
@ -378,7 +387,7 @@
{
if (!p_180467_2_)
{
@@ -1588,16 +1681,17 @@
@@ -1588,16 +1683,17 @@
}
else
{
@ -399,7 +408,7 @@
switch (enumfacing)
{
@@ -1637,16 +1731,24 @@
@@ -1637,16 +1733,24 @@
public BlockPos func_180470_cg()
{
@ -426,7 +435,7 @@
if (p_180473_1_ != null)
{
this.field_71077_c = p_180473_1_;
@@ -1839,6 +1941,10 @@
@@ -1839,6 +1943,10 @@
super.func_180430_e(p_180430_1_, p_180430_2_);
}
@ -437,7 +446,7 @@
}
protected void func_71061_d_()
@@ -2176,7 +2282,10 @@
@@ -2176,7 +2284,10 @@
public ITextComponent func_145748_c_()
{
@ -449,7 +458,7 @@
itextcomponent.func_150256_b().func_150241_a(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + this.func_70005_c_() + " "));
itextcomponent.func_150256_b().func_150209_a(this.func_174823_aP());
itextcomponent.func_150256_b().func_179989_a(this.func_70005_c_());
@@ -2185,7 +2294,7 @@
@@ -2185,7 +2296,7 @@
public float func_70047_e()
{
@ -458,7 +467,7 @@
if (this.func_70608_bn())
{
@@ -2421,6 +2530,168 @@
@@ -2421,6 +2532,168 @@
return this.field_71075_bZ.field_75098_d && this.func_70003_b(2, "");
}

View file

@ -47,20 +47,18 @@
}
protected RayTraceResult func_77621_a(World p_77621_1_, EntityPlayer p_77621_2_, boolean p_77621_3_)
@@ -390,7 +393,11 @@
@@ -389,8 +392,8 @@
float f5 = MathHelper.func_76126_a(-f * 0.017453292F);
float f6 = f3 * f4;
float f7 = f2 * f4;
double d3 = 5.0D;
- double d3 = 5.0D;
- Vec3d vec3d1 = vec3d.func_72441_c((double)f6 * 5.0D, (double)f5 * 5.0D, (double)f7 * 5.0D);
+ if (p_77621_2_ instanceof net.minecraft.entity.player.EntityPlayerMP)
+ {
+ d3 = ((net.minecraft.entity.player.EntityPlayerMP)p_77621_2_).field_71134_c.getBlockReachDistance();
+ }
+ double d3 = p_77621_2_.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e();
+ Vec3d vec3d1 = vec3d.func_72441_c((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
return p_77621_1_.func_147447_a(vec3d, vec3d1, p_77621_3_, !p_77621_3_, false);
}
@@ -409,6 +416,9 @@
@@ -409,6 +412,9 @@
protected boolean func_194125_a(CreativeTabs p_194125_1_)
{

View file

@ -5,7 +5,7 @@
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
- if (d3 > 36.0D)
+ double dist = field_147369_b.field_71134_c.getBlockReachDistance() + 1;
+ double dist = field_147369_b.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e() + 1;
+ dist *= dist;
+
+ if (d3 > dist)
@ -17,7 +17,7 @@
if (blockpos.func_177956_o() < this.field_147367_d.func_71207_Z() - 1 || enumfacing != EnumFacing.UP && blockpos.func_177956_o() < this.field_147367_d.func_71207_Z())
{
- if (this.field_184362_y == null && this.field_147369_b.func_70092_e((double)blockpos.func_177958_n() + 0.5D, (double)blockpos.func_177956_o() + 0.5D, (double)blockpos.func_177952_p() + 0.5D) < 64.0D && !this.field_147367_d.func_175579_a(worldserver, blockpos, this.field_147369_b) && worldserver.func_175723_af().func_177746_a(blockpos))
+ double dist = field_147369_b.field_71134_c.getBlockReachDistance() + 3;
+ double dist = field_147369_b.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e() + 3;
+ dist *= dist;
+ if (this.field_184362_y == null && this.field_147369_b.func_70092_e((double)blockpos.func_177958_n() + 0.5D, (double)blockpos.func_177956_o() + 0.5D, (double)blockpos.func_177952_p() + 0.5D) < dist && !this.field_147367_d.func_175579_a(worldserver, blockpos, this.field_147369_b) && worldserver.func_175723_af().func_177746_a(blockpos))
{

View file

@ -1,15 +1,6 @@
--- ../src-base/minecraft/net/minecraft/server/management/PlayerInteractionManager.java
+++ ../src-work/minecraft/net/minecraft/server/management/PlayerInteractionManager.java
@@ -28,6 +28,8 @@
public class PlayerInteractionManager
{
+ /** Forge reach distance */
+ private double blockReachDistance = 5.0d;
public World field_73092_a;
public EntityPlayerMP field_73090_b;
private GameType field_73091_c = GameType.NOT_SET;
@@ -88,7 +90,7 @@
@@ -88,7 +88,7 @@
int i = this.field_73100_i - this.field_73093_n;
IBlockState iblockstate = this.field_73092_a.func_180495_p(this.field_180241_i);
@ -18,7 +9,7 @@
{
this.field_73097_j = false;
}
@@ -114,7 +116,7 @@
@@ -114,7 +114,7 @@
{
IBlockState iblockstate1 = this.field_73092_a.func_180495_p(this.field_180240_f);
@ -27,7 +18,7 @@
{
this.field_73092_a.func_175715_c(this.field_73090_b.func_145782_y(), this.field_180240_f, -1);
this.field_73094_o = -1;
@@ -123,7 +125,7 @@
@@ -123,7 +123,7 @@
else
{
int k = this.field_73100_i - this.field_73089_e;
@ -36,11 +27,12 @@
int l = (int)(f1 * 10.0F);
if (l != this.field_73094_o)
@@ -137,6 +139,15 @@
@@ -137,6 +137,16 @@
public void func_180784_a(BlockPos p_180784_1_, EnumFacing p_180784_2_)
{
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(field_73090_b, p_180784_1_, p_180784_2_, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(field_73090_b, getBlockReachDistance() + 1));
+ double reachDist = field_73090_b.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e();
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(field_73090_b, p_180784_1_, p_180784_2_, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(field_73090_b, reachDist + 1));
+ if (event.isCanceled())
+ {
+ // Restore block and te data
@ -52,7 +44,7 @@
if (this.func_73083_d())
{
if (!this.field_73092_a.func_175719_a((EntityPlayer)null, p_180784_1_, p_180784_2_))
@@ -172,17 +183,36 @@
@@ -172,17 +182,36 @@
}
}
@ -93,7 +85,7 @@
{
this.func_180237_b(p_180784_1_);
}
@@ -204,7 +234,7 @@
@@ -204,7 +233,7 @@
int i = this.field_73100_i - this.field_73089_e;
IBlockState iblockstate = this.field_73092_a.func_180495_p(p_180785_1_);
@ -102,7 +94,7 @@
{
float f = iblockstate.func_185903_a(this.field_73090_b, this.field_73090_b.field_70170_p, p_180785_1_) * (float)(i + 1);
@@ -233,13 +263,17 @@
@@ -233,13 +262,17 @@
private boolean func_180235_c(BlockPos p_180235_1_)
{
@ -124,7 +116,7 @@
}
return flag;
@@ -247,7 +281,8 @@
@@ -247,7 +280,8 @@
public boolean func_180237_b(BlockPos p_180237_1_)
{
@ -134,7 +126,7 @@
{
return false;
}
@@ -264,53 +299,41 @@
@@ -264,53 +298,41 @@
}
else
{
@ -200,7 +192,7 @@
return flag1;
}
}
@@ -328,8 +351,11 @@
@@ -328,8 +350,11 @@
}
else
{
@ -212,7 +204,7 @@
ActionResult<ItemStack> actionresult = p_187250_3_.func_77957_a(p_187250_2_, p_187250_1_, p_187250_4_);
ItemStack itemstack = actionresult.func_188398_b();
@@ -357,6 +383,7 @@
@@ -357,6 +382,7 @@
if (itemstack.func_190926_b())
{
@ -220,13 +212,14 @@
p_187250_1_.func_184611_a(p_187250_4_, ItemStack.field_190927_a);
}
@@ -402,13 +429,23 @@
@@ -402,13 +428,24 @@
}
else
{
- if (!p_187251_1_.func_70093_af() || p_187251_1_.func_184614_ca().func_190926_b() && p_187251_1_.func_184592_cb().func_190926_b())
+ double reachDist = p_187251_1_.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e();
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = net.minecraftforge.common.ForgeHooks
+ .onRightClickBlock(p_187251_1_, p_187251_4_, p_187251_5_, p_187251_6_, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(p_187251_1_, getBlockReachDistance() + 1));
+ .onRightClickBlock(p_187251_1_, p_187251_4_, p_187251_5_, p_187251_6_, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(p_187251_1_, reachDist + 1));
+ if (event.isCanceled()) return event.getCancellationResult();
+
+ EnumActionResult ret = p_187251_3_.onItemUseFirst(p_187251_1_, p_187251_2_, p_187251_5_, p_187251_4_, p_187251_6_, p_187251_7_, p_187251_8_, p_187251_9_);
@ -271,17 +264,20 @@
}
}
}
@@ -453,4 +498,13 @@
@@ -453,4 +498,16 @@
{
this.field_73092_a = p_73080_1_;
}
+
+ @Deprecated // use the attribute directly
+ public double getBlockReachDistance()
+ {
+ return blockReachDistance;
+ return field_73090_b.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111126_e();
+ }
+
+ @Deprecated // use an attribute modifier
+ public void setBlockReachDistance(double distance)
+ {
+ blockReachDistance = distance;
+ field_73090_b.func_110148_a(EntityPlayer.REACH_DISTANCE).func_111128_a(distance);
+ }
}

View file

@ -208,3 +208,4 @@ fml.button.open.mods.folder=Open Mods Folder
fml.button.open.file=Open %s
forge.container.enchant.limitedEnchantability=Limited Enchantability
attribute.name.generic.reachDistance=Reach Distance

View file

@ -0,0 +1,61 @@
package net.minecraftforge.debug;
import com.google.common.collect.Multimap;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = ReachDistanceAttributeTest.MODID, name = ReachDistanceAttributeTest.MODID, version = "1.0")
@Mod.EventBusSubscriber
public class ReachDistanceAttributeTest
{
public static final String MODID = "reachdistanceattributetest";
private static final Item PLATE = new ExtendedReachPlate().setRegistryName(MODID, "extended_reach_plate");
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> evt) {
evt.getRegistry().register(PLATE);
}
@Mod.EventBusSubscriber(Side.CLIENT)
public static class ClientEvents
{
@SubscribeEvent
public static void registerModels(ModelRegistryEvent evt)
{
ModelLoader.setCustomModelResourceLocation(PLATE, 0, new ModelResourceLocation("minecraft:diamond_chestplate", "inventory"));
}
}
public static class ExtendedReachPlate extends ItemArmor
{
private static final AttributeModifier BOOST = new AttributeModifier("extended reach plate boost", 3, 0);
public ExtendedReachPlate()
{
super(ArmorMaterial.DIAMOND, 3, EntityEquipmentSlot.CHEST);
setUnlocalizedName("extendedReachPlate");
}
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack)
{
Multimap<String, AttributeModifier> attribs = super.getAttributeModifiers(slot, stack);
if (slot == this.armorType)
{
attribs.put(EntityPlayer.REACH_DISTANCE.getName(), BOOST);
}
return attribs;
}
}
}