Add Farmland Trample Event (#4895)

This commit is contained in:
UnRealDinnerbone authored and LexManos committed 2018-06-27 11:31:38 -07:00
1 parent 539626727c
commit c001d2dbf6
4 files changed
+79 -6

No files matched your search

@@ -45,6 +45,7 @@ import com.google.gson.JsonParseException;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementManager;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFarmland;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
@@ -1450,4 +1451,17 @@ public class ForgeHooks
}
return modId;
}
public static boolean onFarmlandTrample(World world, BlockPos pos, IBlockState state, float fallDistance, Entity entity)
{
if (entity.canTrample(world, state.getBlock(), pos, fallDistance))
{
BlockEvent.FarmlandTrampleEvent event = new BlockEvent.FarmlandTrampleEvent(world, pos, state, fallDistance, entity);
MinecraftForge.EVENT_BUS.post(event);
return !event.isCanceled();
}
return false;
}
}
@@ -22,9 +22,12 @@ package net.minecraftforge.event.world;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
@@ -124,7 +127,7 @@ public class BlockEvent extends Event
this.player = player;
if (state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
{
this.exp = 0;
}
@@ -283,7 +286,7 @@ public class BlockEvent extends Event
super(world, pos, state);
}
}
/**
* Fired when a crop block grows. See subevents.
*
@@ -341,7 +344,34 @@ public class BlockEvent extends Event
}
/**
* Fired when an attempt is made to spawn a nether portal from
* Fired when when farmland gets trampled
* This event is {@link Cancelable}
*/
@Cancelable
public static class FarmlandTrampleEvent extends BlockEvent
{
private final Entity entity;
private final float fallDistance;
public FarmlandTrampleEvent(World world, BlockPos pos, IBlockState state, float fallDistance, Entity entity)
{
super(world, pos, state);
this.entity = entity;
this.fallDistance = fallDistance;
}
public Entity getEntity() {
return entity;
}
public float getFallDistance() {
return fallDistance;
}
}
/* Fired when an attempt is made to spawn a nether portal from
* {@link net.minecraft.block.BlockPortal#trySpawnPortal(World, BlockPos)}.
*
* If cancelled, the portal will not be spawned.