detect interaction with pipes (for gates, plugs and robot stations)

This commit is contained in:
AEnterprise 2014-09-17 18:13:00 +02:00
parent b01533e1d5
commit fb706ae1ab
4 changed files with 38 additions and 3 deletions

View file

@ -11,11 +11,14 @@ import cpw.mods.fml.common.eventhandler.Event;
public class BlockPlacedDownEvent extends Event {
public EntityPlayer player;
public Block block;
public int meta;
public int meta, x, y, z;
public BlockPlacedDownEvent(EntityPlayer player, Block block, int meta) {
public BlockPlacedDownEvent(EntityPlayer player, Block block, int meta, int x, int y, int z) {
this.player = player;
this.block = block;
this.meta = meta;
this.x = x;
this.y = y;
this.z = z;
}
}

View file

@ -0,0 +1,26 @@
package buildcraft.api.events;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
/**
* Copyright (c) 2014, AEnterprise
* http://buildcraftadditions.wordpress.com/
* Buildcraft Additions is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://buildcraftadditions.wordpress.com/wiki/licensing-stuff/
*/
@Cancelable
public class RobotPlacementEvent extends Event {
public EntityPlayer player;
public String robotProgram;
public RobotPlacementEvent(EntityPlayer player, String robotProgram) {
this.player = player;
this.robotProgram = robotProgram;
}
}

View file

@ -44,7 +44,7 @@ public abstract class BlockBuildCraft extends BlockContainer {
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
super.onBlockPlacedBy(world, x, y, z, entity, stack);
FMLCommonHandler.instance().bus().post(new BlockPlacedDownEvent((EntityPlayer) entity, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)));
FMLCommonHandler.instance().bus().post(new BlockPlacedDownEvent((EntityPlayer) entity, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z), x, y, z));
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileBuildCraft) {
((TileBuildCraft) tile).onBlockPlacedBy(entity, stack);

View file

@ -48,6 +48,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.api.events.PipePlacedEvent;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
@ -714,6 +715,11 @@ public class BlockGenericPipe extends BlockBuildCraft {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
super.onBlockActivated(world, x, y, z, player, side, xOffset, yOffset, zOffset);
BlockInteractionEvent event = new BlockInteractionEvent(player, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled()) {
return true;
}
world.notifyBlocksOfNeighborChange(x, y, z, BuildCraftTransport.genericPipeBlock);