Update Flow code from MC (with names!)
I don't see anything that can account for the lag though.
This commit is contained in:
parent
2a46bf1954
commit
a1da3627ea
1 changed files with 77 additions and 63 deletions
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package buildcraft.energy;
|
||||
|
||||
import java.util.Random;
|
||||
|
@ -50,69 +48,81 @@ public class BlockOilFlowing extends BlockFluid implements ILiquid {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, int i, int j, int k, Random random) {
|
||||
int l = getFlowDecay(world, i, j, k);
|
||||
byte byte0 = 1;
|
||||
boolean flag = true;
|
||||
if (l > 0) {
|
||||
int i1 = -100;
|
||||
numAdjacentSources = 0;
|
||||
i1 = getSmallestFlowDecay(world, i - 1, j, k, i1);
|
||||
i1 = getSmallestFlowDecay(world, i + 1, j, k, i1);
|
||||
i1 = getSmallestFlowDecay(world, i, j, k - 1, i1);
|
||||
i1 = getSmallestFlowDecay(world, i, j, k + 1, i1);
|
||||
int j1 = i1 + byte0;
|
||||
if (j1 >= 8 || i1 < 0) {
|
||||
j1 = -1;
|
||||
public void updateTick(World world, int x, int y, int z, Random random) {
|
||||
int oldDecay = this.getFlowDecay(world, x, y, z);
|
||||
byte increment = 1;
|
||||
int flowDecay;
|
||||
|
||||
if (oldDecay > 0) {
|
||||
this.numAdjacentSources = 0;
|
||||
int minFlowDecay = this.getSmallestFlowDecay(world, x - 1, y, z, -100);
|
||||
minFlowDecay = this.getSmallestFlowDecay(world, x + 1, y, z, minFlowDecay);
|
||||
minFlowDecay = this.getSmallestFlowDecay(world, x, y, z - 1, minFlowDecay);
|
||||
minFlowDecay = this.getSmallestFlowDecay(world, x, y, z + 1, minFlowDecay);
|
||||
flowDecay = minFlowDecay + increment;
|
||||
|
||||
if (flowDecay >= 8 || minFlowDecay < 0) {
|
||||
flowDecay = -1;
|
||||
}
|
||||
if (getFlowDecay(world, i, j + 1, k) >= 0) {
|
||||
int l1 = getFlowDecay(world, i, j + 1, k);
|
||||
if (l1 >= 8) {
|
||||
j1 = l1;
|
||||
|
||||
int decayAbove = getFlowDecay(world, x, y + 1, z);
|
||||
if (decayAbove >= 0) {
|
||||
if (decayAbove >= 8) {
|
||||
flowDecay = decayAbove;
|
||||
} else {
|
||||
j1 = l1 + 8;
|
||||
flowDecay = decayAbove + 8;
|
||||
}
|
||||
}
|
||||
if (j1 != l) {
|
||||
l = j1;
|
||||
if (l < 0) {
|
||||
world.setBlock(i, j, k, 0);
|
||||
|
||||
if (flowDecay == oldDecay) {
|
||||
this.updateFlow(world, x, y, z);
|
||||
} else {
|
||||
oldDecay = flowDecay;
|
||||
|
||||
if (flowDecay < 0) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
} else {
|
||||
world.setBlockMetadataWithNotify(i, j, k, l,1);
|
||||
world.scheduleBlockUpdate(i, j, k, blockID, tickRate(world));
|
||||
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
|
||||
world.setBlockMetadataWithNotify(x, y, z, flowDecay, 2);
|
||||
world.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate(world));
|
||||
world.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
|
||||
}
|
||||
} else if (flag) {
|
||||
updateFlow(world, i, j, k);
|
||||
}
|
||||
} else {
|
||||
updateFlow(world, i, j, k);
|
||||
this.updateFlow(world, x, y, z);
|
||||
}
|
||||
if (liquidCanDisplaceBlock(world, i, j - 1, k)) {
|
||||
if (l >= 8) {
|
||||
world.setBlock(i, j - 1, k, blockID, l,1);
|
||||
|
||||
if (this.liquidCanDisplaceBlock(world, x, y - 1, z)) {
|
||||
if (oldDecay >= 8) {
|
||||
this.flowIntoBlock(world, x, y - 1, z, oldDecay);
|
||||
} else {
|
||||
world.setBlock(i, j - 1, k, blockID, l + 8,1);
|
||||
this.flowIntoBlock(world, x, y - 1, z, oldDecay + 8);
|
||||
}
|
||||
} else if (l >= 0 && (l == 0 || blockBlocksFlow(world, i, j - 1, k))) {
|
||||
boolean aflag[] = getOptimalFlowDirections(world, i, j, k);
|
||||
int k1 = l + byte0;
|
||||
if (l >= 8) {
|
||||
k1 = 1;
|
||||
} else if (oldDecay >= 0 && (oldDecay == 0 || this.blockBlocksFlow(world, x, y - 1, z))) {
|
||||
boolean[] flowDirection = this.getOptimalFlowDirections(world, x, y, z);
|
||||
flowDecay = oldDecay + increment;
|
||||
|
||||
if (oldDecay >= 8) {
|
||||
flowDecay = 1;
|
||||
}
|
||||
if (k1 >= 8)
|
||||
|
||||
if (flowDecay >= 8) {
|
||||
return;
|
||||
if (aflag[0]) {
|
||||
flowIntoBlock(world, i - 1, j, k, k1);
|
||||
}
|
||||
if (aflag[1]) {
|
||||
flowIntoBlock(world, i + 1, j, k, k1);
|
||||
|
||||
if (flowDirection[0]) {
|
||||
this.flowIntoBlock(world, x - 1, y, z, flowDecay);
|
||||
}
|
||||
if (aflag[2]) {
|
||||
flowIntoBlock(world, i, j, k - 1, k1);
|
||||
|
||||
if (flowDirection[1]) {
|
||||
this.flowIntoBlock(world, x + 1, y, z, flowDecay);
|
||||
}
|
||||
if (aflag[3]) {
|
||||
flowIntoBlock(world, i, j, k + 1, k1);
|
||||
|
||||
if (flowDirection[2]) {
|
||||
this.flowIntoBlock(world, x, y, z - 1, flowDecay);
|
||||
}
|
||||
|
||||
if (flowDirection[3]) {
|
||||
this.flowIntoBlock(world, x, y, z + 1, flowDecay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +133,7 @@ public class BlockOilFlowing extends BlockFluid implements ILiquid {
|
|||
if (i1 > 0) {
|
||||
Block.blocksList[i1].dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0);
|
||||
}
|
||||
world.setBlock(i, j, k, blockID, l,1);
|
||||
world.setBlock(i, j, k, blockID, l, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,8 +161,9 @@ public class BlockOilFlowing extends BlockFluid implements ILiquid {
|
|||
if (blockBlocksFlow(world, l1, i2, j2) || world.getBlockMaterial(l1, i2, j2) == blockMaterial && world.getBlockMetadata(l1, i2, j2) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (!blockBlocksFlow(world, l1, i2 - 1, j2))
|
||||
if (!blockBlocksFlow(world, l1, i2 - 1, j2)) {
|
||||
return l;
|
||||
}
|
||||
if (l >= 4) {
|
||||
continue;
|
||||
}
|
||||
|
@ -209,18 +220,21 @@ public class BlockOilFlowing extends BlockFluid implements ILiquid {
|
|||
|
||||
private boolean blockBlocksFlow(World world, int i, int j, int k) {
|
||||
int l = world.getBlockId(i, j, k);
|
||||
if (l == Block.doorWood.blockID || l == Block.doorIron.blockID || l == Block.signPost.blockID || l == Block.ladder.blockID || l == Block.reed.blockID)
|
||||
if (l == Block.doorWood.blockID || l == Block.doorIron.blockID || l == Block.signPost.blockID || l == Block.ladder.blockID || l == Block.reed.blockID) {
|
||||
return true;
|
||||
if (l == 0)
|
||||
}
|
||||
if (l == 0) {
|
||||
return false;
|
||||
}
|
||||
Material material = Block.blocksList[l].blockMaterial;
|
||||
return material.isSolid();
|
||||
}
|
||||
|
||||
protected int getSmallestFlowDecay(World world, int i, int j, int k, int l) {
|
||||
int i1 = getFlowDecay(world, i, j, k);
|
||||
if (i1 < 0)
|
||||
if (i1 < 0) {
|
||||
return l;
|
||||
}
|
||||
if (i1 >= 8) {
|
||||
i1 = 0;
|
||||
}
|
||||
|
@ -229,10 +243,11 @@ public class BlockOilFlowing extends BlockFluid implements ILiquid {
|
|||
|
||||
private boolean liquidCanDisplaceBlock(World world, int i, int j, int k) {
|
||||
Material material = world.getBlockMaterial(i, j, k);
|
||||
if (material == blockMaterial)
|
||||
if (material == blockMaterial) {
|
||||
return false;
|
||||
else
|
||||
} else {
|
||||
return !blockBlocksFlow(world, i, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -264,9 +279,8 @@ public class BlockOilFlowing extends BlockFluid implements ILiquid {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IconRegister iconRegister){
|
||||
this.theIcon = new Icon[] {iconRegister.registerIcon("buildcraft:oil"), iconRegister.registerIcon("buildcraft:oil_flow")};
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IconRegister iconRegister) {
|
||||
this.theIcon = new Icon[]{iconRegister.registerIcon("buildcraft:oil"), iconRegister.registerIcon("buildcraft:oil_flow")};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue