Filter all vanilla blocks that we missed through Forge's getDrops and BlockDrops events. As well as implemented IShearable for DoublePlants and DeadBushes. Mojang really should generic out some of this stuff instead of repeating logic all over the place!

This commit is contained in:
Lex Manos 2014-06-02 14:10:49 -07:00
parent f2a33ea9f6
commit fa3feda0d5
9 changed files with 365 additions and 10 deletions

View file

@ -139,7 +139,19 @@
}
}
}
@@ -827,7 +851,7 @@
@@ -643,6 +667,11 @@
{
if (!p_149642_1_.field_72995_K && p_149642_1_.func_82736_K().func_82766_b("doTileDrops"))
{
+ if (captureDrops.get())
+ {
+ capturedDrops.get().add(p_149642_5_);
+ return;
+ }
float f = 0.7F;
double d0 = (double)(p_149642_1_.field_73012_v.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
double d1 = (double)(p_149642_1_.field_73012_v.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
@@ -827,7 +856,7 @@
public boolean func_149742_c(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
{
@ -148,7 +160,7 @@
}
public boolean func_149727_a(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
@@ -920,25 +944,35 @@
@@ -920,25 +949,35 @@
p_149636_2_.func_71064_a(StatList.field_75934_C[func_149682_b(this)], 1);
p_149636_2_.func_71020_j(0.025F);
@ -187,12 +199,13 @@
}
protected ItemStack func_149644_j(int p_149644_1_)
@@ -1114,6 +1148,1065 @@
@@ -1114,6 +1153,1091 @@
return null;
}
+ /* ======================================== FORGE START =====================================*/
+ private ThreadLocal<EntityPlayer> harvesters = new ThreadLocal();
+ //For ForgeInternal use Only!
+ protected ThreadLocal<EntityPlayer> harvesters = new ThreadLocal();
+ private ThreadLocal<Integer> silk_check_meta = new ThreadLocal();
+ /**
+ * Get a light value for the block at the specified coordinates, normal ranges are between 0 and 15
@ -1248,6 +1261,31 @@
+ if (harvestTool[metadata] == null) return false;
+ return harvestTool[metadata].equals(type);
+ }
+
+
+ // For Inernal use only to capture droped items inside getDrops
+ protected ThreadLocal<Boolean> captureDrops = new ThreadLocal<Boolean>()
+ {
+ @Override protected Boolean initialValue() { return false; }
+ };
+ protected ThreadLocal<List<ItemStack>> capturedDrops = new ThreadLocal<List<ItemStack>>()
+ {
+ @Override protected List<ItemStack> initialValue() { return new ArrayList<ItemStack>(); }
+ };
+ protected List<ItemStack> captureDrops(boolean start)
+ {
+ if (start)
+ {
+ captureDrops.set(true);
+ capturedDrops.get().clear();
+ return null;
+ }
+ else
+ {
+ captureDrops.set(false);
+ return capturedDrops.get();
+ }
+ }
+ /* ========================================= FORGE END ======================================*/
+
public static class SoundType

View file

@ -0,0 +1,45 @@
--- ../src-base/minecraft/net/minecraft/block/BlockDeadBush.java
+++ ../src-work/minecraft/net/minecraft/block/BlockDeadBush.java
@@ -1,5 +1,7 @@
package net.minecraft.block;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
@@ -8,9 +10,11 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
+import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import net.minecraftforge.common.IShearable;
-public class BlockDeadBush extends BlockBush
+public class BlockDeadBush extends BlockBush implements IShearable
{
private static final String __OBFID = "CL_00000224";
@@ -33,14 +37,15 @@
public void func_149636_a(World p_149636_1_, EntityPlayer p_149636_2_, int p_149636_3_, int p_149636_4_, int p_149636_5_, int p_149636_6_)
{
- if (!p_149636_1_.field_72995_K && p_149636_2_.func_71045_bC() != null && p_149636_2_.func_71045_bC().func_77973_b() == Items.field_151097_aZ)
{
- p_149636_2_.func_71064_a(StatList.field_75934_C[Block.func_149682_b(this)], 1);
- this.func_149642_a(p_149636_1_, p_149636_3_, p_149636_4_, p_149636_5_, new ItemStack(Blocks.field_150330_I, 1, p_149636_6_));
- }
- else
- {
super.func_149636_a(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_);
}
}
+
+ @Override public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z) { return true; }
+ @Override
+ public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)
+ {
+ return new ArrayList<ItemStack>(Arrays.asList(new ItemStack(Blocks.field_150330_I, 1, world.func_72805_g(x, y, z))));
+ }
}

View file

@ -1,6 +1,25 @@
--- ../src-base/minecraft/net/minecraft/block/BlockDoublePlant.java
+++ ../src-work/minecraft/net/minecraft/block/BlockDoublePlant.java
@@ -81,6 +81,7 @@
@@ -2,6 +2,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.material.Material;
@@ -18,8 +19,9 @@
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import net.minecraftforge.common.IShearable;
-public class BlockDoublePlant extends BlockBush implements IGrowable
+public class BlockDoublePlant extends BlockBush implements IGrowable, IShearable
{
public static final String[] field_149892_a = new String[] {"sunflower", "syringa", "grass", "fern", "rose", "paeonia"};
@SideOnly(Side.CLIENT)
@@ -81,6 +83,7 @@
public boolean func_149718_j(World p_149718_1_, int p_149718_2_, int p_149718_3_, int p_149718_4_)
{
@ -8,3 +27,26 @@
int l = p_149718_1_.func_72805_g(p_149718_2_, p_149718_3_, p_149718_4_);
return func_149887_c(l) ? p_149718_1_.func_147439_a(p_149718_2_, p_149718_3_ - 1, p_149718_4_) == this : p_149718_1_.func_147439_a(p_149718_2_, p_149718_3_ + 1, p_149718_4_) == this && super.func_149718_j(p_149718_1_, p_149718_2_, p_149718_3_, p_149718_4_);
}
@@ -262,4 +265,22 @@
int l = this.func_149885_e(p_149853_1_, p_149853_3_, p_149853_4_, p_149853_5_);
this.func_149642_a(p_149853_1_, p_149853_3_, p_149853_4_, p_149853_5_, new ItemStack(this, 1, l));
}
+
+ @Override
+ public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)
+ {
+ int metadata = world.func_72805_g(x, y, z);
+ int type = func_149890_d(metadata);
+ return func_149887_c(metadata) && (type == 3 || type == 4);
+ }
+
+ @Override
+ public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)
+ {
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
+ int type = func_149890_d(world.func_72805_g(x, y, z));
+ if (type == 3 || type == 2)
+ ret.add(new ItemStack(Blocks.field_150329_H, 2, type == 3 ? 2 : 1));
+ return ret;
+ }
}

