Skip to content

Commit

Permalink
make annihilationPlane and FormationPlane to use the player who place…
Browse files Browse the repository at this point in the history
…d them to fire events
  • Loading branch information
xsun2001 committed Dec 16, 2017
1 parent 40db11f commit eae0c76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/main/java/appeng/parts/automation/PartAnnihilationPlane.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
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;
Expand All @@ -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;
Expand All @@ -89,6 +92,13 @@ public PartAnnihilationPlane( final ItemStack is )
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
{
Expand Down Expand Up @@ -500,13 +510,14 @@ private boolean canHandleBlock( final WorldServer w, final int x, final int y, f
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 )
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/appeng/parts/automation/PartFormationPlane.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -87,6 +87,13 @@ public PartFormationPlane( final ItemStack is )
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 );
Expand Down Expand Up @@ -472,7 +479,7 @@ public IAEItemStack injectItems( final IAEItemStack input, final Actionable type
{
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() )
{
Expand Down

0 comments on commit eae0c76

Please sign in to comment.