add event to detect and prevent the placement of robots

This commit is contained in:
AEnterprise 2014-09-16 17:39:18 +02:00
parent df1cf3c6d1
commit 0c11181e85
2 changed files with 33 additions and 0 deletions

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

@ -30,6 +30,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
@ -49,6 +50,7 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.events.PipePlacedEvent;
import buildcraft.api.events.RobotPlacementEvent;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.tools.IToolWrench;
@ -786,6 +788,11 @@ public class BlockGenericPipe extends BlockBuildCraft {
if (((ItemRobot) currentItem.getItem()).getRobotNBT(currentItem) == null) {
return true;
}
RobotPlacementEvent event = new RobotPlacementEvent(player, ((NBTTagCompound) currentItem.stackTagCompound.getTag("board")).getString("id"));
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled()) {
return true;
}
EntityRobot robot = ((ItemRobot) currentItem.getItem())
.createRobot(currentItem, world);
robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());