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;
}
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());
}
}
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"));
}
}
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;
}
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;
}
Aggregations