Files
2019-02-24 22:29:41 +08:00

155 lines
6.2 KiB
Diff

--- ../src-base/minecraft/net/minecraft/block/BlockLeaves.java
+++ ../src-work/minecraft/net/minecraft/block/BlockLeaves.java
@@ -16,8 +16,9 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+import org.bukkit.event.block.LeavesDecayEvent;
-public abstract class BlockLeaves extends Block
+public abstract class BlockLeaves extends Block implements net.minecraftforge.common.IShearable
{
public static final PropertyBool DECAYABLE = PropertyBool.create("decayable");
public static final PropertyBool CHECK_DECAY = PropertyBool.create("check_decay");
@@ -53,9 +54,9 @@
BlockPos blockpos = pos.add(j1, k1, l1);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
- if (iblockstate.getMaterial() == Material.LEAVES && !((Boolean)iblockstate.getValue(CHECK_DECAY)).booleanValue())
+ if (iblockstate.getBlock().isLeaves(iblockstate, worldIn, blockpos))
{
- worldIn.setBlockState(blockpos, iblockstate.withProperty(CHECK_DECAY, Boolean.valueOf(true)), 4);
+ iblockstate.getBlock().beginLeavesDecay(iblockstate, worldIn, blockpos);
}
}
}
@@ -83,7 +84,8 @@
this.surroundings = new int[32768];
}
- if (worldIn.isAreaLoaded(new BlockPos(k - 5, l - 5, i1 - 5), new BlockPos(k + 5, l + 5, i1 + 5)))
+ if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent decaying leaves from updating neighbors and loading unloaded chunks
+ if (worldIn.isAreaLoaded(pos, 6)) // Forge: extend range from 5 to 6 to account for neighbor checks in world.markAndNotifyBlock -> world.updateObservingBlocksAt
{
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
@@ -96,9 +98,9 @@
IBlockState iblockstate = worldIn.getBlockState(blockpos$mutableblockpos.setPos(k + i2, l + j2, i1 + k2));
Block block = iblockstate.getBlock();
- if (block != Blocks.LOG && block != Blocks.LOG2)
+ if (!block.canSustainLeaves(iblockstate, worldIn, blockpos$mutableblockpos.setPos(k + i2, l + j2, i1 + k2)))
{
- if (iblockstate.getMaterial() == Material.LEAVES)
+ if (block.isLeaves(iblockstate, worldIn, blockpos$mutableblockpos.setPos(k + i2, l + j2, i1 + k2)))
{
this.surroundings[(i2 + 16) * 1024 + (j2 + 16) * 32 + k2 + 16] = -2;
}
@@ -177,6 +179,12 @@
private void destroy(World worldIn, BlockPos pos)
{
+ LeavesDecayEvent event = new LeavesDecayEvent(worldIn.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+ worldIn.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled() || worldIn.getBlockState(pos).getBlock() != this) {
+ return;
+ }
this.dropBlockAsItem(worldIn, pos, worldIn.getBlockState(pos), 0);
worldIn.setBlockToAir(pos);
}
@@ -205,40 +213,7 @@
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
- if (!worldIn.isRemote)
- {
- int i = this.getSaplingDropChance(state);
-
- if (fortune > 0)
- {
- i -= 2 << fortune;
-
- if (i < 10)
- {
- i = 10;
- }
- }
-
- if (worldIn.rand.nextInt(i) == 0)
- {
- Item item = this.getItemDropped(state, worldIn.rand, fortune);
- spawnAsEntity(worldIn, pos, new ItemStack(item, 1, this.damageDropped(state)));
- }
-
- i = 200;
-
- if (fortune > 0)
- {
- i -= 10 << fortune;
-
- if (i < 40)
- {
- i = 40;
- }
- }
-
- this.dropApple(worldIn, pos, state, i);
- }
+ super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
}
protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance)
@@ -274,6 +249,51 @@
public abstract BlockPlanks.EnumType getWoodType(int meta);
+ @Override public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos){ return true; }
+ @Override public boolean isLeaves(IBlockState state, IBlockAccess world, BlockPos pos){ return true; }
+
+ @Override
+ public void beginLeavesDecay(IBlockState state, World world, BlockPos pos)
+ {
+ if (!(Boolean)state.getValue(CHECK_DECAY))
+ {
+ world.setBlockState(pos, state.withProperty(CHECK_DECAY, true), 4);
+ }
+ }
+
+ @Override
+ public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
+ {
+ Random rand = world instanceof World ? ((World)world).rand : new Random();
+ int chance = this.getSaplingDropChance(state);
+
+ if (fortune > 0)
+ {
+ chance -= 2 << fortune;
+ if (chance < 10) chance = 10;
+ }
+
+ if (rand.nextInt(chance) == 0)
+ {
+ ItemStack drop = new ItemStack(getItemDropped(state, rand, fortune), 1, damageDropped(state));
+ if (!drop.isEmpty())
+ drops.add(drop);
+ }
+
+ chance = 200;
+ if (fortune > 0)
+ {
+ chance -= 10 << fortune;
+ if (chance < 40) chance = 40;
+ }
+
+ this.captureDrops(true);
+ if (world instanceof World)
+ this.dropApple((World)world, pos, state, chance); // Dammet mojang
+ drops.addAll(this.captureDrops(false));
+ }
+
+
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{