From 0c11181e859d68abff962b5b9065129d4aeaa40c Mon Sep 17 00:00:00 2001 From: AEnterprise Date: Tue, 16 Sep 2014 17:39:18 +0200 Subject: [PATCH] add event to detect and prevent the placement of robots --- .../api/events/RobotPlacementEvent.java | 26 +++++++++++++++++++ .../transport/BlockGenericPipe.java | 7 +++++ 2 files changed, 33 insertions(+) create mode 100644 api/buildcraft/api/events/RobotPlacementEvent.java diff --git a/api/buildcraft/api/events/RobotPlacementEvent.java b/api/buildcraft/api/events/RobotPlacementEvent.java new file mode 100644 index 00000000..294ca37d --- /dev/null +++ b/api/buildcraft/api/events/RobotPlacementEvent.java @@ -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; + } + +} diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 25f61d12..fe38f2af 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -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());