add configurable quarry chunkloading
This commit is contained in:
parent
47a09b3a2a
commit
016109efcf
2 changed files with 59 additions and 48 deletions
|
@ -85,6 +85,7 @@ public class BuildCraftFactory extends BuildCraftMod {
|
|||
public static BlockRefinery refineryBlock;
|
||||
public static BlockHopper hopperBlock;
|
||||
|
||||
public static boolean quarryLoadsChunks = true;
|
||||
public static boolean allowMining = true;
|
||||
public static boolean quarryOneTimeUse = false;
|
||||
public static float miningMultiplier = 1;
|
||||
|
@ -94,8 +95,10 @@ public class BuildCraftFactory extends BuildCraftMod {
|
|||
@Mod.EventHandler
|
||||
public void postInit(FMLPostInitializationEvent evt) {
|
||||
FactoryProxy.proxy.initializeNEIIntegration();
|
||||
if (quarryLoadsChunks) {
|
||||
ForgeChunkManager.setForcedChunkLoadingCallback(instance, new QuarryChunkloadCallback());
|
||||
}
|
||||
}
|
||||
|
||||
public class QuarryChunkloadCallback implements ForgeChunkManager.OrderedLoadingCallback {
|
||||
|
||||
|
@ -105,9 +108,14 @@ public class BuildCraftFactory extends BuildCraftMod {
|
|||
int quarryX = ticket.getModData().getInteger("quarryX");
|
||||
int quarryY = ticket.getModData().getInteger("quarryY");
|
||||
int quarryZ = ticket.getModData().getInteger("quarryZ");
|
||||
|
||||
if (world.blockExists(quarryX, quarryY, quarryZ)) {
|
||||
Block block = world.getBlock(quarryX, quarryY, quarryZ);
|
||||
if (block == quarryBlock) {
|
||||
TileQuarry tq = (TileQuarry) world.getTileEntity(quarryX, quarryY, quarryZ);
|
||||
tq.forceChunkLoading(ticket);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,11 +127,13 @@ public class BuildCraftFactory extends BuildCraftMod {
|
|||
int quarryY = ticket.getModData().getInteger("quarryY");
|
||||
int quarryZ = ticket.getModData().getInteger("quarryZ");
|
||||
|
||||
if (world.blockExists(quarryX, quarryY, quarryZ)) {
|
||||
Block block = world.getBlock(quarryX, quarryY, quarryZ);
|
||||
if (block == quarryBlock) {
|
||||
validTickets.add(ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
return validTickets;
|
||||
}
|
||||
}
|
||||
|
@ -166,6 +176,7 @@ public class BuildCraftFactory extends BuildCraftMod {
|
|||
quarryOneTimeUse = genCat.get("quarry.one.time.use", false, "Quarry cannot be picked back up after placement");
|
||||
miningMultiplier = genCat.get("mining.cost.multipler", 1F, 1F, 10F, "cost multiplier for mining operations, range (1.0 - 10.0)\nhigh values may render engines incapable of powering machines directly");
|
||||
miningDepth = genCat.get("mining.depth", 2, 256, 256, "how far below the machine can mining machines dig, range (2 - 256), default 256");
|
||||
quarryLoadsChunks = genCat.get("quarry.loads.chunks", true, "Quarry loads chunks required for mining");
|
||||
|
||||
Property pumpList = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "pumping.controlList", DefaultProps.PUMP_DIMENSION_LIST);
|
||||
pumpList.comment = "Allows admins to whitelist or blacklist pumping of specific fluids in specific dimensions.\n"
|
||||
|
|
|
@ -66,7 +66,6 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
private double headPosX, headPosY, headPosZ;
|
||||
private double speed = 0.03;
|
||||
private Stage stage = Stage.BUILDING;
|
||||
private boolean isAlive;
|
||||
private boolean movingHorizontally;
|
||||
private boolean movingVertically;
|
||||
private double headTrajectory;
|
||||
|
@ -134,6 +133,18 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
this.arm = arm;
|
||||
}
|
||||
|
||||
public boolean areChunksLoaded() {
|
||||
if (BuildCraftFactory.quarryLoadsChunks) {
|
||||
// Small optimization
|
||||
return true;
|
||||
}
|
||||
|
||||
// Each chunk covers the full height, so we only check one of them per height.
|
||||
return worldObj.blockExists(box.xMin, box.yMax, box.zMin)
|
||||
&& worldObj.blockExists(box.xMax, box.yMax, box.zMin)
|
||||
&& worldObj.blockExists(box.xMin, box.yMax, box.zMax)
|
||||
&& worldObj.blockExists(box.xMax, box.yMax, box.zMax);
|
||||
}
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
@ -146,11 +157,11 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
return;
|
||||
}
|
||||
|
||||
if (!isAlive) {
|
||||
if (stage == Stage.DONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stage == Stage.DONE) {
|
||||
if (!areChunksLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -453,7 +464,9 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
if (chunkTicket != null) {
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
}
|
||||
|
||||
super.invalidate();
|
||||
destroy();
|
||||
|
@ -487,25 +500,15 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
private void setBoundaries(boolean useDefaultI) {
|
||||
boolean useDefault = useDefaultI;
|
||||
|
||||
if (chunkTicket == null) {
|
||||
if (BuildCraftFactory.quarryLoadsChunks && chunkTicket == null) {
|
||||
chunkTicket = ForgeChunkManager.requestTicket(BuildCraftFactory.instance, worldObj, Type.NORMAL);
|
||||
}
|
||||
if (chunkTicket == null) {
|
||||
isAlive = false;
|
||||
|
||||
if (placedBy != null && !worldObj.isRemote) {
|
||||
placedBy.addChatMessage(new ChatComponentText(
|
||||
String.format(
|
||||
"[BUILDCRAFT] The quarry at %d, %d, %d will not work because there are no more chunkloaders available",
|
||||
xCoord, yCoord, zCoord)));
|
||||
}
|
||||
sendNetworkUpdate();
|
||||
return;
|
||||
}
|
||||
if (chunkTicket != null) {
|
||||
chunkTicket.getModData().setInteger("quarryX", xCoord);
|
||||
chunkTicket.getModData().setInteger("quarryY", yCoord);
|
||||
chunkTicket.getModData().setInteger("quarryZ", zCoord);
|
||||
ForgeChunkManager.forceChunk(chunkTicket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
|
||||
}
|
||||
|
||||
IAreaProvider a = null;
|
||||
|
||||
|
@ -522,6 +525,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
int xSize = a.xMax() - a.xMin() + 1;
|
||||
int zSize = a.zMax() - a.zMin() + 1;
|
||||
|
||||
if (chunkTicket != null) {
|
||||
if (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth()) {
|
||||
if (placedBy != null) {
|
||||
placedBy.addChatMessage(new ChatComponentText(
|
||||
|
@ -534,6 +538,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);
|
||||
useDefault = true;
|
||||
}
|
||||
}
|
||||
|
||||
xSize = a.xMax() - a.xMin() + 1;
|
||||
int ySize = a.yMax() - a.yMin() + 1;
|
||||
|
@ -575,9 +580,13 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
}
|
||||
|
||||
a.removeFromWorld();
|
||||
if (chunkTicket != null) {
|
||||
forceChunkLoading(chunkTicket);
|
||||
}
|
||||
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
private void initializeBlueprintBuilder() {
|
||||
Blueprint bpt = ((FillerPattern) FillerManager.registry.getPattern("buildcraft:frame"))
|
||||
.getBlueprint(box, worldObj, BuildCraftFactory.frameBlock, 0);
|
||||
|
@ -599,7 +608,6 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
stream.writeFloat((float) speed);
|
||||
stream.writeFloat((float) headTrajectory);
|
||||
int flags = stage.ordinal();
|
||||
flags |= isAlive ? 0x08 : 0;
|
||||
flags |= movingHorizontally ? 0x10 : 0;
|
||||
flags |= movingVertically ? 0x20 : 0;
|
||||
stream.writeByte(flags);
|
||||
|
@ -619,16 +627,11 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
headTrajectory = stream.readFloat();
|
||||
int flags = stream.readUnsignedByte();
|
||||
stage = Stage.values()[flags & 0x07];
|
||||
isAlive = (flags & 0x08) != 0;
|
||||
movingHorizontally = (flags & 0x10) != 0;
|
||||
movingVertically = (flags & 0x20) != 0;
|
||||
|
||||
if (isAlive) {
|
||||
createUtilsIfNeeded();
|
||||
} else {
|
||||
box.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (arm != null) {
|
||||
arm.setHead(headPosX, headPosY, headPosZ);
|
||||
arm.updatePosition();
|
||||
|
@ -802,7 +805,6 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
}
|
||||
|
||||
Set<ChunkCoordIntPair> chunks = Sets.newHashSet();
|
||||
isAlive = true;
|
||||
ChunkCoordIntPair quarryChunk = new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4);
|
||||
chunks.add(quarryChunk);
|
||||
ForgeChunkManager.forceChunk(ticket, quarryChunk);
|
||||
|
@ -821,8 +823,6 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
|||
"[BUILDCRAFT] The quarry at %d %d %d will keep %d chunks loaded",
|
||||
xCoord, yCoord, zCoord, chunks.size())));
|
||||
}
|
||||
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue