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 BlockRefinery refineryBlock;
|
||||||
public static BlockHopper hopperBlock;
|
public static BlockHopper hopperBlock;
|
||||||
|
|
||||||
|
public static boolean quarryLoadsChunks = true;
|
||||||
public static boolean allowMining = true;
|
public static boolean allowMining = true;
|
||||||
public static boolean quarryOneTimeUse = false;
|
public static boolean quarryOneTimeUse = false;
|
||||||
public static float miningMultiplier = 1;
|
public static float miningMultiplier = 1;
|
||||||
|
@ -94,8 +95,10 @@ public class BuildCraftFactory extends BuildCraftMod {
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void postInit(FMLPostInitializationEvent evt) {
|
public void postInit(FMLPostInitializationEvent evt) {
|
||||||
FactoryProxy.proxy.initializeNEIIntegration();
|
FactoryProxy.proxy.initializeNEIIntegration();
|
||||||
|
if (quarryLoadsChunks) {
|
||||||
ForgeChunkManager.setForcedChunkLoadingCallback(instance, new QuarryChunkloadCallback());
|
ForgeChunkManager.setForcedChunkLoadingCallback(instance, new QuarryChunkloadCallback());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class QuarryChunkloadCallback implements ForgeChunkManager.OrderedLoadingCallback {
|
public class QuarryChunkloadCallback implements ForgeChunkManager.OrderedLoadingCallback {
|
||||||
|
|
||||||
|
@ -105,9 +108,14 @@ public class BuildCraftFactory extends BuildCraftMod {
|
||||||
int quarryX = ticket.getModData().getInteger("quarryX");
|
int quarryX = ticket.getModData().getInteger("quarryX");
|
||||||
int quarryY = ticket.getModData().getInteger("quarryY");
|
int quarryY = ticket.getModData().getInteger("quarryY");
|
||||||
int quarryZ = ticket.getModData().getInteger("quarryZ");
|
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);
|
TileQuarry tq = (TileQuarry) world.getTileEntity(quarryX, quarryY, quarryZ);
|
||||||
tq.forceChunkLoading(ticket);
|
tq.forceChunkLoading(ticket);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,11 +127,13 @@ public class BuildCraftFactory extends BuildCraftMod {
|
||||||
int quarryY = ticket.getModData().getInteger("quarryY");
|
int quarryY = ticket.getModData().getInteger("quarryY");
|
||||||
int quarryZ = ticket.getModData().getInteger("quarryZ");
|
int quarryZ = ticket.getModData().getInteger("quarryZ");
|
||||||
|
|
||||||
|
if (world.blockExists(quarryX, quarryY, quarryZ)) {
|
||||||
Block block = world.getBlock(quarryX, quarryY, quarryZ);
|
Block block = world.getBlock(quarryX, quarryY, quarryZ);
|
||||||
if (block == quarryBlock) {
|
if (block == quarryBlock) {
|
||||||
validTickets.add(ticket);
|
validTickets.add(ticket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return validTickets;
|
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");
|
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");
|
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");
|
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);
|
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"
|
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 headPosX, headPosY, headPosZ;
|
||||||
private double speed = 0.03;
|
private double speed = 0.03;
|
||||||
private Stage stage = Stage.BUILDING;
|
private Stage stage = Stage.BUILDING;
|
||||||
private boolean isAlive;
|
|
||||||
private boolean movingHorizontally;
|
private boolean movingHorizontally;
|
||||||
private boolean movingVertically;
|
private boolean movingVertically;
|
||||||
private double headTrajectory;
|
private double headTrajectory;
|
||||||
|
@ -134,6 +133,18 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
this.arm = arm;
|
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
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
@ -146,11 +157,11 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAlive) {
|
if (stage == Stage.DONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stage == Stage.DONE) {
|
if (!areChunksLoaded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +464,9 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
|
if (chunkTicket != null) {
|
||||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||||
|
}
|
||||||
|
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
destroy();
|
destroy();
|
||||||
|
@ -487,25 +500,15 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
private void setBoundaries(boolean useDefaultI) {
|
private void setBoundaries(boolean useDefaultI) {
|
||||||
boolean useDefault = useDefaultI;
|
boolean useDefault = useDefaultI;
|
||||||
|
|
||||||
if (chunkTicket == null) {
|
if (BuildCraftFactory.quarryLoadsChunks && chunkTicket == null) {
|
||||||
chunkTicket = ForgeChunkManager.requestTicket(BuildCraftFactory.instance, worldObj, Type.NORMAL);
|
chunkTicket = ForgeChunkManager.requestTicket(BuildCraftFactory.instance, worldObj, Type.NORMAL);
|
||||||
}
|
}
|
||||||
if (chunkTicket == null) {
|
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;
|
|
||||||
}
|
|
||||||
chunkTicket.getModData().setInteger("quarryX", xCoord);
|
chunkTicket.getModData().setInteger("quarryX", xCoord);
|
||||||
chunkTicket.getModData().setInteger("quarryY", yCoord);
|
chunkTicket.getModData().setInteger("quarryY", yCoord);
|
||||||
chunkTicket.getModData().setInteger("quarryZ", zCoord);
|
chunkTicket.getModData().setInteger("quarryZ", zCoord);
|
||||||
ForgeChunkManager.forceChunk(chunkTicket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
|
ForgeChunkManager.forceChunk(chunkTicket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
|
||||||
|
}
|
||||||
|
|
||||||
IAreaProvider a = null;
|
IAreaProvider a = null;
|
||||||
|
|
||||||
|
@ -522,6 +525,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
int xSize = a.xMax() - a.xMin() + 1;
|
int xSize = a.xMax() - a.xMin() + 1;
|
||||||
int zSize = a.zMax() - a.zMin() + 1;
|
int zSize = a.zMax() - a.zMin() + 1;
|
||||||
|
|
||||||
|
if (chunkTicket != null) {
|
||||||
if (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth()) {
|
if (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth()) {
|
||||||
if (placedBy != null) {
|
if (placedBy != null) {
|
||||||
placedBy.addChatMessage(new ChatComponentText(
|
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);
|
a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);
|
||||||
useDefault = true;
|
useDefault = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
xSize = a.xMax() - a.xMin() + 1;
|
xSize = a.xMax() - a.xMin() + 1;
|
||||||
int ySize = a.yMax() - a.yMin() + 1;
|
int ySize = a.yMax() - a.yMin() + 1;
|
||||||
|
@ -575,9 +580,13 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
}
|
}
|
||||||
|
|
||||||
a.removeFromWorld();
|
a.removeFromWorld();
|
||||||
|
if (chunkTicket != null) {
|
||||||
forceChunkLoading(chunkTicket);
|
forceChunkLoading(chunkTicket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendNetworkUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeBlueprintBuilder() {
|
private void initializeBlueprintBuilder() {
|
||||||
Blueprint bpt = ((FillerPattern) FillerManager.registry.getPattern("buildcraft:frame"))
|
Blueprint bpt = ((FillerPattern) FillerManager.registry.getPattern("buildcraft:frame"))
|
||||||
.getBlueprint(box, worldObj, BuildCraftFactory.frameBlock, 0);
|
.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) speed);
|
||||||
stream.writeFloat((float) headTrajectory);
|
stream.writeFloat((float) headTrajectory);
|
||||||
int flags = stage.ordinal();
|
int flags = stage.ordinal();
|
||||||
flags |= isAlive ? 0x08 : 0;
|
|
||||||
flags |= movingHorizontally ? 0x10 : 0;
|
flags |= movingHorizontally ? 0x10 : 0;
|
||||||
flags |= movingVertically ? 0x20 : 0;
|
flags |= movingVertically ? 0x20 : 0;
|
||||||
stream.writeByte(flags);
|
stream.writeByte(flags);
|
||||||
|
@ -619,16 +627,11 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
headTrajectory = stream.readFloat();
|
headTrajectory = stream.readFloat();
|
||||||
int flags = stream.readUnsignedByte();
|
int flags = stream.readUnsignedByte();
|
||||||
stage = Stage.values()[flags & 0x07];
|
stage = Stage.values()[flags & 0x07];
|
||||||
isAlive = (flags & 0x08) != 0;
|
|
||||||
movingHorizontally = (flags & 0x10) != 0;
|
movingHorizontally = (flags & 0x10) != 0;
|
||||||
movingVertically = (flags & 0x20) != 0;
|
movingVertically = (flags & 0x20) != 0;
|
||||||
|
|
||||||
if (isAlive) {
|
|
||||||
createUtilsIfNeeded();
|
createUtilsIfNeeded();
|
||||||
} else {
|
|
||||||
box.reset();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (arm != null) {
|
if (arm != null) {
|
||||||
arm.setHead(headPosX, headPosY, headPosZ);
|
arm.setHead(headPosX, headPosY, headPosZ);
|
||||||
arm.updatePosition();
|
arm.updatePosition();
|
||||||
|
@ -802,7 +805,6 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ChunkCoordIntPair> chunks = Sets.newHashSet();
|
Set<ChunkCoordIntPair> chunks = Sets.newHashSet();
|
||||||
isAlive = true;
|
|
||||||
ChunkCoordIntPair quarryChunk = new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4);
|
ChunkCoordIntPair quarryChunk = new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4);
|
||||||
chunks.add(quarryChunk);
|
chunks.add(quarryChunk);
|
||||||
ForgeChunkManager.forceChunk(ticket, 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",
|
"[BUILDCRAFT] The quarry at %d %d %d will keep %d chunks loaded",
|
||||||
xCoord, yCoord, zCoord, chunks.size())));
|
xCoord, yCoord, zCoord, chunks.size())));
|
||||||
}
|
}
|
||||||
|
|
||||||
sendNetworkUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue