Search in sources :

Example 86 with Pos

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

the class SchematicMap method loadWorldSelection.

public SchematicMap loadWorldSelection(World world, IPos3D pos, IPos3D pos2) {
    int deltaX, deltaY, deltaZ;
    Pos start = new Pos(pos.x() > pos2.x() ? pos2.x() : pos.x(), pos.y() > pos2.y() ? pos2.y() : pos.y(), pos.z() > pos2.z() ? pos2.z() : pos.z());
    SchematicMap sch = new SchematicMap();
    if (pos.x() < pos2.x()) {
        deltaX = (int) (pos2.x() - pos.x() + 1);
    } else {
        deltaX = (int) (pos.x() - pos2.x() + 1);
    }
    if (pos.y() < pos2.y()) {
        deltaY = (int) (pos2.y() - pos.y() + 1);
    } else {
        deltaY = (int) (pos.y() - pos2.y() + 1);
    }
    if (pos.z() < pos2.z()) {
        deltaZ = (int) (pos2.z() - pos.z() + 1);
    } else {
        deltaZ = (int) (pos.z() - pos2.z() + 1);
    }
    sch.schematicSize = new Pos(deltaX, deltaY, deltaZ);
    for (int x = 0; x < deltaX; ++x) {
        for (int y = 0; y < deltaY; ++y) {
            for (int z = 0; z < deltaZ; ++z) {
                Block block = world.getBlock((int) start.x() + x, (int) start.y() + y, (int) start.z() + z);
                int blockMeta = world.getBlockMetadata((int) start.x() + x, (int) start.y() + y, (int) start.z() + z);
                sch.block_map.put(new Pos(x, y, z), new Pair<>(block, blockMeta));
            }
        }
    }
    return sch;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block)

Example 87 with Pos

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

the class SchematicMap method save.

@Override
public NBTTagCompound save(NBTTagCompound nbt) {
    if (!init) {
        this.init();
    }
    NBTTagCompound blockNBT = nbt.getCompoundTag(BLOCK_LIST_SAVE_NAME);
    if (this.schematicSize != null) {
        nbt.setInteger("sizeX", (int) this.schematicSize.x());
        nbt.setInteger("sizeY", (int) this.schematicSize.y());
        nbt.setInteger("sizeZ", (int) this.schematicSize.z());
    }
    if (this.schematicCenter != null) {
        nbt.setInteger("centerX", (int) this.schematicCenter.x());
        nbt.setInteger("centerY", (int) this.schematicCenter.y());
        nbt.setInteger("centerZ", (int) this.schematicCenter.z());
    }
    int i = 0;
    for (Entry<Pos, Pair<Block, Integer>> entry : block_map.entrySet()) {
        String output = "";
        Block block = entry.getValue().left();
        if (block != null && SchematicMap.BLOCK_SAVE_MAP_REV.containsKey(block)) {
            output += SchematicMap.BLOCK_SAVE_MAP_REV.get(block);
        } else {
            output += entry.getValue().left();
        }
        output += ":" + entry.getValue().right();
        output += ":" + (entry.getKey().x()) + ":" + ((int) entry.getKey().y()) + ":" + ((int) entry.getKey().z());
        blockNBT.setString("Block" + i, output);
        i++;
    }
    blockNBT.setInteger("count", i);
    nbt.setTag(BLOCK_LIST_SAVE_NAME, blockNBT);
    return nbt;
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) Pair(com.builtbroken.jlib.type.Pair)

Example 88 with Pos

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

the class AbstractTileEntityTest method testGetDistanceFrom.

@Test
public void testGetDistanceFrom() {
    T tile = newTile();
    FakeWorld world = FakeWorld.newWorld("testGetDistanceFrom");
    tile.setWorldObj(world);
    double distance = tile.getDistanceFrom(10, 14, 15);
    double distance2 = new Pos(0.5).sub(10, 14, 15).magnitudeSquared();
    assertTrue("Distance = " + distance + "  Distance2 = " + distance2, Math.abs(distance - distance2) < .01);
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) AbstractTest(com.builtbroken.mc.testing.junit.AbstractTest) Test(org.junit.Test)

Example 89 with Pos

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

the class SchematicMap method getBlocksToPlace.

/**
     * Gets all blocks needed to build the schematic at the given location
     *
     * @param spot                 - center point of the schematic
     * @param blockMap             - map of blocks from the schematic file
     * @param checkWorld           - check if blocks are already placed
     * @param checkIfWorldIsLoaded - check if the area is loaded, make sure this is true if
     *                             checkWorld boolean is true as it effects the results if the chunk is unloaded. Setting this
     *                             true will not load the area and is designed to prevent wasting blocks when generating
     *                             buildings using actual blocks
     */
public void getBlocksToPlace(Location spot, List<IWorldEdit> blockMap, boolean checkWorld, boolean checkIfWorldIsLoaded) {
    if (this.block_map != null) {
        for (Entry<Pos, Pair<Block, Integer>> entry : this.block_map.entrySet()) {
            Block block = entry.getValue().left();
            int meta = entry.getValue().right();
            if (block == null || block != Blocks.sponge) {
                if (meta > 15) {
                    meta = 15;
                } else if (meta < 0) {
                    meta = 0;
                }
                Pos setPos = spot.toPos().subtract(this.schematicCenter).add(entry.getKey());
                if (checkWorld) {
                    if (checkIfWorldIsLoaded) {
                        Chunk chunk = spot.world.getChunkFromBlockCoords(setPos.xi(), setPos.zi());
                        if (!chunk.isChunkLoaded) {
                            continue;
                        }
                    }
                    Block checkID = setPos.getBlock(spot.world);
                    int checkMeta = setPos.getBlockMetadata(spot.world);
                    if (checkID == block && checkMeta == meta) {
                        continue;
                    }
                }
                blockMap.add(new BlockEdit(spot.world, setPos).set(block, meta));
            }
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block) Chunk(net.minecraft.world.chunk.Chunk) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) Pair(com.builtbroken.jlib.type.Pair)

Example 90 with Pos

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

the class MultiBlockListener method onMultiTileBroken.

@Override
public boolean onMultiTileBroken(IMultiTile tileMulti, Object source, boolean harvest) {
    if (!_destroyingStructure && tileMulti instanceof TileEntity) {
        Pos pos = new Pos((TileEntity) tileMulti).floor().sub(new Pos(this).floor());
        if (getLayoutOfMultiBlock().containsKey(pos)) {
            _destroyingStructure = true;
            MultiBlockHelper.destroyMultiBlockStructure(getMultiTileHost() != null ? getMultiTileHost() : this, harvest, true, true);
            _destroyingStructure = false;
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.imp.transform.vector.Pos)

Aggregations

Pos (com.builtbroken.mc.imp.transform.vector.Pos)105 Block (net.minecraft.block.Block)25 TileEntity (net.minecraft.tileentity.TileEntity)13 Location (com.builtbroken.mc.imp.transform.vector.Location)11 Entity (net.minecraft.entity.Entity)11 Cube (com.builtbroken.mc.imp.transform.region.Cube)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 Test (org.junit.Test)7 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)6 EntityMissile (icbm.classic.content.entity.EntityMissile)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 PacketTile (com.builtbroken.mc.core.network.packet.PacketTile)5 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)5 ItemStack (net.minecraft.item.ItemStack)5 EulerAngle (com.builtbroken.mc.imp.transform.rotation.EulerAngle)4 BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)4 Tile (com.builtbroken.mc.prefab.tile.Tile)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4