Search in sources :

Example 26 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class TileMulti method updateConnections.

public void updateConnections() {
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        Pos pos = new Pos(this).add(dir);
        Block b = pos.getBlock(getWorldObj());
        if (connectedBlocks.containsKey(dir)) {
            // TODO notify that a block has changed
            if (connectedBlocks.get(dir) != b) {
                connectedBlocks.remove(dir);
            }
        }
        if (b != null && !b.isAir(getWorldObj(), xCoord, yCoord, zCoord)) {
            connectedBlocks.put(dir, b);
        }
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) Block(net.minecraft.block.Block)

Example 27 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class SelectionHandler method updatePlayerRenderData.

public static void updatePlayerRenderData(EntityPlayerMP player) {
    List<Cube> cubes = new ArrayList();
    List<Cube> regions = new ArrayList();
    Cube selection = getSelection(player);
    for (Cube cube : selections.values()) {
        if (cube != selection && cube.distance(new Pos(player)) <= 160) {
            cubes.add(cube);
        }
    }
    for (Region region : RegionManager.getControllerForWorld(player.worldObj).getRegionsNear(player, 160)) {
        for (Cube cube : region.segments) {
            if (cube.isCloseToAnyCorner(new Pos(player), 160)) {
                regions.add(cube);
            }
        }
    }
    Engine.instance.packetHandler.sendToPlayer(new PacketSelectionData(selection, cubes, regions), player);
}
Also used : PacketSelectionData(com.builtbroken.mc.core.network.packet.PacketSelectionData) Cube(com.builtbroken.mc.lib.transform.region.Cube) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ArrayList(java.util.ArrayList) Region(com.builtbroken.mc.lib.modflags.Region)

Example 28 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class BlockRenderHandler method renderWorldBlock.

@Override
public boolean renderWorldBlock(IBlockAccess access, int x, int y, int z, Block block, int modelId, RenderBlocks renderBlocks) {
    /**
     * Try TileEntity rendering
     */
    TileEntity tile = access.getTileEntity(x, y, z);
    if (tile instanceof Tile) {
        return ((Tile) tile).renderStatic(renderBlocks, new Pos(x, y, z), 0);
    }
    /**
     * Try Block rendering
     */
    if (block instanceof BlockTile) {
        BlockTile dummy = (BlockTile) block;
        tile = dummy.inject(access, x, y, z);
        boolean b = ((Tile) tile).renderStatic(renderBlocks, new Pos(x, y, z), 0);
        dummy.eject();
        return b;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.lib.transform.vector.Pos) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile)

Example 29 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class FluidUtility method drainBlock.

/**
 * Drains a block of fluid
 *
 * @param doDrain - do the action
 * @param update  - block update flag to use
 * @return FluidStack drained from the block
 */
public static FluidStack drainBlock(World world, Pos position, boolean doDrain, int update) {
    if (world == null || position == null) {
        return null;
    }
    Block block = position.getBlock(world);
    int meta = position.getBlockMetadata(world);
    if (block != null) {
        if (block instanceof IFluidBlock && ((IFluidBlock) block).canDrain(world, position.xi(), position.yi(), position.zi())) {
            return ((IFluidBlock) block).drain(world, position.xi(), position.yi(), position.zi(), doDrain);
        } else if ((block == Blocks.water || block == Blocks.flowing_water) && position.getBlockMetadata(world) == 0) {
            if (doDrain) {
                Pos vec = position.clone().add(ForgeDirection.UP);
                if (vec.getBlock(world) == Blocks.water) {
                    vec.setBlock(world, Blocks.air, 0, update);
                    position.setBlock(world, block, meta);
                } else {
                    position.setBlock(world, Blocks.air, 0, update);
                }
            }
            return new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME);
        } else if ((block == Blocks.lava || block == Blocks.flowing_lava) && position.getBlockMetadata(world) == 0) {
            if (doDrain) {
                position.setBlock(world, Blocks.air, 0, update);
            }
            return new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME);
        }
    }
    return null;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) Block(net.minecraft.block.Block)

Example 30 with Pos

use of com.builtbroken.mc.lib.transform.vector.Pos in project Engine by VoltzEngine-Project.

the class FluidUtility method fillBlock.

/**
 * Helper method to fill a location with a fluid
 * <p/>
 * Note: This does not update the block to prevent the liquid from flowing
 *
 * @return
 */
public static int fillBlock(World world, Pos node, FluidStack stack, boolean doFill) {
    if ((isFillableBlock(world, node) || isFillableFluid(world, node)) && stack != null && stack.amount >= FluidContainerRegistry.BUCKET_VOLUME) {
        if (doFill) {
            Block block = node.getBlock(world);
            int meta = node.getBlockMetadata(world);
            Pos vec = node.clone().add(ForgeDirection.UP);
            if (block != null) {
                if (block == Blocks.water && vec.getBlock(world).isAir(world, node.xi(), node.yi(), node.zi())) {
                    vec.setBlock(world, block, meta);
                } else if (replacableBlocks.contains(block) && !nonBlockDropList.contains(block)) {
                    block.dropBlockAsItem(world, node.xi(), node.yi(), node.zi(), meta, 1);
                    block.breakBlock(world, node.xi(), node.yi(), node.zi(), block, meta);
                }
            }
            node.setBlock(world, stack.getFluid().getBlock());
        }
        return FluidContainerRegistry.BUCKET_VOLUME;
    }
    return 0;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) Block(net.minecraft.block.Block)

Aggregations

Pos (com.builtbroken.mc.lib.transform.vector.Pos)68 Block (net.minecraft.block.Block)11 TileEntity (net.minecraft.tileentity.TileEntity)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)7 Cube (com.builtbroken.mc.lib.transform.region.Cube)6 Test (org.junit.Test)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 BlockEdit (com.builtbroken.mc.lib.world.edit.BlockEdit)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Vector3DistanceComparator (com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Pair (com.builtbroken.jlib.type.Pair)3 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)3 Quaternion (com.builtbroken.mc.lib.transform.rotation.Quaternion)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)3