Search in sources :

Example 46 with Pos

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

the class PacketSpawnStream method handleClientSide.

@Override
public void handleClientSide(EntityPlayer player) {
    if (player.worldObj.provider.dimensionId == dim) {
        if (type == 0) {
            short short1 = 128;
            final Random rand = player.worldObj.rand;
            for (int l = 0; l < short1; ++l) {
                double d6 = (double) l / ((double) short1 - 1.0D);
                float f = (rand.nextFloat() - 0.5F) * 0.2F;
                float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
                float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
                double d7 = vx + (x - vx) * d6 + (rand.nextDouble() - 0.5D) * 5.0D;
                double d8 = vy + (y - vy) * d6 + (rand.nextDouble() - 0.5D) * 5.0D;
                double d9 = vz + (z - vz) * d6 + (rand.nextDouble() - 0.5D) * 5.0D;
                Engine.proxy.spawnParticle("portal", player.worldObj, d7, d8, d9, (double) f, (double) f1, (double) f2);
            }
        } else if (type == 1) {
            Engine.proxy.spawnBeamFx(SharedAssets.GREY_TEXTURE, player.worldObj, new Pos(x, y, z), new Pos(vx, vy, vz), Color.RED, 5);
        } else if (type == 2) {
            Engine.proxy.spawnBeamFx(SharedAssets.GREY_TEXTURE, player.worldObj, new Pos(x, y, z), new Pos(vx, vy, vz), new Color(red, green, blue), 5);
        }
    }
}
Also used : Random(java.util.Random) Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 47 with Pos

use of com.builtbroken.mc.lib.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.lib.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 48 with Pos

use of com.builtbroken.mc.lib.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.lib.transform.vector.Pos) Block(net.minecraft.block.Block)

Example 49 with Pos

use of com.builtbroken.mc.lib.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.lib.transform.vector.Pos) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) Pair(com.builtbroken.jlib.type.Pair)

Example 50 with Pos

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

the class EntityAbstractCart method onUpdate.

@Override
public void onUpdate() {
    this.prevDistanceWalkedModified = this.distanceWalkedModified;
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.prevRotationPitch = this.rotationPitch;
    this.prevRotationYaw = this.rotationYaw;
    // Updates the collision box
    if (invalidBox || boundingBox == null) {
        validateBoundBox();
    }
    // Grab rail side if null
    if (railSide == null) {
        for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
            Pos pos = new Pos((Entity) this).add(side);
            Block block = pos.getBlock(worldObj);
            final TileEntity tile = pos.getTileEntity(worldObj);
            if (!(block instanceof ITransportRailBlock || tile instanceof ITransportRail)) {
                railSide = side;
                break;
            }
        }
    }
    Pos pos = new Pos(Math.floor(posX), Math.floor(posY), Math.floor(posZ)).floor();
    Block block = pos.getBlock(world());
    if (block == Blocks.air) {
        pos = pos.add(railSide);
        block = pos.getBlock(worldObj);
    }
    final TileEntity tile = pos.getTileEntity(worldObj);
    if (!worldObj.isRemote) {
        // Kills entity if it falls out of the world, should never happen
        if (this.posY < -64.0D) {
            this.kill();
            return;
        } else // Breaks entity if its not on a track
        if (!(block instanceof ITransportRailBlock || tile instanceof ITransportRail)) {
            destroyCart();
            return;
        }
        // Moves the entity
        if (motionX != 0 || motionY != 0 || motionZ != 0) {
            moveEntity(motionX, motionY, motionZ);
            recenterCartOnRail();
        }
    }
    if (isAirBorne) {
        motionY -= (9.8 / 20);
        motionY = Math.max(-2, motionY);
    }
    // Handles pushing entities out of the way
    doCollisionLogic();
    // Updates the rail and cart position
    if (tile instanceof ITransportRail) {
        ((ITransportRail) tile).tickRailFromCart(this);
    } else if (block instanceof ITransportRailBlock) {
        ((ITransportRailBlock) block).tickRailFromCart(this, world(), pos.xi(), pos.yi(), pos.zi(), worldObj.getBlockMetadata(pos.xi(), pos.yi(), pos.zi()));
    }
    if (!worldObj.isRemote && updateClient) {
        sentDescriptionPacket();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITransportRailBlock(com.builtbroken.mc.api.rails.ITransportRailBlock) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ITransportRail(com.builtbroken.mc.api.rails.ITransportRail) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ITransportRailBlock(com.builtbroken.mc.api.rails.ITransportRailBlock) 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