diff options
Diffstat (limited to 'src/Java/gtPlusPlus/core/handler')
-rw-r--r-- | src/Java/gtPlusPlus/core/handler/chunkloading/ChunkLoading.java | 57 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/handler/chunkloading/ChunkManager.java | 153 |
2 files changed, 210 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/handler/chunkloading/ChunkLoading.java b/src/Java/gtPlusPlus/core/handler/chunkloading/ChunkLoading.java new file mode 100644 index 0000000000..bc690f250c --- /dev/null +++ b/src/Java/gtPlusPlus/core/handler/chunkloading/ChunkLoading.java @@ -0,0 +1,57 @@ +package gtPlusPlus.core.handler.chunkloading; + +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.event.FMLServerStoppingEvent; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.ChunkManager; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.network.PacketHandler; +import net.minecraftforge.common.ForgeChunkManager; + +public class ChunkLoading { + + private final ChunkLoading instance; + + public ChunkLoading() { + instance = this; + } + + public ChunkLoading getInstance() { + return this.instance; + } + + + public void preInit(final FMLPreInitializationEvent event) { + PacketHandler.init(); + ForgeChunkManager.setForcedChunkLoadingCallback(GTplusplus.instance, ChunkManager.getInstance()); + Utils.registerEvent(ChunkManager.getInstance()); + } + + + public void init(final FMLInitializationEvent event) { + + } + + + public void postInit(final FMLPostInitializationEvent event) { + + } + + + public synchronized void serverStarting(final FMLServerStartingEvent event) { + + } + + public void serverStopping(final FMLServerStoppingEvent event){ + //Chunkload Handler + if (ChunkManager.mChunkLoaderManagerMap.size() > 0) { + Logger.INFO("Clearing Chunk Loaders."); + ChunkManager.clearInternalMaps(); + } + } + +} diff --git a/src/Java/gtPlusPlus/core/handler/chunkloading/ChunkManager.java b/src/Java/gtPlusPlus/core/handler/chunkloading/ChunkManager.java new file mode 100644 index 0000000000..f95c4e7a78 --- /dev/null +++ b/src/Java/gtPlusPlus/core/handler/chunkloading/ChunkManager.java @@ -0,0 +1,153 @@ +package gtPlusPlus.core.handler.chunkloading; + +import com.google.common.collect.LinkedListMultimap; +import com.google.common.collect.ListMultimap; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaTileEntityChunkLoader; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.ChunkCoordIntPair; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeChunkManager.LoadingCallback; +import net.minecraftforge.common.ForgeChunkManager.OrderedLoadingCallback; +import net.minecraftforge.common.ForgeChunkManager.PlayerOrderedLoadingCallback; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.event.entity.EntityEvent.EnteringChunk; + +public class ChunkManager implements LoadingCallback, OrderedLoadingCallback, PlayerOrderedLoadingCallback { + private static ChunkManager instance; + + public static ChunkManager getInstance() { + if (instance == null) { + instance = new ChunkManager(); + } + + return instance; + } + + @SubscribeEvent + public void entityEnteredChunk(EnteringChunk event) { + + } + + public Set<ChunkCoordIntPair> getChunksBetween(int xChunkA, int zChunkA, int xChunkB, int zChunkB, int max) { + Set<ChunkCoordIntPair> chunkList = new HashSet<ChunkCoordIntPair>(); + if (xChunkA != xChunkB && zChunkA != zChunkB) { + return chunkList; + } else { + int xStart = Math.min(xChunkA, xChunkB); + int xEnd = Math.max(xChunkA, xChunkB); + int zStart = Math.min(zChunkA, zChunkB); + int zEnd = Math.max(zChunkA, zChunkB); + + for (int xx = xStart; xx <= xEnd; ++xx) { + for (int zz = zStart; zz <= zEnd; ++zz) { + chunkList.add(new ChunkCoordIntPair(xx, zz)); + if (chunkList.size() >= max) { + return chunkList; + } + } + } + + return chunkList; + } + } + + public Set<ChunkCoordIntPair> getChunksAround(int xChunk, int zChunk, int radius) { + Set<ChunkCoordIntPair> chunkList = new HashSet<ChunkCoordIntPair>(); + + for (int xx = xChunk - radius; xx <= xChunk + radius; ++xx) { + for (int zz = zChunk - radius; zz <= zChunk + radius; ++zz) { + chunkList.add(new ChunkCoordIntPair(xx, zz)); + } + } + + return chunkList; + } + + public Set<ChunkCoordIntPair> getBufferAround(int xWorld, int zWorld, int radius) { + int minX = xWorld - radius >> 4; + int maxX = xWorld + radius >> 4; + int minZ = zWorld - radius >> 4; + int maxZ = zWorld + radius >> 4; + Set<ChunkCoordIntPair> chunkList = new HashSet<ChunkCoordIntPair>(); + + for (int xx = minX; xx <= maxX; ++xx) { + for (int zz = minZ; zz <= maxZ; ++zz) { + chunkList.add(new ChunkCoordIntPair(xx, zz)); + } + } + + return chunkList; + } + + public void ticketsLoaded(List<Ticket> tickets, World world) { + Iterator<Ticket> var3 = tickets.iterator(); + while (var3.hasNext()) { + Ticket ticket = (Ticket) var3.next(); + if (!ticket.isPlayerTicket()) { + Entity entity = ticket.getEntity(); + if (entity == null) { + int x = ticket.getModData().getInteger("xCoord"); + int y = ticket.getModData().getInteger("yCoord"); + int z = ticket.getModData().getInteger("zCoord"); + if (y >= 0) { + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof IGregTechTileEntity) { + IGregTechTileEntity g = (IGregTechTileEntity) tile; + if (g instanceof GregtechMetaTileEntityChunkLoader) { + GregtechMetaTileEntityChunkLoader t = (GregtechMetaTileEntityChunkLoader) g; + t.forceChunkLoading(t.getBaseMetaTileEntity(), ticket); + // this.printChunkLoader(t.getName(), x, y, z); + } + } + } + } + } + } + } + + public List<Ticket> ticketsLoaded(List<Ticket> tickets, World world, int maxTicketCount) { + Set<Ticket> adminTickets = new HashSet<Ticket>(); + Set<Ticket> worldTickets = new HashSet<Ticket>(); + Set<Ticket> cartTickets = new HashSet<Ticket>(); + Iterator<Ticket> var7 = tickets.iterator(); + + while (var7.hasNext()) { + Ticket ticket = (Ticket) var7.next(); + Entity entity = ticket.getEntity(); + if (entity == null) { + int x = ticket.getModData().getInteger("xCoord"); + int y = ticket.getModData().getInteger("yCoord"); + int z = ticket.getModData().getInteger("zCoord"); + String type = ticket.getModData().getString("type"); + if (y >= 0) { + if (type.equals("AdminChunkLoader")) { + adminTickets.add(ticket); + } else if (type.equals("StandardChunkLoader")) { + worldTickets.add(ticket); + } else if (type.isEmpty()) { + worldTickets.add(ticket); + } + } + } + } + + List<Ticket> claimedTickets = new LinkedList<Ticket>(); + claimedTickets.addAll(cartTickets); + claimedTickets.addAll(adminTickets); + claimedTickets.addAll(worldTickets); + return claimedTickets; + } + + public ListMultimap<String, Ticket> playerTicketsLoaded(ListMultimap<String, Ticket> tickets, World world) { + return LinkedListMultimap.create(); + } +}
\ No newline at end of file |