Search in sources :

Example 6 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D 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)

Example 7 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D 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)

Example 8 with IPos3D

use of com.builtbroken.jlib.data.vector.IPos3D in project Engine by VoltzEngine-Project.

the class RenderSelection method render.

public static void render(Cube selection, Color box_color) {
    GL11.glPushMatrix();
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    Tessellator tess = Tessellator.instance;
    Tessellator.renderingWorldRenderer = false;
    // GL11.glLineWidth(20f);
    boolean render1 = false;
    // render p1
    if (selection.pointOne() != null && selection.pointOne().y() >= 0) {
        IPos3D vec1 = selection.pointOne();
        GL11.glTranslated(vec1.x() - RenderManager.renderPosX, vec1.y() + 1 - RenderManager.renderPosY, vec1.z() - RenderManager.renderPosZ);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glColor3f(255, 0, 0);
        renderBlockBox(tess);
        render1 = true;
    }
    // render p2
    if (selection.pointTwo() != null && selection.pointOne().y() >= 0) {
        IPos3D p1 = selection.pointOne();
        IPos3D p2 = selection.pointTwo();
        if (render1) {
            float x = (float) (p2.x() - p1.x());
            float y = (float) (p1.y() - p2.y()) + 1;
            float z = (float) (p1.z() - p2.z()) - 1;
            GL11.glTranslated(x, y, z);
        } else {
            GL11.glTranslated(p2.x() - RenderManager.renderPosX, p2.y() + 1 - RenderManager.renderPosY, p2.z() - RenderManager.renderPosZ);
        }
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glColor3f(0, 255, 0);
        renderBlockBox(tess);
    }
    if (selection.isValid()) {
        float x = (float) (selection.min().xf() - selection.pointTwo().x());
        float y = (float) (selection.min().yf() - selection.pointTwo().y());
        float z = (float) (selection.min().zf() - selection.pointTwo().z()) - 1;
        // translate to the low point..
        GL11.glTranslated(x, y, z);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glColor3f(box_color.getRed(), box_color.getGreen(), box_color.getBlue());
        renderBlockBoxTo(tess, new Pos(selection.getSizeX(), -selection.getSizeY(), -selection.getSizeZ()));
    }
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    // tess.renderingWorldRenderer = true;
    GL11.glPopMatrix();
}
Also used : IPos3D(com.builtbroken.jlib.data.vector.IPos3D) Tessellator(net.minecraft.client.renderer.Tessellator) Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Aggregations

IPos3D (com.builtbroken.jlib.data.vector.IPos3D)8 Location (com.builtbroken.mc.imp.transform.vector.Location)5 Pos (com.builtbroken.mc.imp.transform.vector.Pos)5 TileEntity (net.minecraft.tileentity.TileEntity)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)3 IWorldPosition (com.builtbroken.mc.api.IWorldPosition)2 Block (net.minecraft.block.Block)2 Entity (net.minecraft.entity.Entity)2 Quaternion (com.builtbroken.mc.imp.transform.rotation.Quaternion)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 ThreadLargeExplosion (icbm.classic.content.explosive.thread.ThreadLargeExplosion)1 IThreadCallBack (icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack)1 ByteBuf (io.netty.buffer.ByteBuf)1 ArrayList (java.util.ArrayList)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 Material (net.minecraft.block.material.Material)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 EntitySheep (net.minecraft.entity.passive.EntitySheep)1