mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
Add Farmland Trample Event (#4895)
This commit is contained in:
1 parent
539626727c
commit
c001d2dbf6
4 files changed
+79
-6
No files matched your search
@@ -1,15 +1,17 @@
|
||||
--- ../src-base/minecraft/net/minecraft/block/BlockFarmland.java
|
||||
+++ ../src-work/minecraft/net/minecraft/block/BlockFarmland.java
|
||||
@@ -72,7 +72,7 @@
|
||||
@@ -72,9 +72,10 @@
|
||||
|
||||
public void func_180658_a(World p_180658_1_, BlockPos p_180658_2_, Entity p_180658_3_, float p_180658_4_)
|
||||
{
|
||||
- if (!p_180658_1_.field_72995_K && p_180658_1_.field_73012_v.nextFloat() < p_180658_4_ - 0.5F && p_180658_3_ instanceof EntityLivingBase && (p_180658_3_ instanceof EntityPlayer || p_180658_1_.func_82736_K().func_82766_b("mobGriefing")) && p_180658_3_.field_70130_N * p_180658_3_.field_70130_N * p_180658_3_.field_70131_O > 0.512F)
|
||||
+ if (!p_180658_1_.field_72995_K && p_180658_3_.canTrample(p_180658_1_, this, p_180658_2_, p_180658_4_)) // Forge: Move logic to Entity#canTrample
|
||||
+ if (net.minecraftforge.common.ForgeHooks.onFarmlandTrample(p_180658_1_, p_180658_2_, Blocks.field_150346_d.func_176223_P(), p_180658_4_, p_180658_3_)) // Forge: Move logic to Entity#canTrample
|
||||
{
|
||||
func_190970_b(p_180658_1_, p_180658_2_);
|
||||
}
|
||||
@@ -95,7 +95,7 @@
|
||||
|
||||
super.func_180658_a(p_180658_1_, p_180658_2_, p_180658_3_, p_180658_4_);
|
||||
@@ -95,7 +96,7 @@
|
||||
private boolean func_176529_d(World p_176529_1_, BlockPos p_176529_2_)
|
||||
{
|
||||
Block block = p_176529_1_.func_180495_p(p_176529_2_.func_177984_a()).func_177230_c();
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(modid = FarmlandTrampleEventTest.MOD_ID, name = "Farmland Trample Event Test", version = "1.0", acceptableRemoteVersions = "*")
|
||||
@Mod.EventBusSubscriber
|
||||
public class FarmlandTrampleEventTest
|
||||
{
|
||||
static final String MOD_ID = "farmland_trample_test";
|
||||
static final boolean ENABLED = true;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onFarmlandTrampled(BlockEvent.FarmlandTrampleEvent event)
|
||||
{
|
||||
if (!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(event.getEntity().isSneaking())
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user