Properly fix IShearable implementation. Fixes shears taking damage twice, mooshroom particles, and blocks dropping incorrect loot.

This commit is contained in:
LexManos 2017-02-23 15:15:48 -08:00
parent 7c9b67b574
commit 403eda184a
9 changed files with 65 additions and 43 deletions

View File

@ -9,15 +9,6 @@
{
protected static final AxisAlignedBB field_185516_a = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
@@ -58,7 +58,7 @@
public void func_180657_a(World p_180657_1_, EntityPlayer p_180657_2_, BlockPos p_180657_3_, IBlockState p_180657_4_, @Nullable TileEntity p_180657_5_, ItemStack p_180657_6_)
{
- if (!p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ)
+ if (false && !p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ)
{
p_180657_2_.func_71029_a(StatList.func_188055_a(this));
func_180635_a(p_180657_1_, p_180657_3_, new ItemStack(Blocks.field_150330_I, 1, 0));
@@ -68,4 +68,11 @@
super.func_180657_a(p_180657_1_, p_180657_2_, p_180657_3_, p_180657_4_, p_180657_5_, p_180657_6_);
}

View File

@ -1,14 +1,5 @@
--- ../src-base/minecraft/net/minecraft/block/BlockNewLeaf.java
+++ ../src-work/minecraft/net/minecraft/block/BlockNewLeaf.java
@@ -99,7 +99,7 @@
public void func_180657_a(World p_180657_1_, EntityPlayer p_180657_2_, BlockPos p_180657_3_, IBlockState p_180657_4_, @Nullable TileEntity p_180657_5_, ItemStack p_180657_6_)
{
- if (!p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ)
+ if (false && !p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ)
{
p_180657_2_.func_71029_a(StatList.func_188055_a(this));
func_180635_a(p_180657_1_, p_180657_3_, new ItemStack(Item.func_150898_a(this), 1, ((BlockPlanks.EnumType)p_180657_4_.func_177229_b(field_176240_P)).func_176839_a() - 4));
@@ -109,4 +109,10 @@
super.func_180657_a(p_180657_1_, p_180657_2_, p_180657_3_, p_180657_4_, p_180657_5_, p_180657_6_);
}

View File

@ -27,15 +27,6 @@
}
public int func_149679_a(int p_149679_1_, Random p_149679_2_)
@@ -62,7 +62,7 @@
public void func_180657_a(World p_180657_1_, EntityPlayer p_180657_2_, BlockPos p_180657_3_, IBlockState p_180657_4_, @Nullable TileEntity p_180657_5_, ItemStack p_180657_6_)
{
- if (!p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ)
+ if (false && !p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ) // Forge: Noop Taken care of by IShearable
{
p_180657_2_.func_71029_a(StatList.func_188055_a(this));
func_180635_a(p_180657_1_, p_180657_3_, new ItemStack(Blocks.field_150329_H, 1, ((BlockTallGrass.EnumType)p_180657_4_.func_177229_b(field_176497_a)).func_177044_a()));
@@ -181,4 +181,21 @@
}
}

View File

@ -9,15 +9,6 @@
{
public static final PropertyBool field_176277_a = PropertyBool.func_177716_a("up");
public static final PropertyBool field_176273_b = PropertyBool.func_177716_a("north");
@@ -344,7 +344,7 @@
public void func_180657_a(World p_180657_1_, EntityPlayer p_180657_2_, BlockPos p_180657_3_, IBlockState p_180657_4_, @Nullable TileEntity p_180657_5_, ItemStack p_180657_6_)
{
- if (!p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ)
+ if (false && !p_180657_1_.field_72995_K && p_180657_6_.func_77973_b() == Items.field_151097_aZ) // Forge: Noop, Covered by IShearable
{
p_180657_2_.func_71029_a(StatList.func_188055_a(this));
func_180635_a(p_180657_1_, p_180657_3_, new ItemStack(Blocks.field_150395_bd, 1, 0));
@@ -459,4 +459,14 @@
return i;

View File

@ -0,0 +1,22 @@
--- ../src-base/minecraft/net/minecraft/block/BlockWeb.java
+++ ../src-work/minecraft/net/minecraft/block/BlockWeb.java
@@ -20,7 +20,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
-public class BlockWeb extends Block
+public class BlockWeb extends Block implements net.minecraftforge.common.IShearable
{
public BlockWeb()
{
@@ -77,4 +77,10 @@
super.func_180657_a(p_180657_1_, p_180657_2_, p_180657_3_, p_180657_4_, p_180657_5_, p_180657_6_);
}
}
+
+ @Override public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) { return true; }
+ @Override
+ public java.util.List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
+ return com.google.common.collect.Lists.newArrayList(new ItemStack(Item.func_150898_a(this)));
+ }
}

View File

@ -0,0 +1,33 @@
--- ../src-base/minecraft/net/minecraft/entity/monster/EntitySnowman.java
+++ ../src-work/minecraft/net/minecraft/entity/monster/EntitySnowman.java
@@ -31,7 +31,7 @@
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.LootTableList;
-public class EntitySnowman extends EntityGolem implements IRangedAttackMob
+public class EntitySnowman extends EntityGolem implements IRangedAttackMob, net.minecraftforge.common.IShearable
{
private static final DataParameter<Byte> field_184749_a = EntityDataManager.<Byte>func_187226_a(EntitySnowman.class, DataSerializers.field_187191_a);
@@ -152,7 +152,7 @@
{
ItemStack itemstack = p_184645_1_.func_184586_b(p_184645_2_);
- if (itemstack.func_77973_b() == Items.field_151097_aZ && this.func_184748_o() && !this.field_70170_p.field_72995_K)
+ if (false && itemstack.func_77973_b() == Items.field_151097_aZ && this.func_184748_o() && !this.field_70170_p.field_72995_K) //Forge: Moved to onSheared
{
this.func_184747_a(false);
itemstack.func_77972_a(1, p_184645_1_);
@@ -197,4 +197,12 @@
{
return SoundEvents.field_187801_fC;
}
+
+ @Override public boolean isShearable(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos) { return this.func_184748_o(); }
+ @Override
+ public java.util.List<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
+ {
+ this.func_184747_a(false);
+ return com.google.common.collect.Lists.newArrayList();
+ }
}

View File

@ -27,7 +27,7 @@
+ public java.util.List<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, net.minecraft.util.math.BlockPos pos, int fortune)
+ {
+ this.func_70106_y();
+ this.field_70170_p.func_175688_a(EnumParticleTypes.EXPLOSION_LARGE, this.field_70165_t, this.field_70163_u + (double)(this.field_70131_O / 2.0F), this.field_70161_v, 0.0D, 0.0D, 0.0D, new int[0]);
+ ((net.minecraft.world.WorldServer)this.field_70170_p).func_180505_a(EnumParticleTypes.EXPLOSION_LARGE, false, this.field_70165_t, this.field_70163_u + (double)(this.field_70131_O / 2.0F), this.field_70161_v, 1, 0.0D, 0.0D, 0.0D, 0.0D);
+
+ EntityCow entitycow = new EntityCow(this.field_70170_p);
+ entitycow.func_70012_b(this.field_70165_t, this.field_70163_u, this.field_70161_v, this.field_70177_z, this.field_70125_A);

View File

@ -1,15 +1,14 @@
--- ../src-base/minecraft/net/minecraft/item/ItemShears.java
+++ ../src-work/minecraft/net/minecraft/item/ItemShears.java
@@ -26,7 +26,7 @@
@@ -26,6 +26,7 @@
}
Block block = p_179218_3_.func_177230_c();
- return p_179218_3_.func_185904_a() != Material.field_151584_j && block != Blocks.field_150321_G && block != Blocks.field_150329_H && block != Blocks.field_150395_bd && block != Blocks.field_150473_bD && block != Blocks.field_150325_L ? super.func_179218_a(p_179218_1_, p_179218_2_, p_179218_3_, p_179218_4_, p_179218_5_) : true;
+ return p_179218_3_.func_185904_a() != Material.field_151584_j && block != Blocks.field_150321_G && block != Blocks.field_150329_H && block != Blocks.field_150395_bd && block != Blocks.field_150473_bD && block != Blocks.field_150325_L && !(p_179218_3_ instanceof net.minecraftforge.common.IShearable) ? super.func_179218_a(p_179218_1_, p_179218_2_, p_179218_3_, p_179218_4_, p_179218_5_) : true;
+ if (block instanceof net.minecraftforge.common.IShearable) return true;
return p_179218_3_.func_185904_a() != Material.field_151584_j && block != Blocks.field_150321_G && block != Blocks.field_150329_H && block != Blocks.field_150395_bd && block != Blocks.field_150473_bD && block != Blocks.field_150325_L ? super.func_179218_a(p_179218_1_, p_179218_2_, p_179218_3_, p_179218_4_, p_179218_5_) : true;
}
public boolean func_150897_b(IBlockState p_150897_1_)
@@ -40,4 +40,71 @@
@@ -40,4 +41,73 @@
Block block = p_150893_2_.func_177230_c();
return block != Blocks.field_150321_G && p_150893_2_.func_185904_a() != Material.field_151584_j ? (block == Blocks.field_150325_L ? 5.0F : super.func_150893_a(p_150893_1_, p_150893_2_)) : 15.0F;
}
@ -63,7 +62,7 @@
+ net.minecraft.enchantment.EnchantmentHelper.func_77506_a(net.minecraft.init.Enchantments.field_185308_t, itemstack));
+ java.util.Random rand = new java.util.Random();
+
+ for(ItemStack stack : drops)
+ for (ItemStack stack : drops)
+ {
+ float f = 0.7F;
+ double d = (double)(rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
@ -76,6 +75,8 @@
+
+ itemstack.func_77972_a(1, player);
+ player.func_71029_a(net.minecraft.stats.StatList.func_188055_a(block));
+ player.field_70170_p.func_180501_a(pos, Blocks.field_150350_a.func_176223_P(), 11); //TODO: Move to IShearable implementors in 1.12+
+ return true;
+ }
+ }
+ return false;

View File

@ -35,6 +35,8 @@ import javax.annotation.Nonnull;
* to support mod-shears as well.
*
*/
//TODO Change to World, not IBlockAccess and make Implementor responsible for removing itself from the world.
//Better mimics vanilla behavior and allows more control for the user.
public interface IShearable
{
/**