aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java
diff options
context:
space:
mode:
authorbotn365 <42187820+botn365@users.noreply.github.com>2020-01-08 16:48:18 +0100
committerGitHub <noreply@github.com>2020-01-08 16:48:18 +0100
commita3a9d4a5c2e466db33879176626670f2f07b635a (patch)
tree8176e79d6be425dc28cc3a612416b832a5bed3c5 /src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java
parentd7c83c3cd1036668c1f520f144c08de444f675a4 (diff)
parent6bb3c6872c97b36c84f32bf730eee31206728c74 (diff)
downloadGT5-Unofficial-a3a9d4a5c2e466db33879176626670f2f07b635a.tar.gz
GT5-Unofficial-a3a9d4a5c2e466db33879176626670f2f07b635a.tar.bz2
GT5-Unofficial-a3a9d4a5c2e466db33879176626670f2f07b635a.zip
Merge pull request #7 from alkcorp/master
sync
Diffstat (limited to 'src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java')
-rw-r--r--src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java b/src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java
new file mode 100644
index 0000000000..36d9fa670c
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java
@@ -0,0 +1,63 @@
+package gtPlusPlus.core.chunkloading;
+
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gtPlusPlus.api.interfaces.IChunkLoader;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaTileEntityChunkLoader;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.ChunkCoordIntPair;
+
+public class StaticChunkFunctions {
+
+ public static void saveNBTDataForTileEntity(IGregTechTileEntity aBaseMetaTileEntity, NBTTagCompound aNBT) {
+ IChunkLoader aTileEntity = getChunkLoader(aBaseMetaTileEntity);
+ aNBT.setBoolean("chunkLoadingEnabled", aTileEntity.getChunkLoadingActive());
+ aNBT.setBoolean("isChunkloading", aTileEntity.getResidingChunk() != null);
+ if (aTileEntity.getResidingChunk() != null) {
+ aNBT.setInteger("loadedChunkXPos", aTileEntity.getResidingChunk().chunkXPos);
+ aNBT.setInteger("loadedChunkZPos", aTileEntity.getResidingChunk().chunkZPos);
+ }
+ }
+
+ public static void loadNBTDataForTileEntity(IGregTechTileEntity aBaseMetaTileEntity, NBTTagCompound aNBT) {
+ IChunkLoader aTileEntity = getChunkLoader(aBaseMetaTileEntity);
+ if (aNBT.hasKey("chunkLoadingEnabled")) {
+ aTileEntity.setChunkLoadingActive(aNBT.getBoolean("chunkLoadingEnabled"));
+ }
+ if (aNBT.getBoolean("isChunkloading")) {
+ aTileEntity.setResidingChunk(new ChunkCoordIntPair(aNBT.getInteger("loadedChunkXPos"), aNBT.getInteger("loadedChunkZPos")));
+ }
+ }
+
+ public static void onRemoval(IGregTechTileEntity aBaseMetaTileEntity) {
+ IChunkLoader aTileEntity = getChunkLoader(aBaseMetaTileEntity);
+ if (aTileEntity.getChunkLoadingActive()) {
+ GTPP_ChunkManager.releaseTicket((TileEntity)aBaseMetaTileEntity);
+ }
+ }
+
+ public static boolean onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ IChunkLoader aTileEntity = getChunkLoader(aBaseMetaTileEntity);
+ if (aBaseMetaTileEntity.isServerSide() && aTileEntity.getResidingChunk() != null && !aTileEntity.getDoesWorkChunkNeedReload() && !aBaseMetaTileEntity.isAllowedToWork()) {
+ // if machine has stopped, stop chunkloading
+ GTPP_ChunkManager.releaseTicket((TileEntity)aBaseMetaTileEntity);
+ aTileEntity.setDoesWorkChunkNeedReload(true);
+ return false;
+ }
+ return true;
+ }
+
+ public static void createInitialWorkingChunk(IGregTechTileEntity aBaseMetaTileEntity, int aChunkX, int aDrillZ) {
+ final int centerX = aChunkX >> 4;
+ final int centerZ = aDrillZ >> 4;
+ IChunkLoader aTileEntity = getChunkLoader(aBaseMetaTileEntity);
+ aTileEntity.addChunkToLoadedList(new ChunkCoordIntPair(centerX, centerZ));
+ GTPP_ChunkManager.requestChunkLoad((TileEntity)aBaseMetaTileEntity.getMetaTileEntity(), aTileEntity.getResidingChunk());
+ aTileEntity.setDoesWorkChunkNeedReload(false);
+ }
+
+ private static final IChunkLoader getChunkLoader(IGregTechTileEntity aTile) {
+ return (IChunkLoader) ((IGregTechTileEntity)aTile).getMetaTileEntity();
+ }
+
+}