From e6ecfb3505e79fab5e0dfa7e597d6efc30de5b14 Mon Sep 17 00:00:00 2001 From: botn365 <42187820+botn365@users.noreply.github.com> Date: Mon, 30 Dec 2019 18:26:48 +0100 Subject: fix space for fluid detection --- .../implementations/base/GregtechMeta_MultiBlockBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index 4a6cad20c3..53068c68a1 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -770,7 +770,7 @@ public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_Mult // We have Fluid Stacks we did not merge. Do we have space? if (aOutputFluids.size() > 0) { // Not enough space to add fluids. - if (aOutputFluids.size() < aEmptyFluidHatches) { + if (aOutputFluids.size() > aEmptyFluidHatches) { Logger.INFO("Failed to find enough space for all fluid outputs."); return false; } -- cgit From a3777ddeab2cce237cf9a4a3891483c3aaf08d3d Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 30 Dec 2019 20:32:05 +0000 Subject: + Implemented Blacklist for OB Glider. Closes #584. + Added default versioning file. --- .../core/handler/COMPAT_IntermodStaging.java | 4 + .../Preloader_Transformer_Handler.java | 1 - src/Java/gtPlusPlus/xmod/ob/GliderHandler.java | 102 +++++++++++++++++++++ .../gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java | 38 ++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/Java/gtPlusPlus/xmod/ob/GliderHandler.java create mode 100644 src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java b/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java index b7efcf08ea..cd25fdb1c3 100644 --- a/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java +++ b/src/Java/gtPlusPlus/core/handler/COMPAT_IntermodStaging.java @@ -12,6 +12,7 @@ import gtPlusPlus.xmod.galacticraft.HANDLER_GalactiCraft; import gtPlusPlus.xmod.gregtech.HANDLER_GT; import gtPlusPlus.xmod.growthcraft.HANDLER_GC; import gtPlusPlus.xmod.ic2.HANDLER_IC2; +import gtPlusPlus.xmod.ob.HANDLER_OpenBlocks; import gtPlusPlus.xmod.railcraft.HANDLER_Railcraft; import gtPlusPlus.xmod.reliquary.HANDLER_Reliquary; import gtPlusPlus.xmod.sc2.HANDLER_SC2; @@ -37,6 +38,7 @@ public class COMPAT_IntermodStaging { HANDLER_CropsPlusPlus.preInit(preinit); HANDLER_Railcraft.preInit(); HANDLER_Reliquary.preInit(); + HANDLER_OpenBlocks.preInit(); } public static void init(FMLInitializationEvent init){ @@ -55,6 +57,7 @@ public class COMPAT_IntermodStaging { HANDLER_CropsPlusPlus.init(init); HANDLER_Railcraft.init(); HANDLER_Reliquary.init(); + HANDLER_OpenBlocks.init(); } public static void postInit(FMLPostInitializationEvent postinit){ @@ -73,6 +76,7 @@ public class COMPAT_IntermodStaging { HANDLER_CropsPlusPlus.postInit(postinit); HANDLER_Railcraft.postInit(); HANDLER_Reliquary.postInit(); + HANDLER_OpenBlocks.postInit(); } public static void onLoadComplete(FMLLoadCompleteEvent event) { diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java index c269e9463e..d81c96dcca 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java @@ -15,7 +15,6 @@ import gtPlusPlus.preloader.asm.transformers.Preloader_ClassTransformer.OreDicti import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.Launch; -@SuppressWarnings("static-access") public class Preloader_Transformer_Handler implements IClassTransformer { private final boolean mEnabled = false; diff --git a/src/Java/gtPlusPlus/xmod/ob/GliderHandler.java b/src/Java/gtPlusPlus/xmod/ob/GliderHandler.java new file mode 100644 index 0000000000..b1874b7ed2 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ob/GliderHandler.java @@ -0,0 +1,102 @@ +package gtPlusPlus.xmod.ob; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerUseItemEvent; + +public class GliderHandler { + + private static final AutoMap mDimensionalBlacklist = new AutoMap(); + + @SubscribeEvent + public void onItemUsage(final PlayerUseItemEvent event) { + if (event != null) { + ItemStack aItem = event.item; + if (ItemUtils.checkForInvalidItems(aItem)) { + Class aItemGliderClass = ReflectionUtils.getClass("openblocks.common.item.ItemHangGlider"); + if (aItemGliderClass.isInstance(aItem.getItem())) { + if (!canPlayerGlideInThisDimension(event.entityPlayer)){ + event.setCanceled(true); + } + } + } + } + } + + private static final boolean canPlayerGlideInThisDimension(EntityPlayer aPlayer) { + World aWorld = aPlayer.worldObj; + if (aWorld == null) { + return false; + } + else { + if (aWorld.provider == null) { + return false; + } + else { + int aDimID = aWorld.provider.dimensionId; + for (int i : mDimensionalBlacklist) { + if (i == aDimID) { + return false; + } + } + } + } + return true; + } + + static final void populateBlacklist() { + if (!mDimensionalBlacklist.isEmpty()) { + return; + } + File aBlacklist = gtPlusPlus.core.util.data.FileUtils.getFile("config/GTplusplus/", "GliderBlacklist", "cfg"); + List lines = new ArrayList(); + try { + lines = org.apache.commons.io.FileUtils.readLines(aBlacklist, "utf-8"); + } catch (IOException e) { + e.printStackTrace(); + } + if (lines.isEmpty()) { + FileWriter fw; + try { + String aInfoTip = "# Add one dimension ID per line. Lines with a # are comments and are ignored."; + fw = new FileWriter(aBlacklist); + fw.write(aInfoTip); + fw.close(); + lines.add(aInfoTip); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (!lines.isEmpty()) { + for (String s : lines) { + if (s != null && !s.equals("") && !s.contains("#")) { + s = StringUtils.remove(s, " "); + s = StringUtils.trim(s); + s = StringUtils.remove(s, ","); + Integer g = Integer.decode(s); + if (g != null) { + mDimensionalBlacklist.add(g); + Logger.INFO("[OpenBlocks] Added Dimension with ID '"+g+"' to Blacklist for Glider."); + } + } + } + } + } + + +} diff --git a/src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java b/src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java new file mode 100644 index 0000000000..c1b678f5ee --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ob/HANDLER_OpenBlocks.java @@ -0,0 +1,38 @@ +package gtPlusPlus.xmod.ob; + +import static gtPlusPlus.core.creative.AddToCreativeTab.tabMisc; + +import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.base.BaseItemBurnable; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.railcraft.utils.RailcraftUtils; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +public class HANDLER_OpenBlocks { + + public static void preInit() { + if (LoadedMods.OpenBlocks) { + + } + } + + public static void init() { + if (LoadedMods.OpenBlocks) { + GliderHandler.populateBlacklist(); + } + } + + public static void postInit() { + if (LoadedMods.OpenBlocks) { + Utils.registerEvent(new GliderHandler()); + } + } + +} -- cgit From 3a9f2400d30a319990e2ec792fef963cb2f1d3df Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 30 Dec 2019 23:19:38 +0000 Subject: + Added a Debug command for GT++ Chunkloading capabilities. % Retiered Chunkloaders. $ Potentially Fixed Chunkloaders. Thanks to @Repo-alt if such is the case. --- src/Java/gtPlusPlus/GTplusplus.java | 5 + .../gtPlusPlus/api/interfaces/IChunkLoader.java | 33 ++ .../api/interfaces/IChunkLoaderTile.java | 10 - .../core/chunkloading/GTPP_ChunkManager.java | 217 +++++++++ .../core/chunkloading/StaticChunkFunctions.java | 63 +++ .../xmod/gregtech/api/enums/GregtechItemList.java | 2 +- .../GregtechMetaAtmosphericReconditioner.java | 2 - .../basic/GregtechMetaTileEntityChunkLoader.java | 529 +++++++++++---------- .../gregtech/GregtechTieredChunkloaders.java | 9 +- 9 files changed, 609 insertions(+), 261 deletions(-) create mode 100644 src/Java/gtPlusPlus/api/interfaces/IChunkLoader.java delete mode 100644 src/Java/gtPlusPlus/api/interfaces/IChunkLoaderTile.java create mode 100644 src/Java/gtPlusPlus/core/chunkloading/GTPP_ChunkManager.java create mode 100644 src/Java/gtPlusPlus/core/chunkloading/StaticChunkFunctions.java (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index 9cf395a9bf..5828cc9ac2 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -29,6 +29,7 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.Recipe_GT; import gregtech.api.util.SemiFluidFuelHandler; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.chunkloading.GTPP_ChunkManager; import gtPlusPlus.core.commands.CommandDebugChunks; import gtPlusPlus.core.commands.CommandEnableDebugWhileRunning; import gtPlusPlus.core.commands.CommandMath; @@ -182,6 +183,7 @@ public class GTplusplus implements ActionListener { Logger.INFO("Setting up our own GT_Proxy."); Meta_GT_Proxy.preInit(); Core_Manager.preInit(); + GTPP_ChunkManager.init(); } // Init @@ -236,6 +238,9 @@ public class GTplusplus implements ActionListener { if (LoadedMods.Thaumcraft) { event.registerServerCommand(new CommandDumpAspects()); } + if (GTPP_ChunkManager.debugChunkloaders) { + event.registerServerCommand(new GTPP_ChunkManager.DebugCommand()); + } Core_Manager.serverStart(); INIT_PHASE.STARTED.setPhaseActive(true); } diff --git a/src/Java/gtPlusPlus/api/interfaces/IChunkLoader.java b/src/Java/gtPlusPlus/api/interfaces/IChunkLoader.java new file mode 100644 index 0000000000..c04e25f570 --- /dev/null +++ b/src/Java/gtPlusPlus/api/interfaces/IChunkLoader.java @@ -0,0 +1,33 @@ +package gtPlusPlus.api.interfaces; + +import java.util.Set; + +import net.minecraft.world.ChunkCoordIntPair; + +public interface IChunkLoader { + + public long getTicksRemaining(); + + public void setTicksRemaining(long aTicks); + + public ChunkCoordIntPair getResidingChunk(); + + public void setResidingChunk(ChunkCoordIntPair aCurrentChunk); + + public boolean getChunkLoadingActive(); + + public void setChunkLoadingActive(boolean aActive); + + public boolean getDoesWorkChunkNeedReload(); + + public void setDoesWorkChunkNeedReload(boolean aActive); + + public boolean addChunkToLoadedList(ChunkCoordIntPair aActiveChunk); + + public boolean removeChunkFromLoadedList(ChunkCoordIntPair aActiveChunk); + + public Set getManagedChunks(); + + public int getChunkloaderTier(); + +} diff --git a/src/Java/gtPlusPlus/api/interfaces/IChunkLoaderTile.java b/src/Java/gtPlusPlus/api/interfaces/IChunkLoaderTile.java deleted file mode 100644 index 16152668fc..0000000000 --- a/src/Java/gtPlusPlus/api/interfaces/IChunkLoaderTile.java +++ /dev/null @@ -1,10 +0,0 @@ -package gtPlusPlus.api.interfaces; - -import net.minecraft.inventory.IInventory; -import net.minecraft.world.chunk.storage.IChunkLoader; - -public interface IChunkLoaderTile extends IInventory, IChunkLoader{ - - long getTicksRemaining(); - -} diff --git a/src/Java/gtPlusPlus/core/chunkloading/GTPP_ChunkManager.java b/src/Java/gtPlusPlus/core/chunkloading/GTPP_ChunkManager.java new file mode 100644 index 0000000000..ddfe9b8227 --- /dev/null +++ b/src/Java/gtPlusPlus/core/chunkloading/GTPP_ChunkManager.java @@ -0,0 +1,217 @@ +package gtPlusPlus.core.chunkloading; + +import com.google.common.collect.HashMultimap; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.GT_Mod; +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_Log; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.api.interfaces.IChunkLoader; +import gtPlusPlus.core.lib.CORE; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * This class handles re-initializing chunks after a server restart + * Credits to Repo-Alt for the original implementation. + * @author Repo-Alt, Alkalus + * + */ +public class GTPP_ChunkManager implements ForgeChunkManager.OrderedLoadingCallback, ForgeChunkManager.PlayerOrderedLoadingCallback { + + + private Map registeredTickets = new HashMap<>(); + + private static GTPP_ChunkManager instance = new GTPP_ChunkManager(); + + public static boolean enableChunkloaders = true; + public static boolean alwaysReloadChunkloaders = false; + public static boolean debugChunkloaders = false; + + public static void init() { + if (enableChunkloaders) { + ForgeChunkManager.setForcedChunkLoadingCallback(GTplusplus.instance, instance); + } + } + + @Override + public void ticketsLoaded(List tickets, World world) {} + + // Determine if tickets should be kept. Based on if the ticket is a machine or working chunk ticket. + // Working chunk tickets are tossed and re-created when the machine re-activates. + // Machine tickets are kept only if the config alwaysReloadChunkloaders is true. Otherwise + // machine chunks are tossed and re-created only when the machine re-activates, similar to a Passive Anchor. + @Override + public List ticketsLoaded(List tickets, World world, int maxTicketCount) { + List validTickets = new ArrayList<>(); + if (alwaysReloadChunkloaders) { + for (Ticket ticket : tickets) { + int x = ticket.getModData().getInteger("OwnerX"); + int y = ticket.getModData().getInteger("OwnerY"); + int z = ticket.getModData().getInteger("OwnerZ"); + if (y > 0) { + TileEntity tile = world.getTileEntity(x, y, z); + if (tile != null && tile instanceof IGregTechTileEntity && ((IGregTechTileEntity)tile).isAllowedToWork()) { + ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(x >> 4, z >> 4)); + if (!registeredTickets.containsKey(tile)) { + registeredTickets.put(tile, ticket); + if (((IGregTechTileEntity)tile).getMetaTileEntity() instanceof IChunkLoader) { + ForgeChunkManager.forceChunk(ticket, ((IChunkLoader)((IGregTechTileEntity)tile).getMetaTileEntity()).getResidingChunk()); + } + validTickets.add(ticket); + } + } + } + } + } + return validTickets; + } + + // Determine if player tickets should be kept. This is where a ticket list per player would be created and maintained. When + // a player join event occurs, their name/UUID/whatevs is compared against tickets on this list and those tickets reactivated. + // Since that info would be maintained/dealt with on a per-player startup, the list returned back to Forge is empty. + @Override + public ListMultimap playerTicketsLoaded(ListMultimap tickets, World world) { + // Not currently used, so just return an empty list. + return ArrayListMultimap.create(); + } + + // Request a chunk to be loaded for this machine + // may pass null chunk to load just the machine itself, if "alwaysReloadChunkloaders" is enabled in config + static public boolean requestPlayerChunkLoad(TileEntity owner, ChunkCoordIntPair chunkXZ, String player) { + if (!enableChunkloaders) { + return false; + } + if (!alwaysReloadChunkloaders && chunkXZ == null) { + return false; + } + if (debugChunkloaders && chunkXZ != null) { + GT_Log.out.println("GT_ChunkManager: Chunk request: (" + chunkXZ.chunkXPos + ", " + chunkXZ.chunkZPos + ")"); + } + if (instance.registeredTickets.containsKey(owner)) { + ForgeChunkManager.forceChunk(instance.registeredTickets.get(owner), chunkXZ); + } + else { + Ticket ticket = null; + if (player != "") { + ticket = ForgeChunkManager.requestPlayerTicket(GT_Mod.instance, player, owner.getWorldObj(), ForgeChunkManager.Type.NORMAL); + } + else { + ticket = ForgeChunkManager.requestTicket(GT_Mod.instance, owner.getWorldObj(), ForgeChunkManager.Type.NORMAL); + } + if (ticket == null) { + if (debugChunkloaders) { + GT_Log.out.println("GT_ChunkManager: ForgeChunkManager.requestTicket failed"); + } + return false; + } + if (debugChunkloaders) { + GT_Log.out.println("GT_ChunkManager: ticket issued for machine at: (" + owner.xCoord + ", " + owner.yCoord + ", " + owner.zCoord + ")" ); + } + NBTTagCompound tag = ticket.getModData(); + tag.setInteger("OwnerX", owner.xCoord); + tag.setInteger("OwnerY", owner.yCoord); + tag.setInteger("OwnerZ", owner.zCoord); + ForgeChunkManager.forceChunk(ticket, chunkXZ); + if (alwaysReloadChunkloaders) { + ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(owner.xCoord << 4, owner.zCoord << 4)); + } + instance.registeredTickets.put(owner, ticket); + } + return true; + } + + static public boolean requestChunkLoad(TileEntity owner, ChunkCoordIntPair chunkXZ) { + return requestPlayerChunkLoad(owner, chunkXZ, ""); + } + + static public void releaseChunk(TileEntity owner, ChunkCoordIntPair chunkXZ) { + if (!enableChunkloaders) { + return; + } + Ticket ticket = instance.registeredTickets.get(owner); + if (ticket != null) { + if (debugChunkloaders) { + GT_Log.out.println("GT_ChunkManager: Chunk release: (" + chunkXZ.chunkXPos + ", " + chunkXZ.chunkZPos + ")"); + } + ForgeChunkManager.unforceChunk(ticket, chunkXZ); + } + } + + static public void releaseTicket(TileEntity owner) { + if (!enableChunkloaders) { + return; + } + Ticket ticket = instance.registeredTickets.get(owner); + if (ticket != null) { + if (debugChunkloaders) { + GT_Log.out.println("GT_ChunkManager: ticket released by machine at: (" + owner.xCoord + ", " + owner.yCoord + ", " + owner.zCoord + ")" ); + for (ChunkCoordIntPair chunk : ticket.getChunkList()) { + GT_Log.out.println("GT_ChunkManager: Chunk release: (" + chunk.chunkXPos + ", " + chunk.chunkZPos + ")"); + } + } + ForgeChunkManager.releaseTicket(ticket); + instance.registeredTickets.remove(owner); + } + } + + public static void printTickets() { + if (!debugChunkloaders) { + return; + } + GT_Log.out.println("GT_ChunkManager: Start forced chunks dump:"); + instance.registeredTickets.forEach((machine, ticket) -> { + GT_Log.out.print("GT_ChunkManager: Chunks forced by the machine at (" + machine.xCoord + ", " + machine.yCoord + ", " + machine.zCoord + ")"); + if (ticket.isPlayerTicket()) { + GT_Log.out.print(" Owner: " + ticket.getPlayerName()); + } + GT_Log.out.print(" :"); + for (ChunkCoordIntPair c : ticket.getChunkList()) { + GT_Log.out.print("("); + GT_Log.out.print(c.chunkXPos); + GT_Log.out.print(", "); + GT_Log.out.print(c.chunkZPos); + GT_Log.out.print("), "); + } + }); + GT_Log.out.println("GT_ChunkManager: End forced chunks dump:"); + } + public static class DebugCommand extends CommandBase { + @Override + public String getCommandName() { + return "gtpp:dump_chunks"; + } + @Override + public int getRequiredPermissionLevel() { + return 0; + } + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getCommandName(); + } + @Override + public void processCommand(ICommandSender sender, String[] args) { + printTickets(); + } + } +} 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(); + } + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java b/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java index 7c395392a3..573937aeee 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java @@ -466,7 +466,7 @@ public enum GregtechItemList implements GregtechItemContainer { Super_Chest_LV, Super_Chest_MV, Super_Chest_HV, Super_Chest_EV, Super_Chest_IV, //Chunkloader - GT_Chunkloader_HV, GT_Chunkloader_EV, GT_Chunkloader_IV, + GT_Chunkloader_HV, GT_Chunkloader_ZPM, GT_Chunkloader_IV, //Wireless Chargers diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java index 10a1f96be7..33c6bacbd4 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -71,13 +71,11 @@ public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_Basi super(aName, aTier, 2, aDescription, aTextures, 2, 0, aGUIName, aNEIName); }*/ - @SuppressWarnings("deprecation") @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GregtechMetaAtmosphericReconditioner(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); } - @SuppressWarnings("deprecation") @Override public String[] getDescription() { 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 10023722c0..2a2b6d5090 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 @@ -1,122 +1,165 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; import static gregtech.api.enums.GT_Values.V; +import static gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils.mPollution; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; +import java.util.HashSet; import java.util.Set; -import java.util.UUID; -import com.google.common.collect.MapMaker; -import com.google.common.collect.UnmodifiableIterator; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraftforge.common.ForgeChunkManager; -import net.minecraftforge.common.ForgeChunkManager.Ticket; -import net.minecraftforge.common.ForgeChunkManager.Type; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; import gregtech.api.objects.GT_RenderedTexture; -import gtPlusPlus.GTplusplus; -import gtPlusPlus.api.interfaces.IGregtechPacketEntity; -import gtPlusPlus.core.handler.chunkloading.ChunkManager; -import gtPlusPlus.core.util.minecraft.network.PacketBuilder; - -public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredMachineBlock implements IGregtechPacketEntity { - - @SuppressWarnings("unused") - private final static int yMin = 0; - private final static int yMax = 254; - private final int xMin, xMax; - private final int zMin, zMax; - - 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; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.interfaces.IChunkLoader; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.chunkloading.GTPP_ChunkManager; +import gtPlusPlus.core.chunkloading.StaticChunkFunctions; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_BasicMachine implements IChunkLoader { + + public GregtechMetaTileEntityChunkLoader(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, 2, "Loads " + getMaxChunksToLoadForTier(aTier) + " chunks when powered", 0, 0, "Recycler.png", "", + new ITexture[]{ + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB) + }); } - 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; + public GregtechMetaTileEntityChunkLoader(String aName, int aTier, String aDescription, ITexture[][][] aTextures, String aGUIName, String aNEIName) { + super(aName, aTier, 2, aDescription, aTextures, 0, 0, aGUIName, aNEIName); } - @Override - public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { - return new GregtechMetaTileEntityChunkLoader(this.mName, this.mTier, this.mInventory.length, this.mDescription, this.mTextures); + public static int getMaxChunksToLoadForTier(int aTier) { + return (aTier * aTier); } @Override - public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { - return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], (aSide != 1) ? null : aActive ? new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TELEPORTER_ACTIVE) : new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TELEPORTER)}; + public String[] getDescription() { + return new String[] { + this.mDescription, + }; } @Override - public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { - + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; } @Override - public void onRemoval() { - + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final byte aFacing, final byte aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (aSide == aFacing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) ? 1 : aSide == 0 ? 2 : aSide == 1 ? 3 : 4)][aColorIndex + 1]; } - @Override - public boolean isSimpleMachine() { - return false; + + public ITexture[] getFront(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; } - @Override - public boolean isFacingValid(final byte aFacing) { - return aFacing > 1; + + public ITexture[] getBack(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; } - @Override - public boolean isEnetInput() { - return true; + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; } - @Override - public boolean isInputFacing(final byte aSide) { - return true; + + public ITexture[] getTop(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; } - @Override - public boolean isTeleporterCompatible() { - return false; + + public ITexture[] getSides(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3)}; } - @Override - public long getMinimumStoredEU() { - return 512; + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_RedSteel)}; + } + + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; + } + + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Grisium)}; + } + + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], new GT_RenderedTexture(TexturesGtBlock.Casing_Redox_3)}; } @Override - public long maxEUStore() { - return 512 + (V[this.mTier] * 50); + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + PlayerUtils.messagePlayer(aPlayer, "Running every "+" minutes."); + super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); } @Override - public long maxEUInput() { - return V[this.mTier]; + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityChunkLoader(this.mName, this.mTier, this.mDescription, this.mTextures, this.mGUIName, this.mNEIName); } @Override - public long maxAmperesIn() { - return 2; + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()){ + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn){ + //PlayerUtils.messagePlayer(playerIn, "Running every "+mFrequency+" minutes. Owner: "+this.getBaseMetaTileEntity().getOwnerName()); + //PlayerUtils.messagePlayer(playerIn, "Last run: "+Utils.getSecondsFromMillis(aDiff)+" seconds ago."); } @Override @@ -129,230 +172,230 @@ public class GregtechMetaTileEntityChunkLoader extends GT_MetaTileEntity_TieredM return false; } + @Override - public ITexture[][][] getTextureSet(final ITexture[] aTextures) { - return new ITexture[0][0][0]; + public String[] getInfoData() { + return new String[] { + this.getLocalName() + }; } @Override - public void saveNBTData(final NBTTagCompound aNBT) { - + public boolean isGivingInformation() { + return true; } @Override - public void loadNBTData(final NBTTagCompound aNBT) { - + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; } - - - - - /** - * Chunkloading Code from Railcraft - */ - - private static final Map tickets = new MapMaker().makeMap(); - private static final byte MAX_CHUNKS = 25; - private static final byte ANCHOR_RADIUS = 1; - private int prevX; - private int prevY; - private int prevZ; - private Set chunks; - private boolean hasTicket; - private boolean refreshTicket; - private boolean powered; - private UUID uuid; - private int xCoord, yCoord, zCoord; - - public UUID getUUID() { - if (this.uuid == null) { - this.uuid = UUID.randomUUID(); - } - return this.uuid; + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; } - private boolean sendClientUpdate = false; - - public void sendUpdateToClient(IGregTechTileEntity aBaseMetaTileEntity) { - if (aBaseMetaTileEntity.hasWorkJustBeenEnabled()) { - this.sendClientUpdate = true; - } else { - PacketBuilder.instance().sendTileEntityPacket(aBaseMetaTileEntity); - } + @Override + public int getSizeInventory() { + return 0; + } + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return true; } - @Override - public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { - super.onPostTick(aBaseMetaTileEntity, aTimer); - if (!aBaseMetaTileEntity.isServerSide()) { - return; - } - else { - if (this.xCoord != this.prevX || this.yCoord != this.prevY || this.zCoord != this.prevZ) { - this.releaseTicket(aBaseMetaTileEntity); - this.prevX = this.xCoord; - this.prevY = this.yCoord; - this.prevZ = this.zCoord; - } - - this.powered = meetsTicketRequirements(); - if (this.hasActiveTicket() && (this.getTicket().world != aBaseMetaTileEntity.getWorld() || this.refreshTicket || !this.powered)) { - this.releaseTicket(aBaseMetaTileEntity); - } - if (!this.hasActiveTicket()) { - this.requestTicket(aBaseMetaTileEntity); + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + // Have we set the Chunk this Tile resides in yet? + if (mCurrentChunk == null) { + int xTile = getBaseMetaTileEntity().getXCoord(); + int zTile = getBaseMetaTileEntity().getZCoord(); + createInitialWorkingChunk(aBaseMetaTileEntity, xTile, zTile); + } + + // Try unload all chunks if fail to meet global chunkloading conditions. + if (StaticChunkFunctions.onPostTick(aBaseMetaTileEntity, aTick)) { + // Can this tile actively chunkload? + if (getChunkLoadingActive()) { + // Consume some power + this.setEUVar(this.getEUVar() - (maxEUInput() * maxAmperesIn())); + + // Do we need to re-request tickets? + if (getDoesWorkChunkNeedReload()) { + // Request ticket for current chunk. + GTPP_ChunkManager.requestChunkLoad((TileEntity)getBaseMetaTileEntity(), mCurrentChunk); + // Request a ticket for each chunk we have mapped out in a spiral pattern. + if (!mLoadedChunks.isEmpty()) { + for (ChunkCoordIntPair Y : mLoadedChunks) { + GTPP_ChunkManager.requestChunkLoad((TileEntity)getBaseMetaTileEntity(), Y); + } + } + setDoesWorkChunkNeedReload(false); + } + } - } - if (this.sendClientUpdate) { - this.sendClientUpdate = false; - PacketBuilder.instance().sendTileEntityPacket(aBaseMetaTileEntity); - } + } } - public void validate() { - this.refreshTicket = true; + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + StaticChunkFunctions.saveNBTDataForTileEntity(this.getBaseMetaTileEntity(), aNBT); } - protected void releaseTicket(IGregTechTileEntity aBaseMetaTileEntity) { - this.refreshTicket = false; - this.setTicket(aBaseMetaTileEntity, (Ticket) null); + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + StaticChunkFunctions.loadNBTDataForTileEntity(this.getBaseMetaTileEntity(), aNBT); } - protected void requestTicket(IGregTechTileEntity aBaseMetaTileEntity) { - if (this.meetsTicketRequirements()) { - Ticket chunkTicket = this.getTicketFromForge(aBaseMetaTileEntity); - if (chunkTicket != null) { - this.setTicketData(aBaseMetaTileEntity, chunkTicket); - this.forceChunkLoading(aBaseMetaTileEntity, chunkTicket); - } - } + @Override + public long maxAmperesIn() { + return 2; } - protected boolean meetsTicketRequirements() { - return this.getEUVar() > (V[this.mTier]*2); - } - - public Ticket getTicketFromForge(IGregTechTileEntity aBaseMetaTileEntity) { - return ForgeChunkManager.requestTicket(GTplusplus.instance, aBaseMetaTileEntity.getWorld(), Type.NORMAL); + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; } - protected void setTicketData(IGregTechTileEntity aBaseMetaTileEntity, Ticket chunkTicket) { - chunkTicket.getModData().setInteger("xCoord", this.xCoord); - chunkTicket.getModData().setInteger("yCoord", this.yCoord); - chunkTicket.getModData().setInteger("zCoord", this.zCoord); - chunkTicket.getModData().setString("type", "StandardChunkLoader"); + @Override + public long maxEUStore() { + return V[mTier] * 256; } - public boolean hasActiveTicket() { - return this.getTicket() != null; + @Override + public long maxEUInput() { + return V[mTier]; } - public Ticket getTicket() { - return (Ticket) tickets.get(this.getUUID()); + + /* + * Chunkloading Vars + */ + + private long mTicksRemainingForChunkloading = -1; + private ChunkCoordIntPair mCurrentChunk; + private Set mLoadedChunks = new HashSet(); + private boolean mRefreshChunkTickets = false; + + @Override + public long getTicksRemaining() { + return -1; } - public void setTicket(IGregTechTileEntity aBaseMetaTileEntity, Ticket t) { - boolean changed = false; - Ticket ticket = this.getTicket(); - if (ticket != t) { - if (ticket != null) { - if (ticket.world == aBaseMetaTileEntity.getWorld()) { - UnmodifiableIterator var4 = ticket.getChunkList().iterator(); - - while (var4.hasNext()) { - ChunkCoordIntPair chunk = (ChunkCoordIntPair) var4.next(); - if (ForgeChunkManager.getPersistentChunksFor(aBaseMetaTileEntity.getWorld()).keys().contains(chunk)) { - ForgeChunkManager.unforceChunk(ticket, chunk); - } - } - - ForgeChunkManager.releaseTicket(ticket); - } - - tickets.remove(this.getUUID()); - } - - changed = true; - } - - this.hasTicket = t != null; - if (this.hasTicket) { - tickets.put(this.getUUID(), t); - } - - if (changed) { - this.sendUpdateToClient(aBaseMetaTileEntity); - } - + @Override + public void setTicksRemaining(long aTicks) { + mTicksRemainingForChunkloading = aTicks; } - - public void forceChunkLoading(IGregTechTileEntity aBaseMetaTileEntity, Ticket ticket) { - this.setTicket(aBaseMetaTileEntity, ticket); - this.setupChunks(); - if (this.chunks != null) { - Iterator var2 = this.chunks.iterator(); - while (var2.hasNext()) { - ChunkCoordIntPair chunk = (ChunkCoordIntPair) var2.next(); - ForgeChunkManager.forceChunk(ticket, chunk); - } - } + + @Override + public ChunkCoordIntPair getResidingChunk() { + return mCurrentChunk; } - - public void setupChunks() { - if (!this.hasTicket) { - this.chunks = null; - } - else { - this.chunks = ChunkManager.getInstance().getChunksAround(this.xCoord >> 4, this.zCoord >> 4, 1); - } + + @Override + public void setResidingChunk(ChunkCoordIntPair aCurrentChunk) { + mCurrentChunk = aCurrentChunk; } @Override - public void onExplosion() { - this.releaseTicket(this.getBaseMetaTileEntity()); - super.onExplosion(); + public boolean getChunkLoadingActive() { + return this.getEUVar() >= maxEUInput() * maxAmperesIn(); } @Override - public void onValueUpdate(byte aValue) { - super.onValueUpdate(aValue); + public void setChunkLoadingActive(boolean aActive) { + } @Override - public void onMachineBlockUpdate() { - super.onMachineBlockUpdate(); + public boolean getDoesWorkChunkNeedReload() { + return mRefreshChunkTickets; } @Override - public void markDirty() { - this.refreshTicket = true; - super.markDirty(); + public void setDoesWorkChunkNeedReload(boolean aActive) { + mRefreshChunkTickets = aActive; } @Override - public boolean connectsToItemPipe(byte aSide) { - return false; + public boolean addChunkToLoadedList(ChunkCoordIntPair aActiveChunk) { + return mLoadedChunks.add(aActiveChunk); } @Override - public void doExplosion(long aExplosionPower) { - this.releaseTicket(this.getBaseMetaTileEntity()); - super.doExplosion(aExplosionPower); + public boolean removeChunkFromLoadedList(ChunkCoordIntPair aActiveChunk) { + return mLoadedChunks.remove(aActiveChunk); } - public void writePacketData(DataOutputStream data) throws IOException { - data.writeBoolean(this.hasTicket); + @Override + public Set getManagedChunks() { + return mLoadedChunks; } - public void readPacketData(DataInputStream data) throws IOException { - boolean tick = data.readBoolean(); - if (this.hasTicket != tick) { - this.hasTicket = tick; - this.markDirty(); + @Override + public void onRemoval() { + StaticChunkFunctions.onRemoval(getBaseMetaTileEntity()); + super.onRemoval(); + } + + public static Set spiralChunks(final IGregTechTileEntity aBaseMetaTileEntity, int X, int Z) { + World w = aBaseMetaTileEntity.getWorld(); + HashSet aSet = new HashSet(); + if (w == null) { + return aSet; } - this.setupChunks(); + Chunk thisChunk = w.getChunkFromBlockCoords(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getZCoord()); + ChunkCoordIntPair aChunkCo = new ChunkCoordIntPair(thisChunk.xPosition, thisChunk.zPosition); + int x,z,dx,dz; + x = z = dx =0; + dz = -1; + int t = Math.max(X,Z); + int maxI = t*t; + for(int i =0; i < maxI; i++){ + if ((-X/2 <= x) && (x <= X/2) && (-Z/2 <= z) && (z <= Z/2)){ + Chunk C = w.getChunkFromChunkCoords(aChunkCo.chunkXPos + x, aChunkCo.chunkZPos + z); + if (C != null) { + aSet.add(new ChunkCoordIntPair(C.xPosition, C.zPosition)); + } + } + if( (x == z) || ((x < 0) && (x == -z)) || ((x > 0) && (x == 1-z))){ + t = dx; + dx = -dz; + dz = t; + } + x += dx; + z += dz; + } + return aSet; } -} + + @Override + public int getChunkloaderTier() { + return mTier; + } + + public void createInitialWorkingChunk(IGregTechTileEntity aBaseMetaTileEntity, int aTileX, int aTileZ) { + final int centerX = aTileX >> 4; + final int centerZ = aTileZ >> 4; + addChunkToLoadedList(new ChunkCoordIntPair(centerX, centerZ)); + GTPP_ChunkManager.requestChunkLoad((TileEntity)aBaseMetaTileEntity.getMetaTileEntity(), getResidingChunk()); + // If this surrounding chunk map for this tile is empty, we spiral out and map chunks to keep loaded. + if (getManagedChunks().isEmpty()) { + int aChunks = GregtechMetaTileEntityChunkLoader.getMaxChunksToLoadForTier(getChunkloaderTier()); + mLoadedChunks.addAll(spiralChunks(aBaseMetaTileEntity, getChunkloaderTier(), getChunkloaderTier())); + } + if (!mLoadedChunks.isEmpty()) { + for (ChunkCoordIntPair Y : mLoadedChunks) { + GTPP_ChunkManager.requestChunkLoad((TileEntity)aBaseMetaTileEntity.getMetaTileEntity(), Y); + } + } + setDoesWorkChunkNeedReload(false); + } + + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechTieredChunkloaders.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechTieredChunkloaders.java index 84f0adc275..bbfd568e54 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechTieredChunkloaders.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechTieredChunkloaders.java @@ -11,7 +11,6 @@ public class GregtechTieredChunkloaders { Logger.INFO("Gregtech5u Content | Registering Chunk Loaders."); run1(); } - } private static void run1() { @@ -19,11 +18,11 @@ public class GregtechTieredChunkloaders { GregtechItemList.GT_Chunkloader_HV .set(new GregtechMetaTileEntityChunkLoader(ID++, "chunkloader.tier.01", "Chunkloader MK I", 3) .getStackForm(1L)); - GregtechItemList.GT_Chunkloader_EV - .set(new GregtechMetaTileEntityChunkLoader(ID++, "chunkloader.tier.02", "Chunkloader MK II", 4) - .getStackForm(1L)); GregtechItemList.GT_Chunkloader_IV - .set(new GregtechMetaTileEntityChunkLoader(ID++, "chunkloader.tier.03", "Chunkloader MK III", 5) + .set(new GregtechMetaTileEntityChunkLoader(ID++, "chunkloader.tier.02", "Chunkloader MK II", 5) + .getStackForm(1L)); + GregtechItemList.GT_Chunkloader_ZPM + .set(new GregtechMetaTileEntityChunkLoader(ID++, "chunkloader.tier.03", "Chunkloader MK III", 7) .getStackForm(1L)); } } -- cgit From 0ebbaf88ecce9a0e6fcd84498a0e4f1bcf387331 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 31 Dec 2019 15:22:02 +0000 Subject: + Added the Adv. DT. (Locked to T1 for now) + Added 10 new casing blocks, with assembler recipes. - Removed obsolete Chunkloading classes. --- src/Java/gtPlusPlus/GTplusplus.java | 14 - .../api/objects/minecraft/ChunkManager.java | 459 --------------------- src/Java/gtPlusPlus/core/block/ModBlocks.java | 2 + src/Java/gtPlusPlus/core/common/CommonProxy.java | 5 - .../core/handler/chunkloading/ChunkLoading.java | 57 --- .../core/handler/chunkloading/ChunkManager.java | 153 ------- .../gtPlusPlus/core/recipe/RECIPES_Machines.java | 34 ++ src/Java/gtPlusPlus/core/recipe/common/CI.java | 2 +- .../xmod/gregtech/api/enums/GregtechItemList.java | 9 + .../blocks/GregtechMetaTieredCasingBlocks1.java | 111 +++++ .../common/blocks/textures/TexturesGtBlock.java | 22 + ...egtechMetaTileEntity_Adv_DistillationTower.java | 374 +++++++++++++++++ .../xmod/gregtech/loaders/Gregtech_Blocks.java | 9 +- .../GregtechFactoryGradeReplacementMultis.java | 6 + .../gregtech/GregtechFluidReactor.java | 25 +- 15 files changed, 578 insertions(+), 704 deletions(-) delete mode 100644 src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java delete mode 100644 src/Java/gtPlusPlus/core/handler/chunkloading/ChunkLoading.java delete mode 100644 src/Java/gtPlusPlus/core/handler/chunkloading/ChunkManager.java create mode 100644 src/Java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaTieredCasingBlocks1.java create mode 100644 src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index 5828cc9ac2..7f22ac179e 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -37,7 +37,6 @@ import gtPlusPlus.core.common.CommonProxy; import gtPlusPlus.core.config.ConfigHandler; import gtPlusPlus.core.handler.BookHandler; import gtPlusPlus.core.handler.Recipes.RegistrationHandler; -import gtPlusPlus.core.handler.chunkloading.ChunkLoading; import gtPlusPlus.core.handler.events.BlockEventHandler; import gtPlusPlus.core.handler.events.LoginEventHandler; import gtPlusPlus.core.handler.events.MissingMappingsEvent; @@ -47,7 +46,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.nuclear.FLUORIDES; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.data.LocaleUtils; -import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.HazmatUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.RecipeUtils; @@ -66,7 +64,6 @@ import gtPlusPlus.xmod.gregtech.registration.gregtech.GregtechMiniRaFusion; import gtPlusPlus.xmod.thaumcraft.commands.CommandDumpAspects; import net.minecraft.launchwrapper.Launch; import net.minecraft.util.IIcon; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; @MCVersion(value = "1.7.10") @@ -116,9 +113,6 @@ public class GTplusplus implements ActionListener { //GT++ Proxy Instances @SidedProxy(clientSide = "gtPlusPlus.core.proxy.ClientProxy", serverSide = "gtPlusPlus.core.proxy.ServerProxy") public static CommonProxy proxy; - - //Chunk handler - public static ChunkLoading mChunkLoading; // Loads Textures @SideOnly(value = Side.CLIENT) @@ -138,7 +132,6 @@ public class GTplusplus implements ActionListener { public GTplusplus() { super(); INIT_PHASE.SUPER.setPhaseActive(true); - mChunkLoading = new ChunkLoading(); } // Pre-Init @@ -176,9 +169,6 @@ public class GTplusplus implements ActionListener { Utils.registerEvent(new MissingMappingsEvent()); Logger.INFO("Login Handler Initialized"); - - - mChunkLoading.preInit(event); proxy.preInit(event); Logger.INFO("Setting up our own GT_Proxy."); Meta_GT_Proxy.preInit(); @@ -190,7 +180,6 @@ public class GTplusplus implements ActionListener { @Mod.EventHandler public void init(final FMLInitializationEvent event) { INIT_PHASE.INIT.setPhaseActive(true); - mChunkLoading.init(event); proxy.init(event); HazmatUtils.init(); proxy.registerNetworkStuff(); @@ -208,7 +197,6 @@ public class GTplusplus implements ActionListener { @Mod.EventHandler public void postInit(final FMLPostInitializationEvent event) { INIT_PHASE.POST_INIT.setPhaseActive(true); - mChunkLoading.postInit(event); proxy.postInit(event); BookHandler.runLater(); Meta_GT_Proxy.postInit(); @@ -231,7 +219,6 @@ public class GTplusplus implements ActionListener { @EventHandler public synchronized void serverStarting(final FMLServerStartingEvent event) { INIT_PHASE.SERVER_START.setPhaseActive(true); - mChunkLoading.serverStarting(event); event.registerServerCommand(new CommandMath()); event.registerServerCommand(new CommandEnableDebugWhileRunning()); event.registerServerCommand(new CommandDebugChunks()); @@ -247,7 +234,6 @@ public class GTplusplus implements ActionListener { @Mod.EventHandler public synchronized void serverStopping(final FMLServerStoppingEvent event) { - mChunkLoading.serverStopping(event); Core_Manager.serverStop(); if (GregtechBufferThread.mBufferThreadAllocation.size() > 0) { for (GregtechBufferThread i : GregtechBufferThread.mBufferThreadAllocation.values()) { diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java deleted file mode 100644 index 826f0c5106..0000000000 --- a/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java +++ /dev/null @@ -1,459 +0,0 @@ -/* - * Copyright (c) CovertJaguar, 2014 http://railcraft.info - * - * This code is the property of CovertJaguar - * and may only be used with explicit written - * permission unless otherwise specified on the - * license page at http://railcraft.info/wiki/info:license. - */ -package gtPlusPlus.api.objects.minecraft; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -import com.google.common.collect.LinkedListMultimap; -import com.google.common.collect.ListMultimap; - -import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.event.FMLServerStartingEvent; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.TickEvent; - -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.ChunkCoordIntPair; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; - -import gregtech.api.GregTech_API; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; - -import gtPlusPlus.GTplusplus; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.ReverseAutoMap; -import gtPlusPlus.api.objects.data.Triplet; -import gtPlusPlus.core.util.Utils; -import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaTileEntityChunkLoader; -import net.minecraftforge.common.ForgeChunkManager; -import net.minecraftforge.common.ForgeChunkManager.*; -import net.minecraftforge.event.entity.EntityEvent; - -/** - * @author CovertJaguar - */ -public class ChunkManager implements LoadingCallback, OrderedLoadingCallback, ForgeChunkManager.PlayerOrderedLoadingCallback { - - private static final ChunkManager instance; - private static ReverseAutoMap mIdToUUIDMap = new ReverseAutoMap(); - - public Timer mChunkQueue; - public static ConcurrentHashMap> mChunkLoaderManagerMap = new ConcurrentHashMap>(); - private static long mInternalTickCounter = 0; - - static { - instance = new ChunkManager(); - Logger.REFLECTION("Created ChunkManager object."); - } - - private ChunkManager() { - Utils.registerEvent(this); - } - - public static void clearInternalMaps() { - mIdToUUIDMap.clear(); - mChunkLoaderManagerMap.clear(); - } - - public static boolean setIdAndUniqueString(int id, String blockposString) { - if (mIdToUUIDMap.injectCleanDataToAutoMap(id, blockposString)) { - Logger.INFO("Found Cached ID from NBT, cleanly injected into ChunkManager."); - return true; - } - else { - Logger.INFO("ID in use, best try a few times to get a free ID."); - for (int u=0;u - * One of the pairs of start/end coords need to be equal. - *

- * Coordinates are in chunk coordinates, not world coordinates. - * - * @param xChunkA Start Chunk x-Coord - * @param zChunkA Start Chunk z-Coord - * @param xChunkB End Chunk x-Coord - * @param zChunkB End Chunk z-Coord - * @param max Max number of chunks to return - * @return A set of chunks. - */ - public Set getChunksBetween(int xChunkA, int zChunkA, int xChunkB, int zChunkB, int max) { - Set chunkList = new HashSet(); - - if (xChunkA != xChunkB && zChunkA != zChunkB) { - return chunkList; - } - - int xStart = Math.min(xChunkA, xChunkB); - int xEnd = Math.max(xChunkA, xChunkB