create events for external research

This commit is contained in:
AEnterprise 2014-09-10 14:43:06 +02:00
parent f38a299702
commit cfb63644b4
22 changed files with 228 additions and 84 deletions

View file

@ -0,0 +1,17 @@
package buildcraft.api.events;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
@Cancelable
public class BlockInteractionEvent extends Event {
public EntityPlayer player;
public Block block;
public BlockInteractionEvent(EntityPlayer player, Block block){
this.player = player;
this.block = block;
}
}

View file

@ -0,0 +1,17 @@
package buildcraft.api.events;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
@Cancelable
public class BlockPlacedDownEvent extends Event {
public EntityPlayer player;
public Block block;
public BlockPlacedDownEvent(EntityPlayer player, Block block){
this.player = player;
this.block = block;
}
}

View file

@ -0,0 +1,15 @@
package buildcraft.api.events;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayer;
public class PipePlacedEvent extends Event {
public EntityPlayer player;
public String pipeType;
public PipePlacedEvent(EntityPlayer player, String pipeType){
this.player = player;
this.pipeType = pipeType;
}
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
@ -47,6 +49,11 @@ public class BlockArchitect extends BlockMultiTexture {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, x, y, z)) {

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -44,6 +46,10 @@ public class BlockBlueprintLibrary extends BlockContainer {
if (entityplayer.isSneaking()) {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
TileEntity tile = world.getTileEntity(i, j, k);
if (tile instanceof TileBlueprintLibrary) {

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -75,6 +77,10 @@ public class BlockBuilder extends BlockContainer {
if (entityplayer.isSneaking()) {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
TileEntity tile = world.getTileEntity(x, y, z);
TileBuilder builder = tile instanceof TileBuilder ? (TileBuilder) tile : null;

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
@ -57,6 +59,11 @@ public class BlockConstructionMarker extends BlockMarker {
float par8, float par9) {
super.onBlockActivated(world, x, y, z, entityplayer, par6, par7, par8, par9);
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
TileConstructionMarker marker = (TileConstructionMarker) world.getTileEntity(x, y, z);
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem()

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -51,6 +53,11 @@ public class BlockFiller extends BlockContainer {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
if (!world.isRemote) {
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.FILLER, world, i, j, k);
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -99,6 +101,11 @@ public class BlockMarker extends BlockContainer {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
TileEntity tile = world.getTileEntity(i, j, k);
if (tile instanceof TileMarker) {
((TileMarker) tile).tryConnection();

View file

@ -8,6 +8,8 @@
*/
package buildcraft.builders.urbanism;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
@ -37,6 +39,11 @@ public class BlockUrbanist extends BlockBuildCraft {
world, i, j, k);
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
return true;
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.commander;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
@ -45,6 +47,11 @@ public class BlockRequester extends BlockBuildCraft {
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7,
float par8, float par9) {
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
if (!world.isRemote) {
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.REQUESTER,
world, i, j, k);

View file

@ -8,6 +8,8 @@
*/
package buildcraft.commander;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
@ -45,6 +47,11 @@ public class BlockZonePlan extends BlockBuildCraft {
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7,
float par8, float par9) {
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
if (!world.isRemote) {
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.MAP,
world, i, j, k);

View file

@ -8,18 +8,20 @@
*/
package buildcraft.core;
import java.util.Random;
import buildcraft.api.events.BlockPlacedDownEvent;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import buildcraft.core.utils.Utils;
import java.util.Random;
public abstract class BlockBuildCraft extends BlockContainer {
@ -36,9 +38,11 @@ public abstract class BlockBuildCraft extends BlockContainer {
setHardness(5F);
}
@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)));
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileBuildCraft) {
((TileBuildCraft) tile).onBlockPlacedBy(entity, stack);

View file

@ -8,9 +8,14 @@
*/
package buildcraft.energy;
import java.util.List;
import java.util.Random;
import buildcraft.BuildCraftCore;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.ICustomHighlight;
import buildcraft.core.IItemPipe;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -26,16 +31,10 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.ICustomHighlight;
import buildcraft.core.IItemPipe;
import java.util.List;
import java.util.Random;
public class BlockEngine extends BlockBuildCraft implements ICustomHighlight {
@ -129,6 +128,11 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight {
// return false;
// }
BlockInteractionEvent event = new BlockInteractionEvent(player, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
// Do not open guis when having a pipe in hand
if (player.getCurrentEquippedItem() != null) {
if (player.getCurrentEquippedItem().getItem() instanceof IItemPipe) {

View file

@ -8,6 +8,8 @@
*/
package buildcraft.factory;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@ -45,6 +47,10 @@ public class BlockAutoWorkbench extends BlockBuildCraft {
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
super.onBlockActivated(world, i, j, k, entityplayer, par6, par7, par8, par9);
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
// Drop through if the player is sneaking
if (entityplayer.isSneaking()) {

View file

@ -8,6 +8,8 @@
*/
package buildcraft.factory;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@ -61,6 +63,11 @@ public class BlockHopper extends BlockBuildCraft {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
if (entityplayer.getCurrentEquippedItem() != null) {
if (entityplayer.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
return false;

View file

@ -8,6 +8,8 @@
*/
package buildcraft.factory;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -108,6 +110,10 @@ public class BlockRefinery extends BlockContainer {
if (!(tile instanceof TileRefinery)) {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(player, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
ItemStack current = player.getCurrentEquippedItem();
Item equipped = current != null ? current.getItem() : null;
@ -127,6 +133,7 @@ public class BlockRefinery extends BlockContainer {
}
}
if (!world.isRemote) {
player.openGui(BuildCraftFactory.instance, GuiIds.REFINERY, world, x, y, z);
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.factory;
import buildcraft.api.events.BlockInteractionEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@ -89,6 +91,11 @@ public class BlockTank extends BlockContainer {
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
ItemStack current = entityplayer.inventory.getCurrentItem();
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
if (current != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);

View file

@ -8,9 +8,11 @@
*/
package buildcraft.silicon;
import java.util.List;
import net.minecraft.block.BlockContainer;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ICustomHighlight;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
@ -22,16 +24,11 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ICustomHighlight;
import java.util.List;
public class BlockLaser extends BlockContainer implements ICustomHighlight {
public class BlockLaser extends BlockBuildCraft implements ICustomHighlight {
private static final AxisAlignedBB[][] boxes = {
{AxisAlignedBB.getBoundingBox(0.0, 0.75, 0.0, 1.0, 1.0, 1.0), AxisAlignedBB.getBoundingBox(0.3125, 0.1875, 0.3125, 0.6875, 0.75, 0.6875)}, // -Y

View file

@ -8,10 +8,15 @@
*/
package buildcraft.silicon;
import java.util.List;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
@ -22,14 +27,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import buildcraft.BuildCraftSilicon;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.utils.Utils;
public class BlockLaserTable extends BlockContainer {
public class BlockLaserTable extends BlockBuildCraft {
@SideOnly(Side.CLIENT)
private IIcon[][] icons;
@ -63,6 +63,11 @@ public class BlockLaserTable extends BlockContainer {
return false;
}
BlockInteractionEvent event = new BlockInteractionEvent(entityplayer, this);
FMLCommonHandler.instance().bus().post(event);
if (event.isCanceled())
return false;
if (!world.isRemote) {
int meta = world.getBlockMetadata(i, j, k);
entityplayer.openGui(BuildCraftSilicon.instance, meta, world, i, j, k);

View file

@ -8,14 +8,33 @@
*/
package buildcraft.transport;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.events.PipePlacedEvent;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CoreConstants;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemMapLocation;
import buildcraft.core.ItemRobot;
import buildcraft.core.TileBuffer;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.render.PipeRendererWorld;
import buildcraft.transport.utils.FacadeMatrix;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
@ -36,35 +55,15 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.tools.IToolWrench;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CoreConstants;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemMapLocation;
import buildcraft.core.ItemRobot;
import buildcraft.core.TileBuffer;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.render.PipeRendererWorld;
import buildcraft.transport.utils.FacadeMatrix;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
public class BlockGenericPipe extends BlockBuildCraft {
@ -1108,7 +1107,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
return null;
}
public static boolean placePipe(Pipe<?> pipe, World world, int i, int j, int k, Block block, int meta) {
public static boolean placePipe(Pipe<?> pipe, World world, int i, int j, int k, Block block, int meta, EntityPlayer player) {
if (world.isRemote) {
return true;
}
@ -1121,6 +1120,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
TileGenericPipe tilePipe = (TileGenericPipe) tile;
tilePipe.initialize(pipe);
tilePipe.sendUpdateToClient();
FMLCommonHandler.instance().bus().post(new PipePlacedEvent(player, pipe.item.getUnlocalizedName()));
}
}

View file

@ -8,10 +8,14 @@
*/
package buildcraft.transport;
import java.util.List;
import org.apache.logging.log4j.Level;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.IIconProvider;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.IItemPipe;
import buildcraft.core.ItemBuildCraft;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@ -19,16 +23,9 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import org.apache.logging.log4j.Level;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.IIconProvider;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.IItemPipe;
import buildcraft.core.ItemBuildCraft;
import java.util.List;
public class ItemPipe extends ItemBuildCraft implements IItemPipe {
@ -88,7 +85,7 @@ public class ItemPipe extends ItemBuildCraft implements IItemPipe {
return true;
}
if (BlockGenericPipe.placePipe(pipe, world, i, j, k, block, 0)) {
if (BlockGenericPipe.placePipe(pipe, world, i, j, k, block, 0, entityplayer)) {
block.onBlockPlacedBy(world, i, j, k, entityplayer, itemstack);
// TODO: Fix sound