Fix chunkloading for quarries.

This commit is contained in:
Christian 2012-10-01 22:47:50 -04:00
parent 6802a14545
commit 2e6c0ea475
3 changed files with 97 additions and 48 deletions

View file

@ -91,12 +91,19 @@ public class BuildCraftFactory {
{
@Override
public void ticketsLoaded(List<Ticket> tickets, World world) {
// NO OP for OrderedLoadingCallback
for (Ticket ticket : tickets)
{
int quarryX = ticket.getModData().getInteger("quarryX");
int quarryY = ticket.getModData().getInteger("quarryY");
int quarryZ = ticket.getModData().getInteger("quarryZ");
TileQuarry tq = (TileQuarry) world.getBlockTileEntity(quarryX, quarryY, quarryZ);
tq.forceChunkLoading(ticket);
}
}
@Override
public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world,
int maxTicketCount) {
public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount) {
List<Ticket> validTickets = Lists.newArrayList();
for (Ticket ticket : tickets)
{
@ -107,8 +114,6 @@ public class BuildCraftFactory {
int blId = world.getBlockId(quarryX, quarryY, quarryZ);
if (blId == quarryBlock.blockID)
{
TileQuarry tq = (TileQuarry) world.getBlockTileEntity(quarryX, quarryY, quarryZ);
tq.forceChunkLoading(ticket);
validTickets.add(ticket);
}
}

View file

@ -1,8 +1,8 @@
/**
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
@ -11,6 +11,8 @@ package buildcraft.factory;
import java.util.ArrayList;
import com.google.common.math.IntMath;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.Orientations;
import buildcraft.api.core.Position;
@ -57,6 +59,11 @@ public class BlockQuarry extends BlockMachineRoot {
new Position(i, j, k));
world.setBlockMetadataWithNotify(i, j, k, orientation.reverse().ordinal());
if (entityliving instanceof EntityPlayer)
{
TileQuarry tq = (TileQuarry) world.getBlockTileEntity(i,j,k);
tq.placedBy = (EntityPlayer) entityliving;
}
}
@Override
@ -125,46 +132,48 @@ public class BlockQuarry extends BlockMachineRoot {
world.setBlockMetadata(x, y, z, 1);
}
}
@Override
public void breakBlock(World world, int i, int j, int k, int par5, int par6) {
if (CoreProxy.proxy.isRenderWorld(world)){
if (!CoreProxy.proxy.isSimulating(world)){
return;
}
TileEntity tile = world.getBlockTileEntity(i, j, k);
if (tile instanceof TileQuarry){
TileQuarry quarry = (TileQuarry)tile;
Box box = quarry.box;
//X - Axis
for (int x = box.xMin; x <= box.xMax; x++) {
markFrameForDecay(world, x, box.yMin, box.zMin);
markFrameForDecay(world, x, box.yMax, box.zMin);
markFrameForDecay(world, x, box.yMin, box.zMax);
markFrameForDecay(world, x, box.yMax, box.zMax);
}
//Z - Axis
for (int z = box.zMin + 1; z <= box.zMax - 1; z++) {
markFrameForDecay(world, box.xMin, box.yMin, z);
markFrameForDecay(world, box.xMax, box.yMin, z);
markFrameForDecay(world, box.xMin, box.yMax, z);
markFrameForDecay(world, box.xMax, box.yMax, z);
}
//Y - Axis
for (int y = box.yMin + 1; y <= box.yMax -1; y++) {
markFrameForDecay(world, box.xMin, y, box.zMin);
markFrameForDecay(world, box.xMax, y, box.zMin);
markFrameForDecay(world, box.xMin, y, box.zMax);
markFrameForDecay(world, box.xMax, y, box.zMax);
if (box.isInitialized() && Integer.MAX_VALUE != box.xMax)
{
//X - Axis
for (int x = box.xMin; x <= box.xMax; x++) {
markFrameForDecay(world, x, box.yMin, box.zMin);
markFrameForDecay(world, x, box.yMax, box.zMin);
markFrameForDecay(world, x, box.yMin, box.zMax);
markFrameForDecay(world, x, box.yMax, box.zMax);
}
//Z - Axis
for (int z = box.zMin + 1; z <= box.zMax - 1; z++) {
markFrameForDecay(world, box.xMin, box.yMin, z);
markFrameForDecay(world, box.xMax, box.yMin, z);
markFrameForDecay(world, box.xMin, box.yMax, z);
markFrameForDecay(world, box.xMax, box.yMax, z);
}
//Y - Axis
for (int y = box.yMin + 1; y <= box.yMax -1; y++) {
markFrameForDecay(world, box.xMin, y, box.zMin);
markFrameForDecay(world, box.xMax, y, box.zMin);
markFrameForDecay(world, box.xMin, y, box.zMax);
markFrameForDecay(world, box.xMax, y, box.zMax);
}
}
quarry.destroy();
}
Utils.preDestroyBlock(world, i, j, k);
// byte width = 1;
@ -197,7 +206,7 @@ public class BlockQuarry extends BlockMachineRoot {
super.breakBlock(world, i, j, k, par5, par6);
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
TileQuarry tile = (TileQuarry) world.getBlockTileEntity(i, j, k);

View file

@ -11,9 +11,13 @@ package buildcraft.factory;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import buildcraft.BuildCraftFactory;
import buildcraft.api.core.BuildCraftAPI;
@ -42,6 +46,7 @@ import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Block;
import net.minecraft.src.ChunkCoordIntPair;
import net.minecraft.src.EntityItem;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
@ -118,7 +123,8 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
private boolean movingVertically;
private double headTrajectory;
private Ticket chunkTicket;
private boolean isAlive;
public @TileNetworkData boolean isAlive;
public EntityPlayer placedBy;
private void createArm() {
@ -139,6 +145,12 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
public void updateEntity() {
if (!isAlive && CoreProxy.proxy.isSimulating(worldObj))
{
super.updateEntity();
return;
}
if (!CoreProxy.proxy.isSimulating(worldObj) && isAlive)
{
super.updateEntity();
return;
}
super.updateEntity();
@ -152,7 +164,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
}
if (CoreProxy.proxy.isSimulating(worldObj)) {
if (CoreProxy.proxy.isSimulating(worldObj) && inProcess) {
sendNetworkUpdate();
}
if (inProcess || !isDigging) {
@ -400,7 +412,6 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
}
private void mineStack(ItemStack stack) {
System.out.printf("Mining stack %d\n", stack.itemID);
// First, try to add to a nearby chest
ItemStack added = Utils.addToRandomInventory(stack, worldObj, xCoord, yCoord, zCoord, Orientations.Unknown);
stack.stackSize -= added.stackSize;
@ -478,7 +489,11 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
if (chunkTicket == null)
{
isAlive = false;
PacketDispatcher.sendPacketToAllPlayers(new Packet3Chat(String.format("[BUILDCRAFT] Chunkloading capabilities exhausted. The quarry at %d, %d, %d will not work. Remove some quarries!", xCoord, yCoord, zCoord)));
if (placedBy!=null && CoreProxy.proxy.isSimulating(worldObj))
{
PacketDispatcher.sendPacketToPlayer(new Packet3Chat(String.format("[BUILDCRAFT] The quarry at %d, %d, %d will not work because there are no more chunkloaders available", xCoord, yCoord, zCoord)), (Player) placedBy);
}
sendNetworkUpdate();
return;
}
chunkTicket.getModData().setInteger("quarryX", xCoord);
@ -504,7 +519,10 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
if (xSize < 3 || zSize < 3 || ((xSize * zSize) >> 8) >= chunkTicket.getMaxChunkListDepth())
{
FMLLog.info("Quarry size is outside of bounds %d %d (%d)", xSize, zSize, chunkTicket.getMaxChunkListDepth());
if (placedBy != null)
{
PacketDispatcher.sendPacketToPlayer(new Packet3Chat(String.format("Quarry size is outside of chunkloading bounds or too small %d %d (%d)", xSize, zSize, chunkTicket.getMaxChunkListDepth())),(Player) placedBy);
}
a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);
useDefault = true;
@ -589,11 +607,18 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
@Override
public void postPacketHandling(PacketUpdate packet) {
super.postPacketHandling(packet);
createUtilsIfNeeded();
if (isAlive)
{
createUtilsIfNeeded();
}
else
{
box.deleteLasers();
box.reset();
return;
}
if (arm != null) {
arm.setHead(headPosX, headPosY, headPosZ);
arm.updatePosition();
@ -780,16 +805,26 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
chunkTicket = ticket;
}
Set<ChunkCoordIntPair> chunks = Sets.newHashSet();
isAlive = true;
ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
ChunkCoordIntPair quarryChunk = new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4);
chunks.add(quarryChunk);
ForgeChunkManager.forceChunk(ticket, quarryChunk);
for (int chunkX = box.xMin >> 4; chunkX <= box.xMax >> 4; chunkX ++)
{
for (int chunkZ = box.zMin >> 4; chunkZ <= box.zMax >> 4; chunkZ ++)
{
ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(chunkX, chunkZ));
ChunkCoordIntPair chunk = new ChunkCoordIntPair(chunkX, chunkZ);
ForgeChunkManager.forceChunk(ticket, chunk);
chunks.add(chunk);
}
}
if (placedBy != null)
{
PacketDispatcher.sendPacketToPlayer(new Packet3Chat(String.format("[BUILDCRAFT] The quarry at %d %d %d will keep %d chunks loaded",xCoord, yCoord, zCoord, chunks.size())),(Player) placedBy);
}
sendNetworkUpdate();
}
}