Files

114 lines
4.7 KiB
Diff

--- ../src-base/minecraft/net/minecraft/block/BlockCrops.java
+++ ../src-work/minecraft/net/minecraft/block/BlockCrops.java
@@ -15,6 +15,7 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
public class BlockCrops extends BlockBush implements IGrowable
{
@@ -70,6 +71,7 @@
{
super.updateTick(worldIn, pos, state, rand);
+ if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
{
int i = this.getAge(state);
@@ -78,9 +80,17 @@
{
float f = getGrowthChance(this, worldIn, pos);
- if (rand.nextInt((int)(25.0F / f) + 1) == 0)
+ if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) ((100.0F / worldIn.spigotConfig.wheatModifier) * (25.0F / f)) + 1) == 0)) // Spigot
{
- worldIn.setBlockState(pos, this.withAge(i + 1), 2);
+ // CatServer start - modded block bypass bukkit event
+ IBlockState data = this.withAge(i + 1);
+ if (data.getBlock() == this) {
+ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(data));
+ } else {
+ worldIn.setBlockState(pos, data, 2);
+ }
+ // CatServer end
+ net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
}
}
}
@@ -96,7 +106,14 @@
i = j;
}
- worldIn.setBlockState(pos, this.withAge(i), 2);
+ // CatServer start - modded block bypass bukkit event
+ IBlockState data = this.withAge(i);
+ if (data.getBlock() == this) {
+ CraftEventFactory.handleBlockGrowEvent(worldIn, pos.getX(), pos.getY(), pos.getZ(), this, getMetaFromState(data));
+ } else {
+ worldIn.setBlockState(pos, data, 2);
+ }
+ // CatServer end
}
protected int getBonemealAgeIncrease(World worldIn)
@@ -116,11 +133,11 @@
float f1 = 0.0F;
IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j));
- if (iblockstate.getBlock() == Blocks.FARMLAND)
+ if (iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)blockIn))
{
f1 = 1.0F;
- if (((Integer)iblockstate.getValue(BlockFarmland.MOISTURE)).intValue() > 0)
+ if (iblockstate.getBlock().isFertile(worldIn, blockpos.add(i, 0, j)))
{
f1 = 3.0F;
}
@@ -161,7 +178,8 @@
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
- return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && this.canSustainBush(worldIn.getBlockState(pos.down()));
+ IBlockState soil = worldIn.getBlockState(pos.down());
+ return (worldIn.getLight(pos) >= 8 || worldIn.canSeeSky(pos)) && soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}
protected Item getSeed()
@@ -174,11 +192,32 @@
return Items.WHEAT;
}
+ @Override
+ public void getDrops(net.minecraft.util.NonNullList<ItemStack> drops, net.minecraft.world.IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
+ {
+ super.getDrops(drops, world, pos, state, 0);
+ int age = getAge(state);
+ Random rand = world instanceof World ? ((World)world).rand : new Random();
+
+ if (age >= getMaxAge())
+ {
+ int k = 3 + fortune;
+
+ for (int i = 0; i < 3 + fortune; ++i)
+ {
+ if (rand.nextInt(2 * getMaxAge()) <= age)
+ {
+ drops.add(new ItemStack(this.getSeed(), 1, 0));
+ }
+ }
+ }
+ }
+
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
- super.dropBlockAsItemWithChance(worldIn, pos, state, chance, 0);
+ super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
- if (!worldIn.isRemote)
+ if (false && !worldIn.isRemote) // Forge: NOP all this.
{
int i = this.getAge(state);