make annihilationPlane and FormationPlane to use the player who placed them to fire events

This commit is contained in:
xsun2001 2017-12-16 21:41:00 +08:00
parent 40db11fe54
commit eae0c766a3
2 changed files with 22 additions and 4 deletions

View File

@ -56,8 +56,10 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
@ -79,6 +81,7 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
private static final int MAX_CACHE_TIME = 60;
private final BaseActionSource mySrc = new MachineSource( this );
private EntityPlayer owner = null;
private boolean isAccepting = true;
private boolean breaking = false;
private YesNo permissionCache = YesNo.UNDECIDED;
@ -89,6 +92,13 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
super( is );
}
@Override
public void onPlacement( EntityPlayer player, ItemStack held, ForgeDirection side )
{
super.onPlacement( player, held, side );
this.owner = player;
}
@Override
public TickRateModulation call( final World world ) throws Exception
{
@ -500,13 +510,14 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab
final float hardness = block.getBlockHardness( w, x, y, z );
final boolean ignoreMaterials = material == Material.air || material == Material.lava || material == Material.water || material.isLiquid();
final boolean ignoreBlocks = block == Blocks.bedrock || block == Blocks.end_portal || block == Blocks.end_portal_frame || block == Blocks.command_block;
final EntityPlayer player = owner == null ? Platform.getPlayer( w ) : owner;
if( permissionCache == YesNo.UNDECIDED )
{
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent( x, y, z, w, block, w.getBlockMetadata( x, y, z ), Platform.getPlayer( w ) );
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent( x, y, z, w, block, w.getBlockMetadata( x, y, z ), player );
MinecraftForge.EVENT_BUS.post( event );
permissionCache = ( event.isCanceled() ) ? YesNo.NO : YesNo.YES;
}
return permissionCache == YesNo.YES && !ignoreMaterials && !ignoreBlocks && !w.isAirBlock( x, y, z ) && w.blockExists( x, y, z ) && w.canMineBlock( Platform.getPlayer( w ), x, y, z ) && hardness >= 0f;
return permissionCache == YesNo.YES && !ignoreMaterials && !ignoreBlocks && !w.isAirBlock( x, y, z ) && w.blockExists( x, y, z ) && w.canMineBlock( player , x, y, z ) && hardness >= 0f;
}
protected List<ItemStack> obtainBlockDrops( final WorldServer w, final int x, final int y, final int z )

View File

@ -74,10 +74,10 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
{
private final MEInventoryHandler myHandler = new MEInventoryHandler( this, StorageChannel.ITEMS );
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
private EntityPlayer owner = null;
private int priority = 0;
private boolean wasActive = false;
private boolean blocked = false;
public PartFormationPlane( final ItemStack is )
{
super( is );
@ -87,6 +87,13 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
this.updateHandler();
}
@Override
public void onPlacement( EntityPlayer player, ItemStack held, ForgeDirection side )
{
super.onPlacement( player, held, side );
this.owner = player;
}
private void updateHandler()
{
this.myHandler.setBaseAccess( AccessRestriction.WRITE );
@ -472,7 +479,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
{
player.setCurrentItemOrArmor( 0, is.copy() );
BlockSnapshot blockSnapshot = new BlockSnapshot( w, x, y, z, ( (ItemBlock) i ).field_150939_a, i.getMetadata( is.getItemDamage() ) );
BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent( blockSnapshot, w.getBlock( x, y, z ), player );
BlockEvent.PlaceEvent event = new BlockEvent.PlaceEvent( blockSnapshot, w.getBlock( x, y, z ), owner == null ? player : owner );
MinecraftForge.EVENT_BUS.post( event );
if( !event.isCanceled() )
{