aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines
diff options
context:
space:
mode:
authorJordan Byrne <draknyte1@hotmail.com>2018-05-23 03:53:53 +1000
committerJordan Byrne <draknyte1@hotmail.com>2018-05-23 03:53:53 +1000
commit884627caa32082af7e99db2f7d5537499d86d880 (patch)
treea487805d36f16cfb4970c6c543f89de1379845a9 /src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines
parentb85374315559dde05ac6c826fc05273d250b285a (diff)
downloadGT5-Unofficial-884627caa32082af7e99db2f7d5537499d86d880.tar.gz
GT5-Unofficial-884627caa32082af7e99db2f7d5537499d86d880.tar.bz2
GT5-Unofficial-884627caa32082af7e99db2f7d5537499d86d880.zip
+ Added another data storage object. Examine ReverseAutoMap.java for information.
$ Massive overhaul to the Chunk Loaders. $ Hopefully added a way to check OreGen per dimension. % Gave the BlockPos.java object a better UID.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java226
1 files changed, 164 insertions, 62 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java
index 034c2da487..b73daf3db6 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntityChunkLoader.java
@@ -10,6 +10,7 @@ import java.util.Set;
import java.util.UUID;
import com.google.common.collect.MapMaker;
+import com.google.common.collect.Sets;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -39,16 +40,46 @@ import net.minecraftforge.common.ForgeChunkManager.Type;
public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredMachineBlock implements IChunkLoader {
- public int mRange = 16;
private long mTicksLeft = 0;
- private UUID mUUID = UUID.randomUUID();
+
+ private boolean hasTicket;
+ private boolean refreshTicket;
+ @SuppressWarnings("unused")
+ private final static int yMin = 0;
+ private final static int yMax = 254;
+ private final int xMin, xMax;
+ private final int zMin, zMax;
+ private int mChunkLoaderMapID = -1;
+ private boolean mHasID = false;
+ private final short mMaxTicks = 100;
+ private final UUID mUUID;
+ private static final byte ANCHOR_RADIUS = 1;
+ private static final Map<UUID, Ticket> tickets = new MapMaker().makeMap();
+ private Set<ChunkCoordIntPair> chunks;
+
public GregtechMetaTileEntityChunkLoader(final int aID, final String aName, final String aNameRegional, final int aTier) {
super(aID, aName, aNameRegional, aTier, 0, "Loads chunks: " + (16 + (48 * aTier)) + " powered");
+ xMin = this.xCoord-47;
+ xMax = this.xCoord+47;
+ zMin = this.zCoord-47;
+ zMax = this.zCoord+47;
+ mUUID = UUID.randomUUID();
+ this.prevX = this.xCoord;
+ this.prevY = this.yCoord;
+ this.prevZ = this.zCoord;
}
public GregtechMetaTileEntityChunkLoader(final String aName, final int aTier, final int aInvSlotCount, final String aDescription, final ITexture[][][] aTextures) {
super(aName, aTier, aInvSlotCount, aDescription, aTextures);
+ xMin = this.xCoord-47;
+ xMax = this.xCoord+47;
+ zMin = this.zCoord-47;
+ zMax = this.zCoord+47;
+ mUUID = UUID.randomUUID();
+ this.prevX = this.xCoord;
+ this.prevY = this.yCoord;
+ this.prevZ = this.zCoord;
}
@Override
@@ -65,34 +96,50 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
private int prevX, prevY, prevZ;
@Override
public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) {
+
+ xCoord = aBaseMetaTileEntity.getXCoord();
+ yCoord = aBaseMetaTileEntity.getYCoord();
+ zCoord = aBaseMetaTileEntity.getZCoord();
+
+
if (!aBaseMetaTileEntity.isServerSide()) {
return;
}
+
+ if (aTimer % 300 == 0) {
+ if (!isRegistered() && this.getEUVar() > 0) {
+ registerLoader();
+ }
+ else if (isRegistered() && this.getEUVar() <= 0) {
+ releaseTicket();
+ }
+ }
- if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isServerSide()) {
-
-
+ if (!areChunksLoaded()) {
+ return;
+ }
+ if (aBaseMetaTileEntity.isAllowedToWork()) {
if (this.mTicksLeft > 0) {
this.mTicksLeft--;
}
else if (this.mTicksLeft < 0) {
this.mTicksLeft = 0;
}
- if (mTicksLeft < 10) {
+ if (mTicksLeft < mMaxTicks) {
long h = this.getEUVar();
if (h > 0) {
if (h >(this.maxEUInput()+this.getMinimumStoredEU())) {
this.setEUVar((this.getEUVar()-this.maxEUInput()));
- this.mTicksLeft += 10;
+ this.mTicksLeft += 2;
}
}
- }
-
- xCoord = aBaseMetaTileEntity.getXCoord();
- yCoord = aBaseMetaTileEntity.getYCoord();
- zCoord = aBaseMetaTileEntity.getZCoord();
+ }
+ if (mTicksLeft > mMaxTicks) {
+ mTicksLeft = mMaxTicks;
+ }
+ //Somehow the Tile has moved, so lets release the ticket and update the previous xyz.
if (xCoord != prevX || yCoord != prevY || zCoord != prevZ) {
releaseTicket();
prevX = xCoord;
@@ -100,30 +147,26 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
prevZ = zCoord;
}
+ //Tile has an active ticket, but either (1) the ticket is for a different dimension. (2) A ticket refresh has been queued or (3) the Tile is not allowed to work (Disabled via mallet)
if (hasActiveTicket() && (getTicket().world != aBaseMetaTileEntity.getWorld() || refreshTicket || !aBaseMetaTileEntity.isAllowedToWork())) {
releaseTicket();
- }
+ }
+ //Tile does not have a ticket but has mTicksLeft, we had best create a ticket,
if (!hasActiveTicket() && this.mTicksLeft > 0) {
requestTicket();
}
-
-
}
-
-
-
-
}
@Override
public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) {
- validate();
+
}
@Override
public void onRemoval() {
- ChunkManager.mChunkLoaderManagerMap.remove(new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId));
+ releaseTicket();
}
@Override
@@ -133,7 +176,7 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
@Override
public boolean isFacingValid(final byte aFacing) {
- return true;
+ return aFacing > 1;
}
@Override
@@ -189,11 +232,15 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
@Override
public void saveNBTData(final NBTTagCompound aNBT) {
aNBT.setLong("mTicksLeft", getTicksRemaining());
+ aNBT.setBoolean("mHasID", mHasID);
+ aNBT.setInteger("mChunkLoaderMapID", mChunkLoaderMapID);
}
@Override
public void loadNBTData(final NBTTagCompound aNBT) {
this.mTicksLeft = aNBT.getLong("mTicksLeft");
+ this.mHasID = aNBT.getBoolean("mHasID");
+ this.mChunkLoaderMapID = aNBT.getInteger("mChunkLoaderMapID");
}
@@ -203,24 +250,32 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
/**
* Chunk Handling
*/
- private static final Map<UUID, Ticket> tickets = new MapMaker().makeMap();
- private static final byte ANCHOR_RADIUS = 1;
- private boolean hasTicket;
- private boolean refreshTicket;
- private Set<ChunkCoordIntPair> chunks;
- private short mChunkLoaderMapID = -1;
public void registerLoader() {
- short mSize = (short) mChunkLoaderManagerMap.size();
- this.mChunkLoaderMapID = mSize;
- if (this != null && this.getBaseMetaTileEntity() != null) {
- if (!isRegistered()) {
- if (this.xCoord != 0 && this.yCoord != 0 && this.zCoord != 0) {
- BlockPos thisPos = new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId);
- Triplet<Integer, GregtechMetaTileEntityChunkLoader, DimChunkPos> loaderData = new Triplet<Integer, GregtechMetaTileEntityChunkLoader, DimChunkPos>((int) this.mChunkLoaderMapID, this, new DimChunkPos(this.getBaseMetaTileEntity().getWorld(), thisPos));
- mChunkLoaderManagerMap.put(thisPos, loaderData);
- Logger.INFO("[Chunk Loader] Registered Chunk loader ["+this.mChunkLoaderMapID+"]"+thisPos.getLocationString());
- //mChunkLoaders.put(new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId),this);
+ if (this.getBaseMetaTileEntity().getWorld().isRemote) {
+ return;
+ }
+ //Logger.INFO("=======================[Chunkloader Registration]========================");
+ //Logger.INFO("Method Call [1]:"+ReflectionUtils.getMethodName(0));
+ //Logger.INFO("Method Call [2]:"+ReflectionUtils.getMethodName(1));
+ //Logger.INFO("Method Call [3]:"+ReflectionUtils.getMethodName(2));
+ if (this.getEUVar() <= 0) {
+ return;
+ }
+
+ if (this.getBaseMetaTileEntity() != null && this.getBaseMetaTileEntity().getWorld() != null && this.getBaseMetaTileEntity().getWorld().getWorldTime() >= 100) {
+ if (!mHasID) {
+ this.mChunkLoaderMapID = ChunkManager.getIdFromUniqueString(getUniqueID());
+ mHasID = true;
+ }
+ if (this != null && this.getBaseMetaTileEntity() != null) {
+ if (!isRegistered() && !getUniqueID().equalsIgnoreCase("0@0@0@0")) {
+ Triplet<Integer, GregtechMetaTileEntityChunkLoader, DimChunkPos> loaderData = new Triplet<Integer, GregtechMetaTileEntityChunkLoader, DimChunkPos>((int) this.mChunkLoaderMapID, this, new DimChunkPos(this.getBaseMetaTileEntity().getWorld(), getPos()));
+ mChunkLoaderManagerMap.put(getUniqueID(), loaderData);
+ Logger.INFO("[Chunk Loader] Registered Chunk loader ["+this.mChunkLoaderMapID+"]"+getPos().getLocationString());
+ }
+ else {
+ Logger.INFO("Tried to re-register a Chunk-Loader. Loader located @ "+getPos().getLocationString());
}
}
}
@@ -229,22 +284,37 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
public void unregisterLoader() {
if (this != null && this.getBaseMetaTileEntity() != null) {
- if (isRegistered()) {
- BlockPos thisPos = new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId);
- mChunkLoaderManagerMap.remove(thisPos);
- Logger.INFO("[Chunk Loader] Removed Chunk loader ["+this.mChunkLoaderMapID+"]"+thisPos.getLocationString());
- //mChunkLoaders.put(new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId),this);
+ if (isRegistered()) {
+ mChunkLoaderManagerMap.remove(getUniqueID());
+ Logger.INFO("[Chunk Loader] Removed Chunk loader ["+this.mChunkLoaderMapID+"]"+getPos().getLocationString());
}
}
}
public boolean isRegistered() {
- BlockPos j = new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId);
- return mChunkLoaderManagerMap.containsKey(j);
- //return mChunkLoaders.containsValue(this);
+ return mChunkLoaderManagerMap.containsKey(getUniqueID());
+ }
+
+ private BlockPos mCachedLocation;
+ public BlockPos getPos() {
+ if (mCachedLocation == null) {
+ mCachedLocation = new BlockPos(this.xCoord, this.yCoord, this.zCoord, this.getBaseMetaTileEntity().getWorld().provider.dimensionId);
+ }
+ else if (mCachedLocation.xPos == 0 && mCachedLocation.yPos == 0 && mCachedLocation.zPos == 0 && mCachedLocation.dim == 0) {
+ mCachedLocation = null;
+ return getPos();
+ }
+ return mCachedLocation;
+ }
+
+ public String getUniqueID() {
+ if (getPos() == null) {
+ return "InvalidChunkLoader";
+ }
+ return getPos().getUniqueIdentifier();
}
- public short getLoaderID() {
+ public int getLoaderID() {
return this.mChunkLoaderMapID;
}
@@ -253,19 +323,22 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
}
public void invalidate() {
+ releaseTicket();
+ super.inValidate();
refreshTicket = true;
- unregisterLoader();
}
public void validate() {
if (!isRegistered()) {
registerLoader();
}
- refreshTicket = true;
}
protected void releaseTicket() {
refreshTicket = false;
+ if (getTicket() != null) {
+ ForgeChunkManager.releaseTicket(getTicket());
+ }
setTicket(null);
unregisterLoader();
}
@@ -312,14 +385,14 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
}
ForgeChunkManager.releaseTicket(ticket);
}
- Logger.INFO("[Chunk Loader] "+"Removing Ticking. ["+this.getLoaderID()+"] @ [x: "+this.xCoord+"][y: "+this.yCoord+"][z: "+this.zCoord+"]");
+ Logger.INFO("[Chunk Loader] "+"Removing Ticket. ["+this.getLoaderID()+"] @ [x: "+this.xCoord+"][y: "+this.yCoord+"][z: "+this.zCoord+"]");
tickets.remove(mUUID);
}
changed = true;
}
- hasTicket = t != null;
+ hasTicket = (t != null);
if (hasTicket) {
- Logger.INFO("[Chunk Loader] "+"Putting Ticking. ["+this.getLoaderID()+"] @ [x: "+this.xCoord+"][y: "+this.yCoord+"][z: "+this.zCoord+"]");
+ Logger.INFO("[Chunk Loader] "+"Putting Ticket. ["+this.getLoaderID()+"] @ [x: "+this.xCoord+"][y: "+this.yCoord+"][z: "+this.zCoord+"]");
tickets.put(mUUID, t);
}
//if (changed)
@@ -327,22 +400,36 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
}
public void forceChunkLoading(Ticket ticket) {
- try {
+ try {
setTicket(ticket);
-
- setupChunks();
-
- if (chunks != null) {
+ forceChunkLoading2(ticket);
+ //setupChunks();
+ /*if (chunks != null) {
for (ChunkCoordIntPair chunk : chunks) {
ForgeChunkManager.forceChunk(ticket, chunk);
}
- }
+ }*/
}
catch (Throwable t){
t.printStackTrace();
}
}
+ public void forceChunkLoading2(Ticket ticket) {
+ chunks = Sets.newHashSet();
+ ChunkCoordIntPair quarryChunk = new ChunkCoordIntPair(xCoord >> 4, zCoord >> 4);
+ chunks.add(quarryChunk);
+ ForgeChunkManager.forceChunk(ticket, quarryChunk);
+ for (int chunkX = xMin >> 4; chunkX <= xMax >> 4; chunkX++) {
+ for (int chunkZ = zMin >> 4; chunkZ <= zMax >> 4; chunkZ++) {
+ ChunkCoordIntPair chunk = new ChunkCoordIntPair(chunkX, chunkZ);
+ ForgeChunkManager.forceChunk(ticket, chunk);
+ chunks.add(chunk);
+ }
+ }
+
+ }
+
public void setupChunks() {
if (!hasTicket)
chunks = null;
@@ -412,7 +499,6 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
@Override
public void onMachineBlockUpdate() {
- validate();
super.onMachineBlockUpdate();
}
@@ -424,7 +510,7 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
@Override
public void doExplosion(long aExplosionPower) {
- this.releaseTicket();
+ releaseTicket();
super.doExplosion(aExplosionPower);
}
@@ -438,13 +524,12 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
return new String[] {
this.getLocalName(),
"Ticks Left: "+this.mTicksLeft,
- "mRange: "+this.mRange,
+ "mRange: "+(16 + (48 * mTier)),
"chunks: "+this.chunks.size()};
}
@Override
public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
- validate();
super.onCreated(aStack, aWorld, aPlayer);
}
@@ -466,4 +551,21 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM
super.onWorldSave(aSaveDirectory);
}
+ //Based on BC 7
+
+
+ private boolean hasCheckedChunks = false;
+ public boolean areChunksLoaded() {
+ if (hasCheckedChunks) {
+ return true;
+ }
+ World worldObj = this.getBaseMetaTileEntity().getWorld();
+ hasCheckedChunks = worldObj.blockExists(xMin, yMax, zMin)
+ && worldObj.blockExists(xMax, yMax, zMin)
+ && worldObj.blockExists(xMin, yMax, zMax)
+ && worldObj.blockExists(xMax, yMax, zMax);
+ // Each chunk covers the full height, so we only check one of them per height.
+ return hasCheckedChunks;
+ }
+
}