diff options
| author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-09-01 14:24:32 +1000 |
|---|---|---|
| committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-09-01 14:24:32 +1000 |
| commit | 64bb2d7847ddb4eb9fba868f2b27ccd2c9582a00 (patch) | |
| tree | 095ad534f7a1957902ae68b7521dcc3ea5a1b349 /src/Java/gtPlusPlus | |
| parent | db20475a5973d588a9ef9e52feb22da0f4b92205 (diff) | |
| download | GT5-Unofficial-64bb2d7847ddb4eb9fba868f2b27ccd2c9582a00.tar.gz GT5-Unofficial-64bb2d7847ddb4eb9fba868f2b27ccd2c9582a00.tar.bz2 GT5-Unofficial-64bb2d7847ddb4eb9fba868f2b27ccd2c9582a00.zip | |
$ Reworked the Chunk loaders.
> Maybe they work now?
Diffstat (limited to 'src/Java/gtPlusPlus')
13 files changed, 941 insertions, 390 deletions
diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index 219117fd8f..b6a14acb62 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -21,12 +21,12 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; -import gtPlusPlus.api.objects.minecraft.ChunkManager; import gtPlusPlus.core.commands.CommandMath; 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.*; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; @@ -67,6 +67,9 @@ 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) @@ -78,6 +81,11 @@ public class GTplusplus implements ActionListener { // Blocks Logger.WARNING("Processing texture: " + TexturesGtBlock.Casing_Machine_Dimensional.getTextureFile().getResourcePath()); } + + public GTplusplus() { + super(); + mChunkLoading = new ChunkLoading(); + } // Pre-Init @Mod.EventHandler @@ -114,7 +122,7 @@ public class GTplusplus implements ActionListener { Logger.INFO("Login Handler Initialized"); - + mChunkLoading.preInit(event); proxy.preInit(event); Core_Manager.preInit(); } @@ -122,6 +130,7 @@ public class GTplusplus implements ActionListener { // Init @Mod.EventHandler public void init(final FMLInitializationEvent event) { + mChunkLoading.init(event); proxy.init(event); proxy.registerNetworkStuff(); @@ -142,6 +151,7 @@ public class GTplusplus implements ActionListener { // Post-Init @Mod.EventHandler public void postInit(final FMLPostInitializationEvent event) { + mChunkLoading.postInit(event); proxy.postInit(event); BookHandler.runLater(); Core_Manager.postInit(); @@ -160,6 +170,7 @@ public class GTplusplus implements ActionListener { @EventHandler public synchronized void serverStarting(final FMLServerStartingEvent event) { + mChunkLoading.serverStarting(event); event.registerServerCommand(new CommandMath()); if (LoadedMods.Thaumcraft) { event.registerServerCommand(new CommandDumpAspects()); @@ -168,12 +179,7 @@ public class GTplusplus implements ActionListener { @Mod.EventHandler public synchronized void serverStopping(final FMLServerStoppingEvent event) { - //Chunkload Handler - if (ChunkManager.mChunkLoaderManagerMap.size() > 0) { - Logger.INFO("Clearing Chunk Loaders."); - ChunkManager.clearInternalMaps(); - } - + mChunkLoading.serverStopping(event); if (GregtechBufferThread.mBufferThreadAllocation.size() > 0) { for (GregtechBufferThread i : GregtechBufferThread.mBufferThreadAllocation.values()) { i.destroy(); diff --git a/src/Java/gtPlusPlus/RoadMap.java b/src/Java/gtPlusPlus/RoadMap.java index 11714ef2cb..47a0116192 100644 --- a/src/Java/gtPlusPlus/RoadMap.java +++ b/src/Java/gtPlusPlus/RoadMap.java @@ -1,12 +1,5 @@ package gtPlusPlus; -import java.util.Iterator; -import java.util.LinkedHashMap; - -import gregtech.api.util.GT_Utility; -import gtPlusPlus.api.objects.data.ObjMap; -import net.minecraft.item.ItemStack; - /** * This Class purely exists to note down ideas and or plans to (re)implement things. * @@ -70,6 +63,32 @@ public class RoadMap { return false; }*/ - +/* private static final LinkedHashMap<String, ObjMap<Integer, Boolean>>mCachedResults = new LinkedHashMap<String, ObjMap<Integer, Boolean>>(); + + public boolean contains(ItemStack aStack) { + if (aStack == null){ + return false; + } + ObjMap<Integer, Boolean> aCurrentSet = mCachedResults.get(this.toString().toUpperCase()); + if (aCurrentSet == null){ + aCurrentSet = new ObjMap<Integer, Boolean>((mPrefixedItems != null && mPrefixedItems.size() > 0 ? mPrefixedItems.size() : 1000), 0.5f); + mCachedResults.put(this.toString().toUpperCase(), aCurrentSet); + } + int mainHash = Objects.hashCode(aStack.getItem(), aStack.getItemDamage()); + Boolean result = aCurrentSet.get(mainHash); + if (result != null){ + return result; + } + else { + for (ItemStack tStack : mPrefixedItems){ + if (GT_Utility.areStacksEqual(aStack, tStack, !tStack.hasTagCompound())){ + aCurrentSet.put(Objects.hashCode(tStack.getItem(), tStack.getItemDamage()), true); + return true; + } + } + } + aCurrentSet.put(mainHash, false); + return false; + }*/ } diff --git a/src/Java/gtPlusPlus/api/interfaces/IGregtechPacketEntity.java b/src/Java/gtPlusPlus/api/interfaces/IGregtechPacketEntity.java new file mode 100644 index 0000000000..fa59c58d9f --- /dev/null +++ b/src/Java/gtPlusPlus/api/interfaces/IGregtechPacketEntity.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.interfaces; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public interface IGregtechPacketEntity { + + public void writePacketData(DataOutputStream data) throws IOException; + + public void readPacketData(DataInputStream data) throws IOException; + +} diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java index b0975dcca7..826f0c5106 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/ChunkManager.java @@ -344,8 +344,8 @@ public class ChunkManager implements LoadingCallback, OrderedLoadingCallback, Fo if (H != null) { ForgeChunkManager.releaseTicket(H); } - f.forceChunkLoading(ticket); - printAnchor("Force Chunk Loading. Chunk Loader has ID of "+f.getLoaderID()+". ",x,y,z); + f.forceChunkLoading(f.getBaseMetaTileEntity(), ticket); + printAnchor("Force Chunk Loading. Chunk Loader has ID of "+f.getUUID().toString()+". ",x,y,z); } else { Logger.INFO("Tile Entity is null."); @@ -445,7 +445,7 @@ public class ChunkManager implements LoadingCallback, OrderedLoadingCallback, Fo for (Triplet<Integer, GregtechMetaTileEntityChunkLoader, DimChunkPos> j : mChunkLoaderManagerMap.values()) { Ticket T; Chunk C; - T = j.getValue_2().getTicketFromForge(); + T = j.getValue_2().getTicketFromForge(j.getValue_2().getBaseMetaTileEntity()); C = j.getValue_3().getChunk(); ForgeChunkManager.forceChunk(T, C.getChunkCoordIntPair()); Logger.INFO("[Chunk Loader] Trying to force load a chunk that holds a chunkloader. [Timer]"); diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java new file mode 100644 index 0000000000..7a3a01b27c --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_ScrollTest.java @@ -0,0 +1,228 @@ +package gtPlusPlus.core.gui.machine; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.Sys; + +import com.google.common.collect.Lists; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiOptionButton; +import net.minecraft.client.gui.GuiResourcePackAvailable; +import net.minecraft.client.gui.GuiResourcePackSelected; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.resources.ResourcePackListEntry; +import net.minecraft.client.resources.ResourcePackListEntryFound; +import net.minecraft.client.resources.ResourcePackRepository; +import net.minecraft.client.resources.ResourcePackRepository.Entry; +import net.minecraft.util.Util; + +@SideOnly(Side.CLIENT) +public class GUI_ScrollTest extends GuiScreen +{ + private static final Logger logger = LogManager.getLogger(); + private GuiScreen aThisGUIScreen; + private List<?> field_146966_g; + private List<?> field_146969_h; + private GuiResourcePackAvailable MapOfFreeResourcePacks; + private GuiResourcePackSelected MapOfActiveResourcePacks; + private static final String __OBFID = "CL_00000820"; + + public GUI_ScrollTest(GuiScreen p_i45050_1_) + { + this.aThisGUIScreen = p_i45050_1_; + } + + /** + * Adds the buttons (and other controls) to the screen in question. + */ + @SuppressWarnings("unchecked") + public void initGui() + { + this.buttonList.add(new GuiOptionButton(2, this.width / 2 - 154, this.height - 48, I18n.format("resourcePack.openFolder", new Object[0]))); + this.buttonList.add(new GuiOptionButton(1, this.width / 2 + 4, this.height - 48, I18n.format("gui.done", new Object[0]))); + this.field_146966_g = new ArrayList<Object>(); + this.field_146969_h = new ArrayList<Entry>(); + ResourcePackRepository resourcepackrepository = this.mc.getResourcePackRepository(); + resourcepackrepository.updateRepositoryEntriesAll(); + ArrayList<?> arraylist = Lists.newArrayList(resourcepackrepository.getRepositoryEntriesAll()); + arraylist.removeAll(resourcepackrepository.getRepositoryEntries()); + Iterator<?> iterator = arraylist.iterator(); + ResourcePackRepository.Entry entry; + + while (iterator.hasNext()) + { + entry = (ResourcePackRepository.Entry)iterator.next(); + //this.field_146966_g.add(new ResourcePackListEntryFound(this, entry)); + } + + iterator = Lists.reverse(resourcepackrepository.getRepositoryEntries()).iterator(); + + while (iterator.hasNext()) + { + entry = (ResourcePackRepository.Entry)iterator.next(); + //this.field_146969_h.add(new ResourcePackListEntryFound(this, entry)); + } + + //this.field_146969_h.add(new ResourcePackListEntryDefault(this)); + this.MapOfFreeResourcePacks = new GuiResourcePackAvailable(this.mc, 200, this.height, this.field_146966_g); + this.MapOfFreeResourcePacks.setSlotXBoundsFromLeft(this.width / 2 - 4 - 200); + this.MapOfFreeResourcePacks.registerScrollButtons(7, 8); + this.MapOfActiveResourcePacks = new GuiResourcePackSelected(this.mc, 200, this.height, this.field_146969_h); + this.MapOfActiveResourcePacks.setSlotXBoundsFromLeft(this.width / 2 + 4); + this.MapOfActiveResourcePacks.registerScrollButtons(7, 8); + } + + public boolean func_146961_a(ResourcePackListEntry p_146961_1_) + { + return this.field_146969_h.contains(p_146961_1_); + } + + public List<?> func_146962_b(ResourcePackListEntry p_146962_1_) + { + return this.func_146961_a(p_146962_1_) ? this.field_146969_h : this.field_146966_g; + } + + public List<?> func_146964_g() + { + return this.field_146966_g; + } + + public List<?> func_146963_h() + { + return this.field_146969_h; + } + + protected void actionPerformed(GuiButton p_146284_1_) + { + if (p_146284_1_.enabled) + { + if (p_146284_1_.id == 2) + { + File file1 = this.mc.getResourcePackRepository().getDirResourcepacks(); + String s = file1.getAbsolutePath(); + + if (Util.getOSType() == Util.EnumOS.OSX) + { + try + { + logger.info(s); + Runtime.getRuntime().exec(new String[] {"/usr/bin/open", s}); + return; + } + catch (IOException ioexception1) + { + logger.error("Couldn\'t open file", ioexception1); + } + } + else if (Util.getOSType() == Util.EnumOS.WINDOWS) + { + String s1 = String.format("cmd.exe /C start \"Open file\" \"%s\"", new Object[] {s}); + + try + { + Runtime.getRuntime().exec(s1); + return; + } + catch (IOException ioexception) + { + logger.error("Couldn\'t open file", ioexception); + } + } + + boolean flag = false; + + try + { + Class<?> oclass = Class.forName("java.awt.Desktop"); + Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]); + oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {file1.toURI()}); + } + catch (Throwable throwable) + { + logger.error("Couldn\'t open link", throwable); + flag = true; + } + + if (flag) + { + logger.info("Opening via system class!"); + Sys.openURL("file://" + s); + } + } + else if (p_146284_1_.id == 1) + { + ArrayList<Entry> arraylist = Lists.newArrayList(); + Iterator<?> iterator = this.field_146969_h.iterator(); + + while (iterator.hasNext()) + { + ResourcePackListEntry resourcepacklistentry = (ResourcePackListEntry)iterator.next(); + + if (resourcepacklistentry instanceof ResourcePackListEntryFound) + { + arraylist.add(((ResourcePackListEntryFound)resourcepacklistentry).func_148318_i()); + } + } + + Collections.reverse(arraylist); + this.mc.getResourcePackRepository().func_148527_a(arraylist); + this.mc.gameSettings.resourcePacks.clear(); + iterator = arraylist.iterator(); + + while (iterator.hasNext()) + { + ResourcePackRepository.Entry entry = (ResourcePackRepository.Entry)iterator.next(); + this.mc.gameSettings.resourcePacks.add(entry.getResourcePackName()); + } + + this.mc.gameSettings.saveOptions(); + this.mc.refreshResources(); + this.mc.displayGuiScreen(this.aThisGUIScreen); + } + } + } + + /** + * Called when the mouse is clicked. + */ + protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_) + { + super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_); + this.MapOfFreeResourcePacks.func_148179_a(p_73864_1_, p_73864_2_, p_73864_3_); + this.MapOfActiveResourcePacks.func_148179_a(p_73864_1_, p_73864_2_, p_73864_3_); + } + + /** + * Called when the mouse is moved or a mouse button is released. Signature: (mouseX, mouseY, which) which==-1 is + * mouseMove, which==0 or which==1 is mouseUp + */ + protected void mouseMovedOrUp(int p_146286_1_, int p_146286_2_, int p_146286_3_) + { + super.mouseMovedOrUp(p_146286_1_, p_146286_2_, p_146286_3_); + } + + /** + * Draws the screen and all the components in it. + */ + public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_) + { + this.drawBackground(0); + this.MapOfFreeResourcePacks.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); + this.MapOfActiveResourcePacks.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); + this.drawCenteredString(this.fontRendererObj, I18n.format("resourcePack.title", new Object[0]), this.width / 2, 16, 16777215); + this.drawCenteredString(this.fontRendererObj, I18n.format("resourcePack.folderInfo", new Object[0]), this.width / 2 - 77, this.height - 26, 8421504); + super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_); + } +}
\ No newline at end of file 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 diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/CustomPacket.java b/src/Java/gtPlusPlus/core/util/minecraft/network/CustomPacket.java new file mode 100644 index 0000000000..def836eac9 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/minecraft/network/CustomPacket.java @@ -0,0 +1,39 @@ +package gtPlusPlus.core.util.minecraft.network; + +import cpw.mods.fml.common.network.internal.FMLProxyPacket; +import io.netty.buffer.Unpooled; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import mods.railcraft.common.util.misc.Game; + +public abstract class CustomPacket { + public static final String CHANNEL_NAME = "GTPP"; + + public enum PacketType { + TILE_ENTITY, + } + + public FMLProxyPacket getPacket() { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + DataOutputStream data = new DataOutputStream(bytes); + try { + data.writeByte(this.getID()); + this.writeData(data); + } catch (IOException var4) { + Game.logThrowable("Error constructing packet: {0}", var4, new Object[]{this.getClass()}); + } + return new FMLProxyPacket(Unpooled.wrappedBuffer(bytes.toByteArray()), "GTPP"); + } + + public abstract void writeData(DataOutputStream var1) throws IOException; + + public abstract void readData(DataInputStream var1) throws IOException; + + public abstract int getID(); + + public String toString() { + return this.getClass().getSimpleName(); + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketBuilder.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketBuilder.java new file mode 100644 index 0000000000..edbc6aaf83 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketBuilder.java @@ -0,0 +1,25 @@ +package gtPlusPlus.core.util.minecraft.network; + +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.world.WorldServer; + +public class PacketBuilder { + + private static PacketBuilder instance; + + public static PacketBuilder instance() { + if (instance == null) { + instance = new PacketBuilder(); + } + return instance; + } + + public void sendTileEntityPacket(IGregTechTileEntity tile) { + if (tile.getWorld() instanceof WorldServer) { + WorldServer world = (WorldServer) tile.getWorld(); + PacketTileEntity pkt = new PacketTileEntity(tile); + PacketDispatcher.sendToWatchers(pkt, world, tile.getXCoord(), tile.getZCoord()); + } + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketDispatcher.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketDispatcher.java new file mode 100644 index 0000000000..3e3801bff3 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketDispatcher.java @@ -0,0 +1,88 @@ +package gtPlusPlus.core.util.minecraft.network; + +import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; +import cpw.mods.fml.relauncher.ReflectionHelper; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.preloader.DevHelper; + +import java.lang.reflect.Method; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.Packet; +import net.minecraft.server.management.PlayerManager; +import net.minecraft.world.WorldServer; + +@SuppressWarnings("unchecked") +public class PacketDispatcher { + private static final Class playerInstanceClass; + private static final Method getOrCreateChunkWatcher; + private static final Method sendToAllPlayersWatchingChunk; + + public static void sendToServer(CustomPacket packet) { + PacketHandler.INSTANCE.channel.sendToServer(packet.getPacket()); + } + + public static void sendToPlayer(CustomPacket packet, EntityPlayerMP player) { + PacketHandler.INSTANCE.channel.sendTo(packet.getPacket(), player); + } + + public static void sendToAll(CustomPacket packet) { + PacketHandler.INSTANCE.channel.sendToAll(packet.getPacket()); + } + + public static void sendToAllAround(CustomPacket packet, TargetPoint zone) { + PacketHandler.INSTANCE.channel.sendToAllAround(packet.getPacket(), zone); + } + + public static void sendToDimension(CustomPacket packet, int dimensionId) { + PacketHandler.INSTANCE.channel.sendToDimension(packet.getPacket(), dimensionId); + } + + public static void sendToWatchers(CustomPacket packet, WorldServer world, int worldX, int worldZ) { + try { + Object playerInstance = getOrCreateChunkWatcher.invoke(world.getPlayerManager(), worldX >> 4, worldZ >> 4, + false); + if (playerInstance != null) { + sendToAllPlayersWatchingChunk.invoke(playerInstance, packet.getPacket()); + } + + } catch (Exception var5) { + Logger.ERROR("Reflection Failure in PacketDispatcher.sendToWatchers() {0} {1}" + 20 + var5 + + new Object[]{getOrCreateChunkWatcher.getName() + sendToAllPlayersWatchingChunk.getName()}); + throw new RuntimeException(var5); + } + } + + static { + try { + playerInstanceClass = PlayerManager.class.getDeclaredClasses()[0]; + + Method a, b; + + try { + a = DevHelper.getInstance().getForgeMethod(PlayerManager.class, "getOrCreateChunkWatcher", int.class, int.class, boolean.class); + } + catch (Throwable t) { + a = ReflectionHelper.findMethod(playerInstanceClass, (Object) null, + new String[]{"func_72690_a", "getOrCreateChunkWatcher"}, + new Class[]{Integer.TYPE, Integer.TYPE, Boolean.TYPE}); + } + try { + b = DevHelper.getInstance().getForgeMethod(PlayerManager.class, "sendToAllPlayersWatchingChunk", Packet.class); + } + catch (Throwable t) { + b = ReflectionHelper.findMethod(playerInstanceClass, (Object) null, + new String[]{"func_151251_a", "sendToAllPlayersWatchingChunk"}, + new Class[]{Packet.class}); + } + + + getOrCreateChunkWatcher = a; + sendToAllPlayersWatchingChunk = b; + getOrCreateChunkWatcher.setAccessible(true); + sendToAllPlayersWatchingChunk.setAccessible(true); + } catch (Exception var1) { + Logger.ERROR("Reflection Failure in PacketDispatcher initalization {0} {1}" + var1); + throw new RuntimeException(var1); + } + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/util/minecraft/network/PacketHandler.java b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketHandler.java new file mode 100644 index 0000000000..158f9f9483 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/minecraft/network/PacketHandler.java @@ -0,0 +1,71 @@ +package gtPlusPlus.core.util.minecraft.network; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.network.FMLEventChannel; +import cpw.mods.fml.common.network.NetworkRegistry; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.minecraft.network.CustomPacket.PacketType; +import cpw.mods.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent; +import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.Arrays; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.NetHandlerPlayServer; + +public class PacketHandler { + public static final PacketHandler INSTANCE = new PacketHandler(); + private static final PacketType[] packetTypes = PacketType.values(); + final FMLEventChannel channel; + + private PacketHandler() { + this.channel = NetworkRegistry.INSTANCE.newEventDrivenChannel("GTPP"); + this.channel.register(this); + } + + public static void init() { + } + + @SubscribeEvent + public void onPacket(ServerCustomPacketEvent event) { + byte[] data = new byte[event.packet.payload().readableBytes()]; |
