Merge branch 'chunkloading'
This commit is contained in:
commit
c365be9e00
8 changed files with 107 additions and 15 deletions
|
@ -8,6 +8,10 @@
|
|||
|
||||
package buildcraft;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.Init;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
|
@ -49,7 +53,10 @@ import buildcraft.silicon.TileLaser;
|
|||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.Property;
|
||||
|
||||
@Mod(name="BuildCraft Factory", version=Version.VERSION, useMetadata = false, modid = "BuildCraft|Factory", dependencies = DefaultProps.DEPENDENCY_CORE)
|
||||
|
@ -77,6 +84,37 @@ public class BuildCraftFactory {
|
|||
@PostInit
|
||||
public void postInit(FMLPostInitializationEvent evt) {
|
||||
FactoryProxy.proxy.initializeNEIIntegration();
|
||||
ForgeChunkManager.setForcedChunkLoadingCallback(instance,new QuarryChunkloadCallback());
|
||||
}
|
||||
|
||||
public class QuarryChunkloadCallback implements ForgeChunkManager.OrderedLoadingCallback
|
||||
{
|
||||
@Override
|
||||
public void ticketsLoaded(List<Ticket> tickets, World world) {
|
||||
// NO OP for OrderedLoadingCallback
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world,
|
||||
int maxTicketCount) {
|
||||
List<Ticket> validTickets = Lists.newArrayList();
|
||||
for (Ticket ticket : tickets)
|
||||
{
|
||||
int quarryX = ticket.getModData().getInteger("quarryX");
|
||||
int quarryY = ticket.getModData().getInteger("quarryY");
|
||||
int quarryZ = ticket.getModData().getInteger("quarryZ");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return validTickets;
|
||||
}
|
||||
|
||||
}
|
||||
@Init
|
||||
public void load(FMLInitializationEvent evt) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/**
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ public abstract class ItemBptBase extends ItemBuildCraft {
|
|||
|
||||
maxStackSize = 1;
|
||||
iconIndex = 5 * 16 + 0;
|
||||
this.setTabToDisplayOn(CreativeTabs.tabMisc);
|
||||
this.setCreativeTab(CreativeTabs.tabMisc);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "all" })
|
||||
|
|
|
@ -76,7 +76,7 @@ public class TilePathMarker extends TileMarker {
|
|||
double nearestDistance = 0, distance; //The initialization of nearestDistance is only to make the compiler shut up
|
||||
|
||||
for (TilePathMarker t : availableMarkers) {
|
||||
if (t == this || t == this.links[0] || t == this.links[1] || t.worldObj.provider.worldType != this.worldObj.provider.worldType)
|
||||
if (t == this || t == this.links[0] || t == this.links[1] || t.worldObj.provider.dimensionId != this.worldObj.provider.dimensionId)
|
||||
continue;
|
||||
|
||||
distance = Math.sqrt(Math.pow(this.xCoord - t.xCoord, 2) + Math.pow(this.yCoord - t.yCoord, 2) + Math.pow(this.zCoord - t.zCoord, 2));
|
||||
|
@ -257,7 +257,7 @@ public class TilePathMarker extends TileMarker {
|
|||
public static void clearAvailableMarkersList(World w) {
|
||||
for (Iterator<TilePathMarker> it = availableMarkers.iterator(); it.hasNext();) {
|
||||
TilePathMarker t = it.next();
|
||||
if (t.worldObj.provider.worldType != w.provider.worldType) {
|
||||
if (t.worldObj.provider.dimensionId != w.provider.dimensionId) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
}
|
||||
|
||||
@Override
|
||||
public Packet getAuxillaryInfoPacket() {
|
||||
public Packet getDescriptionPacket() {
|
||||
return new PacketTileUpdate(this).getPacket();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft {
|
|||
|
||||
drawTexturedModalRect(cornerX + x, cornerY + y, 16 * textureJ, 16 * textureI, 16, 16);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void drawStack(ItemStack item) {
|
||||
|
@ -165,7 +165,7 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft {
|
|||
if (s.length() > 0) {
|
||||
int i2 = (lastX - cornerX);
|
||||
int k2 = lastY - cornerY;
|
||||
func_74190_a(s, i2, k2);
|
||||
drawCreativeTabHoveringText(s, i2, k2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public interface ISynchronizedTile {
|
|||
|
||||
public Packet getUpdatePacket();
|
||||
|
||||
public Packet getAuxillaryInfoPacket();
|
||||
public Packet getDescriptionPacket();
|
||||
|
||||
public PacketPayload getPacketPayload();
|
||||
}
|
||||
|
|
|
@ -321,10 +321,10 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
|
|||
|
||||
/* SMP UPDATING */
|
||||
@Override
|
||||
public Packet getAuxillaryInfoPacket() {
|
||||
public Packet getDescriptionPacket() {
|
||||
createEngineIfNeeded();
|
||||
|
||||
return super.getAuxillaryInfoPacket();
|
||||
return super.getDescriptionPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,9 @@ package buildcraft.factory;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
|
@ -37,10 +40,15 @@ import buildcraft.core.utils.Utils;
|
|||
|
||||
import net.minecraft.src.AxisAlignedBB;
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.ChunkCoordIntPair;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.Packet3Chat;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
|
||||
public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor, IPipeConnection, IBuilderInventory {
|
||||
public @TileNetworkData
|
||||
|
@ -109,6 +117,8 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
private boolean movingHorizontally;
|
||||
private boolean movingVertically;
|
||||
private double headTrajectory;
|
||||
private Ticket chunkTicket;
|
||||
private boolean isAlive;
|
||||
|
||||
private void createArm() {
|
||||
|
||||
|
@ -127,6 +137,10 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (!isAlive && CoreProxy.proxy.isSimulating(worldObj))
|
||||
{
|
||||
return;
|
||||
}
|
||||
super.updateEntity();
|
||||
if (inProcess) {
|
||||
float energyToUse = 2 + powerProvider.getEnergyStored() / 1000;
|
||||
|
@ -386,7 +400,7 @@ 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;
|
||||
|
@ -425,6 +439,7 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
|
||||
super.invalidate();
|
||||
destroy();
|
||||
|
@ -456,6 +471,20 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
}
|
||||
|
||||
private void setBoundaries(boolean useDefault) {
|
||||
if (chunkTicket == null)
|
||||
{
|
||||
chunkTicket = ForgeChunkManager.requestTicket(BuildCraftFactory.instance, worldObj, Type.NORMAL);
|
||||
}
|
||||
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)));
|
||||
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;
|
||||
|
||||
|
@ -473,7 +502,9 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
int ySize = a.yMax() - a.yMin() + 1;
|
||||
int zSize = a.zMax() - a.zMin() + 1;
|
||||
|
||||
if (xSize < 3 || zSize < 3) {
|
||||
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());
|
||||
a = new DefaultAreaProvider(xCoord, yCoord, zCoord, xCoord + 10, yCoord + 4, zCoord + 10);
|
||||
|
||||
useDefault = true;
|
||||
|
@ -519,10 +550,10 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
}
|
||||
|
||||
a.removeFromWorld();
|
||||
forceChunkLoading(chunkTicket);
|
||||
}
|
||||
|
||||
private void initializeBluePrintBuilder() {
|
||||
|
||||
BptBlueprint bluePrint = new BptBlueprint(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
|
||||
for (int i = 0; i < bluePrint.sizeX; ++i) {
|
||||
|
@ -573,6 +604,11 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
public void initialize() {
|
||||
super.initialize();
|
||||
|
||||
if (CoreProxy.proxy.isSimulating(this.worldObj) && !box.initialized)
|
||||
{
|
||||
setBoundaries(false);
|
||||
}
|
||||
|
||||
createUtilsIfNeeded();
|
||||
|
||||
sendNetworkUpdate();
|
||||
|
@ -738,4 +774,22 @@ public class TileQuarry extends TileMachine implements IMachine, IPowerReceptor,
|
|||
this.targetZ = z;
|
||||
}
|
||||
|
||||
public void forceChunkLoading(Ticket ticket) {
|
||||
if (chunkTicket == null)
|
||||
{
|
||||
chunkTicket = ticket;
|
||||
}
|
||||
|
||||
isAlive = true;
|
||||
ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4));
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue