use of blusunrize.immersiveengineering.api.tool.BelljarHandler.FluidFertilizerHandler in project ImmersiveEngineering by BluSunrize.
the class TileEntityBelljar method update.
@Override
public void update() {
if (dummy != 0 || worldObj.isBlockIndirectlyGettingPowered(getPos()) > 0)
return;
if (getWorld().isRemote) {
if (energyStorage.getEnergyStored() > IEConfig.Machines.belljar_consumption && fertilizerAmount > 0 && renderActive) {
IPlantHandler handler = getCurrentPlantHandler();
if (handler != null && handler.isCorrectSoil(inventory[1], inventory[0]) && fertilizerAmount > 0) {
if (renderGrowth < 1) {
renderGrowth += handler.getGrowthStep(inventory[1], inventory[0], renderGrowth, this, fertilizerMod, true);
fertilizerAmount--;
} else
renderGrowth = handler.resetGrowth(inventory[1], inventory[0], renderGrowth, this, true);
if (getWorld().rand.nextInt(8) == 0) {
double partX = getPos().getX() + .5;
double partY = getPos().getY() + 2.6875;
double partZ = getPos().getZ() + .5;
ImmersiveEngineering.proxy.spawnRedstoneFX(getWorld(), partX, partY, partZ, .25, .25, .25, 1f, .55f, .1f, .1f);
}
}
}
} else {
if (inventory[1] != null) {
IPlantHandler handler = getCurrentPlantHandler();
if (handler != null && handler.isCorrectSoil(inventory[1], inventory[0]) && fertilizerAmount > 0 && energyStorage.extractEnergy(IEConfig.Machines.belljar_consumption, true) == IEConfig.Machines.belljar_consumption) {
boolean consume = false;
if (growth >= 1) {
ItemStack[] outputs = handler.getOutput(inventory[1], inventory[0], this);
int canFit = 0;
for (int i = 0; i < outputs.length; i++) if (outputs[i] != null)
for (int j = 3; j < 7; j++) if (inventory[j] == null || (ItemHandlerHelper.canItemStacksStack(inventory[j], outputs[i]) && inventory[j].stackSize + outputs[i].stackSize <= inventory[j].getMaxStackSize()))
canFit++;
if (canFit >= outputs.length) {
for (ItemStack output : outputs) for (int j = 3; j < 7; j++) {
if (inventory[j] == null) {
inventory[j] = output.copy();
break;
} else if (ItemHandlerHelper.canItemStacksStack(inventory[j], output) && inventory[j].stackSize + output.stackSize <= inventory[j].getMaxStackSize()) {
inventory[j].stackSize += output.stackSize;
break;
}
}
growth = handler.resetGrowth(inventory[1], inventory[0], growth, this, false);
consume = true;
}
} else if (growth < 1) {
growth += handler.getGrowthStep(inventory[1], inventory[0], growth, this, fertilizerMod, false);
consume = true;
if (worldObj.getTotalWorldTime() % 32 == ((getPos().getX() ^ getPos().getZ()) & 31))
sendSyncPacket(0);
}
if (consume) {
energyStorage.extractEnergy(IEConfig.Machines.belljar_consumption, false);
fertilizerAmount--;
if (!renderActive) {
renderActive = true;
sendSyncPacket(0);
}
} else if (renderActive) {
renderActive = false;
sendSyncPacket(0);
}
} else
growth = 0;
if (fertilizerAmount <= 0 && tank.getFluidAmount() >= IEConfig.Machines.belljar_fluid) {
FluidFertilizerHandler fluidFert = BelljarHandler.getFluidFertilizerHandler(tank.getFluid());
if (fluidFert != null) {
fertilizerMod = fluidFert.getGrowthMultiplier(tank.getFluid(), inventory[1], inventory[0], this);
tank.drain(IEConfig.Machines.belljar_fluid, true);
if (inventory[2] != null) {
ItemFertilizerHandler itemFert = BelljarHandler.getItemFertilizerHandler(inventory[2]);
if (itemFert != null)
fertilizerMod *= itemFert.getGrowthMultiplier(inventory[2], inventory[1], inventory[0], this);
inventory[2].stackSize--;
if (inventory[2].stackSize <= 0)
inventory[2] = null;
}
fertilizerAmount = IEConfig.Machines.belljar_fertilizer;
sendSyncPacket(1);
}
}
} else
growth = 0;
if (worldObj.getTotalWorldTime() % 8 == 0) {
BlockPos outputPos = getPos().up().offset(facing.getOpposite());
TileEntity outputTile = this.worldObj.getTileEntity(outputPos);
if (outputTile != null)
for (int j = 3; j < 7; j++) if (inventory[j] != null) {
int out = Math.min(inventory[j].stackSize, 16);
ItemStack stack = Utils.copyStackWithAmount(inventory[j], out);
stack = Utils.insertStackIntoInventory(outputTile, stack, facing);
if (stack != null)
out -= stack.stackSize;
if ((this.inventory[j].stackSize -= out) <= 0)
this.inventory[j] = null;
}
}
}
}
Aggregations