Search in sources :

Example 6 with IMultiTile

use of com.builtbroken.mc.api.tile.multiblock.IMultiTile in project Engine by VoltzEngine-Project.

the class MultiBlockHelper method canBuild.

public static boolean canBuild(World world, int x, int y, int z, Map<IPos3D, String> map, boolean offset) {
    if (world != null && Engine.multiBlock != null) {
        //Ensure the map is not null or empty in case there is no structure to generate
        if (map != null && !map.isEmpty()) {
            //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 || type == null || type.isEmpty()) {
                    return false;
                }
                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(world, x, y, z).add(location);
                    }
                    Block block = world.getBlock(location.xi(), location.yi(), location.zi());
                    if (!block.isAir(world, location.xi(), location.yi(), location.zi()) && !block.isReplaceable(world, location.xi(), location.yi(), location.zi())) {
                        return false;
                    } else if (block == Engine.multiBlock) {
                        TileEntity tileEntity = world.getTileEntity(location.xi(), location.yi(), location.zi());
                        if (tileEntity instanceof IMultiTile && ((IMultiTile) tileEntity).getHost() != null) {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Block(net.minecraft.block.Block) 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