use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntityArcFurnace method update.
@Override
public void update() {
super.update();
if (!worldObj.isRemote && !isDummy() && !isRSDisabled() && energyStorage.getEnergyStored() > 0) {
if (this.tickedProcesses > 0)
for (int i = 23; i < 26; i++) if (this.inventory[i].attemptDamageItem(1, worldObj.rand)) {
this.inventory[i] = null;
// updateClient = true;
// update = true;
}
if (this.processQueue.size() < this.getProcessQueueMaxLength()) {
Set<Integer> usedInvSlots = new HashSet<Integer>();
// final int[] usedInvSlots = new int[8];
for (MultiblockProcess<ArcFurnaceRecipe> process : processQueue) if (process instanceof MultiblockProcessInMachine)
for (int i : ((MultiblockProcessInMachine<ArcFurnaceRecipe>) process).inputSlots) usedInvSlots.add(i);
// Integer[] preferredSlots = new Integer[]{0,1,2,3,4,5,6,7};
// Arrays.sort(preferredSlots, 0,8, new Comparator<Integer>(){
// @Override
// public int compare(Integer arg0, Integer arg1)
// {
// return Integer.compare(usedInvSlots[arg0],usedInvSlots[arg1]);
// }});
ItemStack[] additives = new ItemStack[4];
for (int i = 0; i < 4; i++) additives[i] = (inventory[12 + i] != null ? inventory[12 + i].copy() : null);
for (int slot = 0; slot < 12; slot++) if (!usedInvSlots.contains(slot)) {
ItemStack stack = this.getInventory()[slot];
// }
if (stack != null && stack.stackSize > 0) {
ArcFurnaceRecipe recipe = ArcFurnaceRecipe.findRecipe(stack, additives);
if (recipe != null) {
MultiblockProcessArcFurnace process = new MultiblockProcessArcFurnace(recipe, slot, 12, 13, 14, 15);
if (this.addProcessToQueue(process, true)) {
this.addProcessToQueue(process, false);
usedInvSlots.add(slot);
// update = true;
}
}
}
}
}
if (worldObj.getTotalWorldTime() % 8 == 0) {
BlockPos outputPos = this.getBlockPosForPos(2).offset(facing, -1);
TileEntity outputTile = this.worldObj.getTileEntity(outputPos);
if (outputTile != null)
for (int j = 16; j < 22; j++) if (inventory[j] != null) {
ItemStack stack = Utils.copyStackWithAmount(inventory[j], 1);
stack = Utils.insertStackIntoInventory(outputTile, stack, facing.getOpposite());
if (stack == null)
if ((--this.inventory[j].stackSize) <= 0)
this.inventory[j] = null;
}
outputPos = this.getBlockPosForPos(22).offset(facing);
outputTile = this.worldObj.getTileEntity(outputPos);
if (outputTile != null)
if (inventory[22] != null) {
int out = Math.min(inventory[22].stackSize, 16);
ItemStack stack = Utils.copyStackWithAmount(inventory[22], out);
stack = Utils.insertStackIntoInventory(outputTile, stack, facing);
if (stack != null)
out -= stack.stackSize;
if ((this.inventory[22].stackSize -= out) <= 0)
this.inventory[22] = null;
}
}
}
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntityArcFurnace method doProcessOutput.
@Override
public void doProcessOutput(ItemStack output) {
BlockPos pos = getPos().add(0, -1, 0).offset(facing, -2);
TileEntity inventoryTile = this.worldObj.getTileEntity(pos);
if (inventoryTile != null)
output = Utils.insertStackIntoInventory(inventoryTile, output, facing.getOpposite());
if (output != null)
Utils.dropStackAtPos(worldObj, pos, output, facing);
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class BlockConnector method onBlockPlaced.
@Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
IBlockState ret = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer);
if (meta == BlockTypes_Connector.TRANSFORMER.getMeta()) {
BlockPos pos2 = pos.offset(facing, -1);
IBlockState placedAgainst = world.getBlockState(pos2);
Block block = placedAgainst.getBlock();
if (block instanceof IPostBlock && ((IPostBlock) block).canConnectTransformer(world, pos2))
ret = ret.withProperty(IEProperties.BOOLEANS[1], true);
TileEntity tile = world.getTileEntity(pos2);
if (tile instanceof IPostBlock && ((IPostBlock) tile).canConnectTransformer(world, pos2))
ret = ret.withProperty(IEProperties.BOOLEANS[1], true);
}
return ret;
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntitySilo method disassemble.
@Override
public void disassemble() {
super.invalidate();
if (formed && !worldObj.isRemote) {
BlockPos startPos = this.getPos().add(-offset[0], -offset[1], -offset[2]);
if (!(offset[0] == 0 && offset[1] == 0 && offset[2] == 0) && !(worldObj.getTileEntity(startPos) instanceof TileEntitySilo))
return;
for (int yy = 0; yy <= 6; yy++) for (int xx = -1; xx <= 1; xx++) for (int zz = -1; zz <= 1; zz++) {
ItemStack s = null;
TileEntity te = worldObj.getTileEntity(startPos.add(xx, yy, zz));
if (te instanceof TileEntitySilo) {
s = ((TileEntitySilo) te).getOriginalBlock();
((TileEntitySilo) te).formed = false;
}
if (startPos.add(xx, yy, zz).equals(getPos()))
s = this.getOriginalBlock();
if (s != null && Block.getBlockFromItem(s.getItem()) != null) {
if (startPos.add(xx, yy, zz).equals(getPos()))
worldObj.spawnEntityInWorld(new EntityItem(worldObj, getPos().getX() + .5, getPos().getY() + .5, getPos().getZ() + .5, s));
else {
if (Block.getBlockFromItem(s.getItem()) == IEContent.blockMetalMultiblock)
worldObj.setBlockToAir(startPos.add(xx, yy, zz));
worldObj.setBlockState(startPos.add(xx, yy, zz), Block.getBlockFromItem(s.getItem()).getStateFromMeta(s.getItemDamage()));
}
}
}
}
}
use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.
the class TileEntitySqueezer method doProcessOutput.
@Override
public void doProcessOutput(ItemStack output) {
BlockPos pos = getPos().offset(facing, 2);
TileEntity inventoryTile = this.worldObj.getTileEntity(pos);
if (inventoryTile != null)
output = Utils.insertStackIntoInventory(inventoryTile, output, facing.getOpposite());
if (output != null)
Utils.dropStackAtPos(worldObj, pos, output, facing);
}
Aggregations