use of com.builtbroken.mc.api.tile.multiblock.IMultiTile in project Engine by VoltzEngine-Project.
the class BlockMultiblock method breakBlock.
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
IMultiTile tile = getTile(world, x, y, z);
if (tile != null && tile.getHost() != null) {
tile.getHost().onMultiTileBroken(tile, null, true);
}
super.breakBlock(world, x, y, z, block, meta);
}
use of com.builtbroken.mc.api.tile.multiblock.IMultiTile in project Engine by VoltzEngine-Project.
the class BlockMultiblock method onBlockAdded.
@Override
public void onBlockAdded(World world, int x, int y, int z) {
IMultiTile tile = getTile(world, x, y, z);
if (tile != null && tile.getHost() != null) {
tile.getHost().onMultiTileAdded(tile);
}
super.onBlockAdded(world, x, y, z);
}
use of com.builtbroken.mc.api.tile.multiblock.IMultiTile in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method destroyMultiBlockStructure.
/**
* Breaks down the multiblock stucture linked to the host
*
* @param host - host providing the layour of the structure
* @param doDrops - attempt to drop blocks?
* @param offset - offset the layout by the location of the host?
* @param killHost - destroy the host block as well?
*/
public static void destroyMultiBlockStructure(IMultiTileHost host, boolean doDrops, boolean offset, boolean killHost) {
if (host != null) {
HashMap<IPos3D, String> map = host.getLayoutOfMultiBlock();
if (map != null && !map.isEmpty()) {
IWorldPosition center;
if (host instanceof TileEntity) {
center = new Location((TileEntity) host);
} else if (host instanceof IWorldPosition) {
center = (IWorldPosition) host;
} else {
logger.error("MultiBlockHelper >> Tile[" + host + "]'s is not a TileEntity or IWorldPosition instance, thus we can not get a position to break down the structure.");
return;
}
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
Pos pos = entry.getKey() instanceof Pos ? (Pos) entry.getKey() : new Pos(entry.getKey());
if (offset) {
pos = pos.add(center);
}
TileEntity tile = pos.getTileEntity(center.world());
if (tile instanceof IMultiTile) {
((IMultiTile) tile).setHost(null);
pos.setBlockToAir(center.world());
}
}
if (doDrops) {
InventoryUtility.dropBlockAsItem(center, killHost);
} else if (killHost) {
center.world().setBlockToAir(center.xi(), center.yi(), center.zi());
}
} else {
logger.error("MultiBlockHelper >> Tile[" + host + "]'s structure map is empty");
}
}
}
use of com.builtbroken.mc.api.tile.multiblock.IMultiTile in project ICBM-Classic by BuiltBrokenModding.
the class ItemRadarGun method onItemUse.
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hit_x, float hit_y, float hit_z) {
if (world.isRemote) {
return true;
}
Location location = new Location(world, x, y, z);
TileEntity tile = location.getTileEntity();
if (tile instanceof IMultiTile) {
IMultiTileHost host = ((IMultiTile) tile).getHost();
if (host instanceof TileEntity) {
tile = (TileEntity) host;
}
}
if (player.isSneaking()) {
stack.setTagCompound(null);
stack.setItemDamage(0);
LanguageUtility.addChatToPlayer(player, "gps.cleared");
player.inventoryContainer.detectAndSendChanges();
return true;
} else {
Location storedLocation = getLocation(stack);
if (storedLocation == null || !storedLocation.isAboveBedrock()) {
LanguageUtility.addChatToPlayer(player, "gps.error.pos.invalid");
return true;
} else if (tile instanceof ILauncherController) {
((ILauncherController) tile).setTarget(storedLocation.toPos());
LanguageUtility.addChatToPlayer(player, "gps.data.transferred");
return true;
}
}
return false;
}
use of com.builtbroken.mc.api.tile.multiblock.IMultiTile in project Engine by VoltzEngine-Project.
the class MultiBlockHelper method buildMultiBlock.
/**
* Builds a multi block structure using data from the provided tile
*
* @param world - world
* @param tile - multiblock host
* @param validate - if true will check if a tile already exists at location rather than placing a new one
* @param offset - offset the map position by the tile center
*/
public static void buildMultiBlock(World world, IMultiTileHost tile, boolean validate, boolean offset) {
//Rare edge case, should never happen
if (world == null) {
logger.error("MultiBlockHelper: buildMultiBlock was called with a null world by " + tile, new RuntimeException());
return;
}
//Rare edge case, should never happen
if (tile == null) {
logger.error("MultiBlockHelper: buildMultiBlock was called with a null tile ", new RuntimeException());
return;
}
//Multi-block should be registered but just in case a dev forgot
if (Engine.multiBlock != null) {
//Get layout of multi-block for it's current state
Map<IPos3D, String> map = tile.getLayoutOfMultiBlock();
//Ensure the map is not null or empty in case there is no structure to generate
if (map != null && !map.isEmpty()) {
//Keep track of position just for traceability
int i = 0;
//Loop all blocks and start placement
for (Map.Entry<IPos3D, String> entry : map.entrySet()) {
IPos3D location = entry.getKey();
String type = entry.getValue();
String dataString = null;
if (location == null) {
logger.error("MultiBlockHelper: location[" + i + "] is null, this is most likely in error in " + tile);
i++;
continue;
}
if (type == null) {
logger.error("MultiBlockHelper: type[" + i + "] is null, this is most likely in error in " + tile);
i++;
continue;
}
if (type.isEmpty()) {
logger.error("MultiBlockHelper: type[" + i + "] is empty, this is most likely in error in " + tile);
i++;
continue;
}
if (type.contains("#")) {
dataString = type.substring(type.indexOf("#") + 1, type.length());
type = type.substring(0, type.indexOf("#"));
}
EnumMultiblock enumType = EnumMultiblock.get(type);
if (enumType != null) {
//Moves the position based on the location of the host
if (offset) {
location = new Location((IWorldPosition) tile).add(location);
}
TileEntity ent = world.getTileEntity(location.xi(), location.yi(), location.zi());
if (!validate || ent == null || enumType.clazz != ent.getClass()) {
if (!world.setBlock(location.xi(), location.yi(), location.zi(), Engine.multiBlock, enumType.ordinal(), 3)) {
logger.error("MultiBlockHelper: type[" + i + ", " + type + "] error block was not placed ");
}
ent = world.getTileEntity(location.xi(), location.yi(), location.zi());
}
if (ent instanceof IMultiTile) {
((IMultiTile) ent).setHost(tile);
setData(dataString, (IMultiTile) ent);
} else {
logger.error("MultiBlockHelper: type[" + i + ", " + type + "] tile at location is not IMultiTile, " + ent);
}
} else {
logger.error("MultiBlockHelper: type[" + i + ", " + type + "] is not a invalid multi tile type, this is most likely an error in " + tile);
}
i++;
}
} else {
logger.error("Tile[" + tile + "] didn't return a structure map");
}
} else {
logger.error("MultiBlock was never registered, this is a critical error and can have negative effects on gameplay. " + "Make sure the block was not disabled in the configs and contact support to ensure nothing is broken", new RuntimeException());
}
}
Aggregations