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,7 +95,9 @@ 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();
|
||||||
ForgeChunkManager.setForcedChunkLoadingCallback(instance, new QuarryChunkloadCallback());
|
if (quarryLoadsChunks) {
|
||||||
|
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");
|
||||||
TileQuarry tq = (TileQuarry) world.getTileEntity(quarryX, quarryY, quarryZ);
|
|
||||||
tq.forceChunkLoading(ticket);
|
|
||||||
|
|
||||||
|
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,9 +127,11 @@ 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");
|
||||||
|
|
||||||
Block block = world.getBlock(quarryX, quarryY, quarryZ);
|
if (world.blockExists(quarryX, quarryY, quarryZ)) {
|
||||||
if (block == quarryBlock) {
|
Block block = world.getBlock(quarryX, quarryY, quarryZ);
|
||||||
validTickets.add(ticket);
|
if (block == quarryBlock) {
|
||||||
|
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() {
|
||||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
if (chunkTicket != null) {
|
||||||
|
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;
|
chunkTicket.getModData().setInteger("quarryX", xCoord);
|
||||||
|
chunkTicket.getModData().setInteger("quarryY", yCoord);
|
||||||
if (placedBy != null && !worldObj.isRemote) {
|
chunkTicket.getModData().setInteger("quarryZ", zCoord);
|
||||||
placedBy.addChatMessage(new ChatComponentText(
|
ForgeChunkManager.forceChunk(chunkTicket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
|
||||||
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("quarryY", yCoord);
|
|
||||||
chunkTicket.getModData().setInteger("quarryZ", zCoord);
|
|
||||||
ForgeChunkManager.forceChunk(chunkTicket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
|
|
||||||
|
|
||||||
IAreaProvider a = null;
|
IAreaProvider a = null;
|
||||||
|
|
||||||
|
@ -522,17 +525,19 @@ 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 (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth()) {
|
if (chunkTicket != null) {
|
||||||
if (placedBy != null) {
|
if (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth()) {
|
||||||
placedBy.addChatMessage(new ChatComponentText(
|
if (placedBy != null) {
|
||||||
String.format(
|
placedBy.addChatMessage(new ChatComponentText(
|
||||||
"Quarry size is outside of chunkloading bounds or too small %d %d (%d)",
|
String.format(
|
||||||
xSize, zSize,
|
"Quarry size is outside of chunkloading bounds or too small %d %d (%d)",
|
||||||
chunkTicket.getMaxChunkListDepth())));
|
xSize, zSize,
|
||||||
}
|
chunkTicket.getMaxChunkListDepth())));
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -575,7 +580,11 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
|
||||||
}
|
}
|
||||||
|
|
||||||
a.removeFromWorld();
|
a.removeFromWorld();
|
||||||
forceChunkLoading(chunkTicket);
|
if (chunkTicket != null) {
|
||||||
|
forceChunkLoading(chunkTicket);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendNetworkUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeBlueprintBuilder() {
|
private void initializeBlueprintBuilder() {
|
||||||
|
@ -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