View file

@ -0,0 +1,38 @@
--- ../src-base/minecraft/net/minecraft/block/BlockFlowerPot.java
+++ ../src-work/minecraft/net/minecraft/block/BlockFlowerPot.java
@@ -2,6 +2,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import java.util.ArrayList;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
@@ -139,12 +140,6 @@
public void func_149690_a(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
super.func_149690_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, p_149690_7_);
- TileEntityFlowerPot tileentityflowerpot = this.func_149929_e(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_);
-
- if (tileentityflowerpot != null && tileentityflowerpot.func_145965_a() != null)
- {
- this.func_149642_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, new ItemStack(tileentityflowerpot.func_145965_a(), 1, tileentityflowerpot.func_145966_b()));
- }
}
public void func_149749_a(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
@@ -242,4 +237,14 @@
return new TileEntityFlowerPot(Item.func_150898_a((Block)object), b0);
}
+
+ @Override
+ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
+ {
+ ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune);
+ TileEntityFlowerPot te = this.func_149929_e(world, x, y, z);
+ if (te != null && te.func_145965_a() != null)
+ ret.add(new ItemStack(te.func_145965_a(), 1, te.func_145966_b()));
+ return ret;
+ }
}

View file

@ -1,11 +1,50 @@
--- ../src-base/minecraft/net/minecraft/block/BlockIce.java
+++ ../src-work/minecraft/net/minecraft/block/BlockIce.java
@@ -43,7 +43,7 @@
@@ -2,6 +2,7 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import java.util.ArrayList;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
@@ -13,6 +14,7 @@
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import net.minecraftforge.event.ForgeEventFactory;
public class BlockIce extends BlockBreakable
{
@@ -43,14 +45,16 @@
p_149636_2_.func_71064_a(StatList.field_75934_C[Block.func_149682_b(this)], 1);
p_149636_2_.func_71020_j(0.025F);
- if (this.func_149700_E() && EnchantmentHelper.func_77502_d(p_149636_2_))
+ if (this.canSilkHarvest(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_) && EnchantmentHelper.func_77502_d(p_149636_2_))
{
+ ArrayList<ItemStack> items = new ArrayList<ItemStack>();
ItemStack itemstack = this.func_149644_j(p_149636_6_);
- if (itemstack != null)
- {
- this.func_149642_a(p_149636_1_, p_149636_3_, p_149636_4_, p_149636_5_, itemstack);
- }
+ if (itemstack != null) items.add(itemstack);
+
+ ForgeEventFactory.fireBlockHarvesting(items, p_149636_1_, this, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_, 0, 1.0f, true, p_149636_2_);
+ for (ItemStack is : items)
+ this.func_149642_a(p_149636_1_, p_149636_3_, p_149636_4_, p_149636_5_, is);
}
else
{
@@ -61,7 +65,9 @@
}
int i1 = EnchantmentHelper.func_77517_e(p_149636_2_);
+ harvesters.set(p_149636_2_);
this.func_149697_b(p_149636_1_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_, i1);
+ harvesters.set(null);
Material material = p_149636_1_.func_147439_a(p_149636_3_, p_149636_4_ - 1, p_149636_5_).func_149688_o();
if (material.func_76230_c() || material.func_76224_d())

View file

@ -45,7 +45,49 @@
{
this.field_150128_a[(l1 + k1) * j1 + (i2 + k1) * b1 + j2 + k1] = -2;
}
@@ -281,13 +283,7 @@
@@ -236,40 +238,7 @@
public void func_149690_a(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
- if (!p_149690_1_.field_72995_K)
- {
- int j1 = this.func_150123_b(p_149690_5_);
-
- if (p_149690_7_ > 0)
- {
- j1 -= 2 << p_149690_7_;
-
- if (j1 < 10)
- {
- j1 = 10;
- }
- }
-
- if (p_149690_1_.field_73012_v.nextInt(j1) == 0)
- {
- Item item = this.func_149650_a(p_149690_5_, p_149690_1_.field_73012_v, p_149690_7_);
- this.func_149642_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, new ItemStack(item, 1, this.func_149692_a(p_149690_5_)));
- }
-
- j1 = 200;
-
- if (p_149690_7_ > 0)
- {
- j1 -= 10 << p_149690_7_;
-
- if (j1 < 40)
- {
- j1 = 40;
- }
- }
-
- this.func_150124_c(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, j1);
- }
+ super.func_149690_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, 1.0f, p_149690_7_);
}
protected void func_150124_c(World p_150124_1_, int p_150124_2_, int p_150124_3_, int p_150124_4_, int p_150124_5_, int p_150124_6_) {}
@@ -281,13 +250,7 @@
public void func_149636_a(World p_149636_1_, EntityPlayer p_149636_2_, int p_149636_3_, int p_149636_4_, int p_149636_5_, int p_149636_6_)
{
@ -59,7 +101,7 @@
super.func_149636_a(p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_);
}
}
@@ -318,4 +314,38 @@
@@ -318,4 +281,67 @@
}
public abstract String[] func_150125_e();
@ -96,5 +138,34 @@
+ public boolean isLeaves(IBlockAccess world, int x, int y, int z)
+ {
+ return true;
+ }
+
+
+ @Override
+ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
+ {
+ ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
+ int chance = this.func_150123_b(metadata);
+
+ if (fortune > 0)
+ {
+ chance -= 2 << fortune;
+ if (chance < 10) chance = 10;
+ }
+
+ if (world.field_73012_v.nextInt(chance) == 0)
+ ret.add(new ItemStack(this.func_149650_a(metadata, world.field_73012_v, fortune), 1, this.func_149692_a(metadata)));
+
+ chance = 200;
+ if (fortune > 0)
+ {
+ chance -= 10 << fortune;
+ if (chance < 40) chance = 40;
+ }
+
+ this.captureDrops(true);
+ this.func_150124_c(world, x, y, z, metadata, chance); // Dammet mojang
+ ret.addAll(this.captureDrops(false));
+ return ret;
+ }
}

