New LivingDestroyBlockEvent for controlling if some entities can destroy blocks (#3628)

This commit is contained in:
Silly511 2017-04-07 17:34:26 -05:00 committed by LexManos
parent f2425b7486
commit f0eb941abc
6 changed files with 83 additions and 3 deletions

View File

@ -0,0 +1,11 @@
--- ../src-base/minecraft/net/minecraft/entity/ai/EntityAIBreakDoor.java
+++ ../src-work/minecraft/net/minecraft/entity/ai/EntityAIBreakDoor.java
@@ -21,7 +21,7 @@
{
return false;
}
- else if (!this.field_75356_a.field_70170_p.func_82736_K().func_82766_b("mobGriefing"))
+ else if (!this.field_75356_a.field_70170_p.func_82736_K().func_82766_b("mobGriefing") || !this.field_75356_a.field_70170_p.func_180495_p(this.field_179507_b).func_177230_c().canEntityDestroy(this.field_75356_a.field_70170_p.func_180495_p(this.field_179507_b), this.field_75356_a.field_70170_p, this.field_179507_b, this.field_75356_a) || !net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this.field_75356_a, this.field_179507_b, this.field_75356_a.field_70170_p.func_180495_p(this.field_179507_b)))
{
return false;
}

View File

@ -12,7 +12,7 @@
flag = true;
}
- else if (block != Blocks.field_180401_cv && block != Blocks.field_150343_Z && block != Blocks.field_150377_bs && block != Blocks.field_150357_h && block != Blocks.field_150384_bq && block != Blocks.field_150378_br)
+ else if (block.canEntityDestroy(iblockstate, this.field_70170_p, blockpos, this))
+ else if (block.canEntityDestroy(iblockstate, this.field_70170_p, blockpos, this) && net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this, blockpos, iblockstate))
{
if (block != Blocks.field_150483_bI && block != Blocks.field_185776_dc && block != Blocks.field_185777_dd && block != Blocks.field_150411_aY && block != Blocks.field_185775_db)
{

View File

@ -5,7 +5,7 @@
Block block = iblockstate.func_177230_c();
- if (iblockstate.func_185904_a() != Material.field_151579_a && func_181033_a(block))
+ if (!block.isAir(iblockstate, this.field_70170_p, blockpos) && block.canEntityDestroy(iblockstate, field_70170_p, blockpos, this))
+ if (!block.isAir(iblockstate, this.field_70170_p, blockpos) && block.canEntityDestroy(iblockstate, field_70170_p, blockpos, this) && net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this, blockpos, iblockstate))
{
flag = this.field_70170_p.func_175655_b(blockpos, true) || flag;
}

View File

@ -5,7 +5,7 @@
Block block = p_180428_4_.func_177230_c();
- if (this.func_82342_d() && EntityWither.func_181033_a(block))
+ if (this.func_82342_d() && block.canEntityDestroy(p_180428_4_, p_180428_2_, p_180428_3_, this))
+ if (this.func_82342_d() && block.canEntityDestroy(p_180428_4_, p_180428_2_, p_180428_3_, this) && net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this.field_70235_a, p_180428_3_, p_180428_4_))
{
f = Math.min(0.8F, f);
}

View File

@ -78,6 +78,7 @@ import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.item.ItemExpireEvent;
import net.minecraftforge.event.entity.living.LivingDestroyBlockEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
import net.minecraftforge.event.entity.living.LivingHealEvent;
@ -659,4 +660,9 @@ public class ForgeEventFactory
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(e);
return e.getLevel();
}
public static boolean onEntityDestroyBlock(EntityLivingBase entity, BlockPos pos, IBlockState state)
{
return !MinecraftForge.EVENT_BUS.post(new LivingDestroyBlockEvent(entity, pos, state));
}
}

View File

@ -0,0 +1,63 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* Fired when the ender dragon or wither attempts to destroy a block and when ever a zombie attempts to break a door. Basically a event version of {@link Block#canEntityDestroy(IBlockState, IBlockAccess, BlockPos, Entity)}<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the block will not be destroyed.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
**/
@Cancelable
public class LivingDestroyBlockEvent extends LivingEvent
{
private final BlockPos pos;
private final IBlockState state;
public LivingDestroyBlockEvent(EntityLivingBase entity, BlockPos pos, IBlockState state)
{
super(entity);
this.pos = pos;
this.state = state;
}
public IBlockState getState()
{
return state;
}
public BlockPos getPos()
{
return pos;
}
}