Search in sources :

Example 1 with IMultiTile

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);
}
Also used : IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile)

Example 2 with IMultiTile

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);
}
Also used : IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile)

Example 3 with IMultiTile

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");
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Pos(com.builtbroken.mc.imp.transform.vector.Pos) IWorldPosition(com.builtbroken.mc.api.IWorldPosition) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 4 with IMultiTile

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILauncherController(resonant.api.explosion.ILauncherController) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) IMultiTileHost(com.builtbroken.mc.api.tile.multiblock.IMultiTileHost) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 5 with IMultiTile

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());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) IMultiTile(com.builtbroken.mc.api.tile.multiblock.IMultiTile) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.builtbroken.mc.imp.transform.vector.Location)

Aggregations

IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)6 Location (com.builtbroken.mc.imp.transform.vector.Location)4 TileEntity (net.minecraft.tileentity.TileEntity)4 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IWorldPosition (com.builtbroken.mc.api.IWorldPosition)1 IMultiTileHost (com.builtbroken.mc.api.tile.multiblock.IMultiTileHost)1 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 Block (net.minecraft.block.Block)1 ILauncherController (resonant.api.explosion.ILauncherController)1