Merge pull request #2014 from AEnterprise/6.1.x

create events for external research
This commit is contained in:
SpaceToad 2014-09-13 09:42:18 +01:00
commit fd8d8531a1
22 changed files with 188 additions and 6 deletions

View file

@ -0,0 +1,18 @@
package buildcraft.api.events;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
@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,19 @@
package buildcraft.api.events;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
@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,16 @@
package buildcraft.api.events;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.eventhandler.Event;
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

@ -18,9 +18,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockMultiTexture;
import buildcraft.core.CreativeTabBuildCraft;
@ -47,6 +50,12 @@ 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

@ -18,10 +18,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
@ -44,6 +46,11 @@ 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

@ -21,12 +21,14 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
@ -75,6 +77,11 @@ 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

@ -17,9 +17,11 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.utils.Utils;
public class BlockConstructionMarker extends BlockMarker {
@ -57,6 +59,12 @@ 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

@ -18,12 +18,14 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
@ -51,6 +53,12 @@ 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

@ -18,12 +18,14 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemMapLocation;
import buildcraft.core.utils.Utils;
@ -99,6 +101,12 @@ 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

@ -14,9 +14,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.GuiIds;
@ -37,6 +40,12 @@ 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

@ -17,12 +17,14 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.utils.Utils;
@ -45,6 +47,12 @@ 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

@ -17,12 +17,14 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.utils.Utils;
@ -45,6 +47,12 @@ 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

@ -14,11 +14,15 @@ 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 cpw.mods.fml.common.FMLCommonHandler;
import buildcraft.api.events.BlockPlacedDownEvent;
import buildcraft.core.utils.Utils;
public abstract class BlockBuildCraft extends BlockContainer {
@ -36,9 +40,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

@ -27,12 +27,14 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.ICustomHighlight;
import buildcraft.core.IItemPipe;
@ -129,6 +131,12 @@ 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

@ -15,10 +15,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftFactory;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
@ -45,6 +47,11 @@ 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

@ -15,11 +15,13 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
@ -61,6 +63,12 @@ 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

@ -20,6 +20,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -28,6 +29,7 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
@ -108,6 +110,11 @@ 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 +134,7 @@ public class BlockRefinery extends BlockContainer {
}
}
if (!world.isRemote) {
player.openGui(BuildCraftFactory.instance, GuiIds.REFINERY, world, x, y, z);
}

View file

@ -18,6 +18,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -26,6 +27,7 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.BuildCraftCore;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.inventory.InvUtils;
@ -89,6 +91,12 @@ 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

@ -10,7 +10,6 @@ package buildcraft.silicon;
import java.util.List;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
@ -28,10 +27,11 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ICustomHighlight;
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

@ -11,7 +11,6 @@ package buildcraft.silicon;
import java.util.List;
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 +21,17 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.events.BlockInteractionEvent;
import buildcraft.core.BlockBuildCraft;
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 +65,12 @@ 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,6 +8,7 @@
*/
package buildcraft.transport;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -37,6 +38,7 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
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;
@ -46,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.PipePlacedEvent;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.tools.IToolWrench;
@ -1108,7 +1111,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 +1124,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

@ -88,7 +88,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