View file

@ -25,8 +25,11 @@
}
public void func_149674_a(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_)
@@ -62,7 +64,9 @@
@@ -60,9 +62,12 @@
return 6;
}
+ @SuppressWarnings("unused")
public void func_149690_a(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
- if (!p_149690_1_.field_72995_K)
@ -36,7 +39,7 @@
{
int j1 = 1;
@@ -109,4 +113,23 @@
@@ -109,4 +114,23 @@
this.field_149883_a[i] = p_149651_1_.func_94245_a(this.func_149641_N() + "_stage_" + i);
}
}

View file

@ -0,0 +1,47 @@
--- ../src-base/minecraft/net/minecraft/block/BlockPistonMoving.java
+++ ../src-work/minecraft/net/minecraft/block/BlockPistonMoving.java
@@ -2,11 +2,13 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import java.util.ArrayList;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityPiston;
import net.minecraft.util.AxisAlignedBB;
@@ -90,15 +92,7 @@
public void func_149690_a(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
- if (!p_149690_1_.field_72995_K)
- {
- TileEntityPiston tileentitypiston = this.func_149963_e(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_);
-
- if (tileentitypiston != null)
- {
- tileentitypiston.func_145861_a().func_149697_b(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, tileentitypiston.func_145832_p(), 0);
- }
- }
+ super.func_149690_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, p_149690_7_);
}
public void func_149695_a(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
@@ -231,4 +225,13 @@
{
this.field_149761_L = p_149651_1_.func_94245_a("piston_top_normal");
}
+
+ @Override
+ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
+ {
+ TileEntityPiston te = this.func_149963_e(world, x, y, z);
+ if (te != null)
+ return te.func_145861_a().getDrops(world, x, y, z, te.func_145832_p(), 0);
+ return new ArrayList<ItemStack>();
+ }
}

View file

@ -0,0 +1,32 @@
--- ../src-base/minecraft/net/minecraft/block/BlockPotato.java
+++ ../src-work/minecraft/net/minecraft/block/BlockPotato.java
@@ -1,5 +1,6 @@
package net.minecraft.block;
+import java.util.ArrayList;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -46,14 +47,15 @@
public void func_149690_a(World p_149690_1_, int p_149690_2_, int p_149690_3_, int p_149690_4_, int p_149690_5_, float p_149690_6_, int p_149690_7_)
{
super.func_149690_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, p_149690_5_, p_149690_6_, p_149690_7_);
+ }
- if (!p_149690_1_.field_72995_K)
- {
- if (p_149690_5_ >= 7 && p_149690_1_.field_73012_v.nextInt(50) == 0)
- {
- this.func_149642_a(p_149690_1_, p_149690_2_, p_149690_3_, p_149690_4_, new ItemStack(Items.field_151170_bI));
- }
- }
+ @Override
+ public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
+ {
+ ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune);
+ if (metadata >= 7 && world.field_73012_v.nextInt(50) == 0)
+ ret.add(new ItemStack(Items.field_151170_bI));
+ return ret;
}
@SideOnly(Side.CLIENT)