use of com.builtbroken.jlib.type.Pair in project Engine by VoltzEngine-Project.
the class LoadableHandler method applyModule.
/**
* Call for modules late or as already existing modules, DO NOT CALL FOR REGISTERED Proxies!
*/
public void applyModule(ILoadable module) {
loadables.put(module, new Pair(false, false));
switch(phase) {
case DONE:
break;
case POSTINIT:
module.preInit();
module.init();
module.postInit();
break;
case INIT:
module.preInit();
module.init();
break;
case PREINIT:
}
}
use of com.builtbroken.jlib.type.Pair 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));
}
}
}
}
use of com.builtbroken.jlib.type.Pair 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;
}
use of com.builtbroken.jlib.type.Pair in project Engine by VoltzEngine-Project.
the class InventoryUtility method findFirstItemInInventory.
/**
* Gets the first slot containing items
* <p>
* Does not actually consume the items
*
* @param inventory - inventory to search for items
* @param side - side to access, used for {@link ISidedInventory}
* If this value is not between 0-5 it will not use
* ISideInventory and instead bypass the sided checks
* @param stackSize - amount to remove
* @return pair containing the removed stack, and item
*/
public static Pair<ItemStack, Integer> findFirstItemInInventory(IInventory inventory, int side, int stackSize, IInventoryFilter filter) {
if (!(inventory instanceof ISidedInventory) || side == -1 || side > 5) {
for (int i = inventory.getSizeInventory() - 1; i >= 0; i--) {
final ItemStack slotStack = inventory.getStackInSlot(i);
if (slotStack != null && (filter == null || filter.isStackInFilter(slotStack))) {
int amountToTake = stackSize <= 0 ? slotStack.getMaxStackSize() : Math.min(stackSize, slotStack.getMaxStackSize());
amountToTake = Math.min(amountToTake, slotStack.stackSize);
ItemStack toSend = slotStack.copy();
toSend.stackSize = amountToTake;
// inventory.decrStackSize(i, amountToTake);
return new Pair(toSend, i);
}
}
} else {
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
if (slots != null) {
for (int get = slots.length - 1; get >= 0; get--) {
int slotID = slots[get];
final ItemStack slotStack = sidedInventory.getStackInSlot(slotID);
if (slotStack != null && (filter == null || filter.isStackInFilter(slotStack))) {
int amountToTake = stackSize <= 0 ? slotStack.getMaxStackSize() : Math.min(stackSize, slotStack.getMaxStackSize());
amountToTake = Math.min(amountToTake, slotStack.stackSize);
ItemStack toSend = slotStack.copy();
toSend.stackSize = amountToTake;
if (sidedInventory.canExtractItem(slotID, toSend, side)) {
// sidedInventory.decrStackSize(slotID, amountToTake);
return new Pair(toSend, slotID);
}
}
}
}
}
return null;
}
Aggregations