mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
Merge pull request #1689 from MatthiasMann/sagmill_grindingball
simplify grinding ball synchronization and fix wrong display (issue #1673)...
This commit is contained in:
commit
9d0450219e
1 file changed
+19
-16
@@ -16,7 +16,7 @@ public class TileCrusher extends AbstractPoweredTaskEntity {
|
||||
|
||||
protected IGrindingMultiplier gb;
|
||||
protected int currGbUse = 0;
|
||||
protected int maxGbUse = 0; // client only
|
||||
protected int maxGbUse = 0;
|
||||
|
||||
protected int lastSendGbScaled = 0;
|
||||
private boolean useGrindingBall;
|
||||
@@ -44,40 +44,42 @@ public class TileCrusher extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
|
||||
public int getBallDurationScaled(int scale) {
|
||||
if(gb == null) {
|
||||
return worldObj.isRemote ? calcScaled(currGbUse, maxGbUse, scale) : 0;
|
||||
}
|
||||
return calcScaled(currGbUse, gb.getDurationMJ(), scale);
|
||||
}
|
||||
|
||||
private int calcScaled(float cur, float max, int scale) {
|
||||
return max == 0 ? 0 : (int) (scale * (1 - ((float) cur / (float) max)));
|
||||
return (maxGbUse > 0) ? (int) (scale * (1 - ((float) currGbUse / (float) maxGbUse))) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double usePower() {
|
||||
double res = super.usePower();
|
||||
boolean sendGB = false;
|
||||
|
||||
if(gb != null && useGrindingBall) {
|
||||
currGbUse += res;
|
||||
|
||||
int newScaled = getBallDurationScaled(16);
|
||||
if(newScaled != lastSendGbScaled) {
|
||||
PacketHandler.sendToAllAround(new PacketGrindingBall(this), this);
|
||||
lastSendGbScaled = newScaled;
|
||||
}
|
||||
|
||||
if(currGbUse > gb.getDurationMJ()) {
|
||||
if(currGbUse >= gb.getDurationMJ()) {
|
||||
currGbUse = 0;
|
||||
maxGbUse = 0;
|
||||
gb = null;
|
||||
sendGB = true;
|
||||
} else {
|
||||
int newScaled = getBallDurationScaled(16);
|
||||
if(newScaled != lastSendGbScaled) {
|
||||
sendGB = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(gb == null) {
|
||||
gb = CrusherRecipeManager.getInstance().getGrindballFromStack(inventory[1]);
|
||||
if(gb != null) {
|
||||
maxGbUse = gb.getDurationMJ();
|
||||
decrStackSize(1, 1);
|
||||
markDirty();
|
||||
sendGB = false; // the tile update will also sync the grinding ball
|
||||
}
|
||||
}
|
||||
if(sendGB) {
|
||||
PacketHandler.sendToAllAround(new PacketGrindingBall(this), this);
|
||||
lastSendGbScaled = getBallDurationScaled(16);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -124,6 +126,7 @@ public class TileCrusher extends AbstractPoweredTaskEntity {
|
||||
super.readCustomNBT(nbtRoot);
|
||||
gb = GrindingMultiplierNBT.readFromNBT(nbtRoot);
|
||||
currGbUse = nbtRoot.getInteger("currGbUse");
|
||||
maxGbUse = (gb != null) ? gb.getDurationMJ() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user