Search in sources :

Example 61 with Pos

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

the class TileMulti method read.

@Override
public boolean read(ByteBuf buf, int id, EntityPlayer player, PacketType type) {
    if (worldObj.isRemote) {
        if (id == 1) {
            // Update host data for client use
            Pos pos = new Pos(buf);
            if (pos.isZero()) {
                this.setHost(null);
            } else {
                TileEntity tile = pos.getTileEntity(worldObj);
                if (tile instanceof IMultiTileHost) {
                    this.setHost((IMultiTileHost) tile);
                }
            }
            // Update should render
            boolean prev = shouldRenderBlock;
            shouldRenderBlock = buf.readBoolean();
            // Update render bounds
            if (buf.readBoolean()) {
                overrideRenderBounds = new Cube(buf);
            } else {
                overrideRenderBounds = new Cube(0, 0, 0, 1, 1, 1);
            }
            if (prev != shouldRenderBlock) {
                worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.lib.transform.vector.Pos) Cube(com.builtbroken.mc.lib.transform.region.Cube) IMultiTileHost(com.builtbroken.mc.api.tile.multiblock.IMultiTileHost)

Example 62 with Pos

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

the class BlastBasic method getEffectedBlocks.

@Override
public void getEffectedBlocks(List<IWorldEdit> list) {
    // TODO disable profiler if not in debug mode
    HashMap<BlockEdit, Float> map = new HashMap();
    profile.startSection("getEffectedBlocks");
    // Start path finder
    profile.startSection("Pathfinder");
    list.add(new BlockEdit(this, Blocks.air, 0));
    triggerPathFinder(map, new BlockEdit(this.world, this.x, this.y, this.z), energy);
    profile.endSection("Pathfinder");
    // Add map keys to block list
    list.addAll(map.keySet());
    // Sort results so blocks are placed in the center first
    profile.startSection("Sorter");
    Collections.sort(list, new Vector3DistanceComparator(new Pos(x(), y(), z())));
    profile.endSection("Sorter");
    profile.endSection("getEffectedBlocks");
    // Generate debug info
    if (Engine.runningAsDev) {
        Engine.instance.logger().info(profile.getOutputSimple());
    }
}
Also used : Vector3DistanceComparator(com.builtbroken.mc.lib.transform.sorting.Vector3DistanceComparator) HashMap(java.util.HashMap) Pos(com.builtbroken.mc.lib.transform.vector.Pos) BlockEdit(com.builtbroken.mc.lib.world.edit.BlockEdit) BlastEventBlockEdit(com.builtbroken.mc.api.event.blast.BlastEventBlockEdit)

Example 63 with Pos

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

the class EntityProjectile method readEntityFromNBT.

@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
    this.xTile = nbt.getShort("xTile");
    this.yTile = nbt.getShort("yTile");
    this.zTile = nbt.getShort("zTile");
    this.sideTile = nbt.getShort("sideTile");
    this.ticksInGround = nbt.getShort("life");
    this.inBlockID = Block.getBlockById(nbt.getByte("inTile") & 255);
    this.inData = nbt.getByte("inData") & 255;
    this.inGround = nbt.getByte("inGround") == 1;
    if (nbt.hasKey("sourcePos")) {
        sourceOfProjectile = new Pos(nbt.getCompoundTag("sourcePos"));
    }
    if (nbt.hasKey("Shooter-UUID")) {
        shootingEntityUUID = UUID.fromString(nbt.getString("Shooter-UUID"));
    }
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos)

Example 64 with Pos

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

the class InternalInventoryHandler method tryGrabFromPosition.

/**
 * Tries to get an item from a position
 *
 * @param position - location of item
 * @param dir      - direction this item is from the original
 * @param ammount  - amount up to one stack to grab
 * @return the grabbed item stack
 */
public ItemStack tryGrabFromPosition(Pos position, ForgeDirection dir, int ammount) {
    ItemStack returnStack = null;
    TileEntity tileEntity = position.getTileEntity(world);
    ForgeDirection direction = dir.getOpposite();
    if (tileEntity != null) {
        if (tileEntity.getClass() == TileEntityChest.class) {
            TileEntityChest[] chests = { (TileEntityChest) tileEntity, null };
            /**
             * Try to find a double chest.
             */
            for (int i = 2; i < 6; i++) {
                ForgeDirection searchDirection = ForgeDirection.getOrientation(i);
                Pos searchPosition = position.clone();
                searchPosition.add(searchDirection);
                if (searchPosition.getTileEntity(world) != null) {
                    if (searchPosition.getTileEntity(world).getClass() == chests[0].getClass()) {
                        chests[1] = (TileEntityChest) searchPosition.getTileEntity(world);
                        break;
                    }
                }
            }
            chestSearch: for (TileEntityChest chest : chests) {
                if (chest != null) {
                    for (int i = 0; i < chest.getSizeInventory(); i++) {
                        ItemStack itemStack = this.removeStackFromInventory(i, chest, ammount);
                        if (itemStack != null) {
                            returnStack = itemStack;
                            break chestSearch;
                        }
                    }
                }
            }
        } else if (tileEntity instanceof ISidedInventory) {
            ISidedInventory inventory = (ISidedInventory) tileEntity;
            int[] slots = inventory.getAccessibleSlotsFromSide(direction.ordinal());
            for (int i = 0; i < slots.length; i++) {
                int slot = slots[i];
                ItemStack slotStack = inventory.getStackInSlot(slot);
                if (inventory.canExtractItem(slot, slotStack, direction.ordinal())) {
                    ItemStack itemStack = this.removeStackFromInventory(slot, inventory, ammount);
                    if (itemStack != null) {
                        returnStack = itemStack;
                        break;
                    }
                }
            }
        } else if (tileEntity instanceof IInventory) {
            IInventory inventory = (IInventory) tileEntity;
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack itemStack = this.removeStackFromInventory(i, inventory, ammount);
                if (itemStack != null) {
                    returnStack = itemStack;
                    break;
                }
            }
        }
    }
    return returnStack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) Pos(com.builtbroken.mc.lib.transform.vector.Pos) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack)

Example 65 with Pos

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

the class Selection method getBlockLocations.

/**
 * Grabs all blocks in the cube that match
 *
 * @param block - block instance to match against, if null will match all
 * @param meta  - meta value to match, if -1 will match all meta
 * @param size  - limiter for the list in case only a few blocks are wanted.
 *              If zero or less will not limit size
 * @return list of blocks, never null but can be empty
 */
public List<Pos> getBlockLocations(Block block, int meta, int size) {
    List<Pos> list = new LinkedList<>();
    for (int y = min().yi(); y <= max().yi(); y++) {
        for (int x = min().xi(); x <= max().xi(); x++) {
            for (int z = min().zi(); z <= max().zi(); z++) {
                if (size > 0 && list.size() > size)
                    return list;
                Pos Pos = new Pos(x, y, z);
                Block b = Pos.getBlock(world);
                int m = Pos.getBlockMetadata(world);
                if (block == null || b == block && (meta == -1 || m == meta)) {
                    list.add(Pos);
                }
            }
        }
    }
    return list;
}
Also used : Pos(com.builtbroken.mc.lib.transform.vector.Pos) Block(net.minecraft.block.Block) LinkedList(java.util.LinkedList)

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