use of micdoodle8.mods.galacticraft.api.block.IOxygenReliantBlock in project Galacticraft by micdoodle8.
the class TileEntityOxygenDistributor method invalidate.
@Override
public void invalidate() {
if (!this.worldObj.isRemote) /* && this.oxygenBubble != null*/
{
int bubbleR = MathHelper.ceiling_double_int(bubbleSize);
int bubbleR2 = (int) (bubbleSize * bubbleSize);
final int xMin = this.getPos().getX() - bubbleR;
final int xMax = this.getPos().getX() + bubbleR;
final int yMin = this.getPos().getY() - bubbleR;
final int yMax = this.getPos().getY() + bubbleR;
final int zMin = this.getPos().getZ() - bubbleR;
final int zMax = this.getPos().getZ() + bubbleR;
for (int x = xMin; x < xMax; x++) {
for (int z = zMin; z < zMax; z++) {
// Doing y as the inner loop allows BlockVec3 to cache the chunks more efficiently
for (int y = yMin; y < yMax; y++) {
Block block = new BlockVec3(x, y, z).getBlockID(this.worldObj);
if (block instanceof IOxygenReliantBlock && this.getDistanceFromServer(x, y, z) <= bubbleR2) {
this.worldObj.scheduleUpdate(new BlockPos(x, y, z), block, 0);
}
}
}
}
// this.oxygenBubble.setDead();
TileEntityOxygenDistributor.loadedTiles.remove(new BlockVec3Dim(this));
}
super.invalidate();
}
use of micdoodle8.mods.galacticraft.api.block.IOxygenReliantBlock in project Galacticraft by micdoodle8.
the class TileEntityOxygenDistributor method update.
@Override
public void update() {
if (!this.worldObj.isRemote) {
ItemStack oxygenItemStack = this.getStackInSlot(1);
if (oxygenItemStack != null && oxygenItemStack.getItem() instanceof IItemOxygenSupply) {
IItemOxygenSupply oxygenItem = (IItemOxygenSupply) oxygenItemStack.getItem();
int oxygenDraw = (int) Math.floor(Math.min(this.oxygenPerTick * 2.5F, this.getMaxOxygenStored() - this.getOxygenStored()));
this.setOxygenStored(getOxygenStored() + oxygenItem.discharge(oxygenItemStack, oxygenDraw));
if (this.getOxygenStored() > this.getMaxOxygenStored()) {
this.setOxygenStored(this.getOxygenStored());
}
}
}
super.update();
if (!this.worldObj.isRemote) {
if (this.getEnergyStoredGC() > 0.0F && this.hasEnoughEnergyToRun && this.getOxygenStored() > this.oxygenPerTick) {
this.bubbleSize += 0.01F;
} else {
this.bubbleSize -= 0.1F;
}
this.bubbleSize = Math.min(Math.max(this.bubbleSize, 0.0F), 10.0F);
}
if (!this.worldObj.isRemote) /* && this.oxygenBubble != null*/
{
this.active = bubbleSize >= 1 && this.hasEnoughEnergyToRun && this.getOxygenStored() > this.oxygenPerTick;
if (this.ticks % (this.active ? 20 : 4) == 0) {
double size = bubbleSize;
int bubbleR = MathHelper.floor_double(size) + 4;
int bubbleR2 = (int) (size * size);
for (int x = this.getPos().getX() - bubbleR; x <= this.getPos().getX() + bubbleR; x++) {
for (int y = this.getPos().getY() - bubbleR; y <= this.getPos().getY() + bubbleR; y++) {
for (int z = this.getPos().getZ() - bubbleR; z <= this.getPos().getZ() + bubbleR; z++) {
BlockPos pos = new BlockPos(x, y, z);
IBlockState state = this.worldObj.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof IOxygenReliantBlock) {
if (this.getDistanceFromServer(x, y, z) <= bubbleR2) {
((IOxygenReliantBlock) block).onOxygenAdded(this.worldObj, pos, state);
} else {
// Do not necessarily extinguish it - it might be inside another oxygen system
this.worldObj.scheduleUpdate(pos, block, 0);
}
}
}
}
}
}
}
this.lastActive = this.active;
}
Aggregations