Ensure we clamp the miner's min and max height to the level on placement
@@ -313,12 +313,13 @@ public class TileEntityDigitalMiner extends TileEntityMekanism implements ISusta
}
private void setSilkTouch(boolean newSilkTouch) {
- boolean changed = silkTouch != newSilkTouch;
+ if (silkTouch != newSilkTouch) {
silkTouch = newSilkTouch;
- if (changed && (hasLevel() && !isRemote())) {
+ if (hasLevel() && !isRemote()) {
energyContainer.updateMinerEnergyPerTick();
}
}
+ }
public void toggleSilkTouch() {
setSilkTouch(!getSilkTouch());
@@ -361,14 +362,15 @@ public class TileEntityDigitalMiner extends TileEntityMekanism implements ISusta
}
private void setRadius(int newRadius) {
- boolean changed = radius != newRadius;
+ if (radius != newRadius) {
radius = newRadius;
- if (changed && (hasLevel() && !isRemote())) {
+ if (hasLevel() && !isRemote()) {
energyContainer.updateMinerEnergyPerTick();
// If the radius changed, and we're on the server, go ahead and refresh the chunk set
getChunkLoader().refreshChunkTickets();
}
}
+ }
public void setMinYFromPacket(int newMinY) {
if (level != null) {
@@ -381,12 +383,13 @@ public class TileEntityDigitalMiner extends TileEntityMekanism implements ISusta
}
private void setMinY(int newMinY) {
- boolean changed = minY != newMinY;
+ if (minY != newMinY) {
minY = newMinY;
- if (changed && (hasLevel() && !isRemote())) {
+ if (hasLevel() && !isRemote()) {
energyContainer.updateMinerEnergyPerTick();
}
}
+ }
public void setMaxYFromPacket(int newMaxY) {
if (level != null) {
@@ -399,12 +402,13 @@ public class TileEntityDigitalMiner extends TileEntityMekanism implements ISusta
}
private void setMaxY(int newMaxY) {
- boolean changed = maxY != newMaxY;
+ if (maxY != newMaxY) {
maxY = newMaxY;
- if (changed && (hasLevel() && !isRemote())) {
+ if (hasLevel() && !isRemote()) {
energyContainer.updateMinerEnergyPerTick();
}
}
+ }
@Override
public void moveUp(int filterIndex) {
@@ -899,8 +903,20 @@ public class TileEntityDigitalMiner extends TileEntityMekanism implements ISusta
@Override
public void readSustainedData(CompoundTag dataMap) {
setRadius(Math.min(dataMap.getInt(NBTConstants.RADIUS), MekanismConfig.general.minerMaxRadius.get()));
- NBTUtils.setIntIfPresent(dataMap, NBTConstants.MIN, this::setMinY);
- NBTUtils.setIntIfPresent(dataMap, NBTConstants.MAX, this::setMaxY);
+ NBTUtils.setIntIfPresent(dataMap, NBTConstants.MIN, newMinY -> {
+ if (hasLevel() && !isRemote()) {
+ setMinY(Math.max(newMinY, level.getMinBuildHeight()));
+ } else {
+ setMinY(newMinY);
+ }
+ });
+ NBTUtils.setIntIfPresent(dataMap, NBTConstants.MAX, newMaxY -> {
+ if (hasLevel() && !isRemote()) {
+ setMaxY(Math.min(newMaxY, level.getMaxBuildHeight() - 1));
+ } else {
+ setMaxY(newMaxY);
+ }
+ });
NBTUtils.setBooleanIfPresent(dataMap, NBTConstants.EJECT, eject -> doEject = eject);
NBTUtils.setBooleanIfPresent(dataMap, NBTConstants.PULL, pull -> doPull = pull);
NBTUtils.setBooleanIfPresent(dataMap, NBTConstants.SILK_TOUCH, this::setSilkTouch);
