Jump to content

FireController1847

Members
  • Posts

    290
  • Joined

  • Last visited

Posts posted by FireController1847

  1. Just now, Draco18s said:

    isRemote is the difference between the logical client and the logical server. Even single player there is still a server thread (the Integrated Server) with 1 player connected.

    PlayerLoggedIn only fires on the logical server.

    Ahh, okay, that makes sense. So now my question is what events would I use to be able to seperate the two? I can use PlayerLoggedInEvent for singleplayer, obviously, as it seems to only happen during singleplayer, but what other event will run for first time login on multiplayer? I can't use WorldEvent.Load, as that fires also on changing dimension (as far as I've read & tested), as well as being unable to fetch the player within that event.

  2. I'm trying to make a mod that requires me to detect when the Client joins a Singleplayer world, and when the Client joins a Multiplayer world. I've used PlayerLoggedInEvent, and have checked if world.isRemote (that being said, I'm not sure I fully understand what isRemote is, as it was false every time I connected to a singleplayer world and was never true even when connecting to a server), and that works fine for singleplayer worlds. When I connect to a server, though, the event doesn't even seem to be called. Here's the code I've been testing:
     

    @SubscribeEvent
      public void onLogin(PlayerLoggedInEvent event) {
      MCDRP.logger.info("WORKING");
      World world = event.player.getEntityWorld();
      if (!world.isRemote) {
        MCDRP.logger.info("World loaded.");
        // Do stuff for singleplayer world
    	return;
      }
      MCDRP.logger.info("Server loaded.");
      System.out.println(world.getMinecraftServer().getName());
    }
    
    @SubscribeEvent
    public void onLogout(PlayerLoggedOutEvent event) {
      // Handle leaving the server / exiting the world
    }

     

    What events do I use to separate the singleplayer load from the multiplayer connect?

  3. I'll explain the lines one by one.
     

    				ResourcePackRepository rpr = Minecraft.getMinecraft().getResourcePackRepository();
    				Class cls = ResourcePackRepository.class;
    				Method md = cls.getDeclaredMethod("getResourcePack", File.class);
    				md.setAccessible(true);
    				IResourcePack myNewPack = (IResourcePack) md.invoke(rpr,
    						new File("E:\\Users\\FireController1847\\Desktop\\Faithful 1.12.2-rv4.zip"));

    This creates a new valid ResourcePack by getting the private method "getResourcePack" from ResourcePackRepository.
     

    				Class cls2 = Entry.class;
    				Constructor cn = cls2.getDeclaredConstructor(ResourcePackRepository.class, IResourcePack.class);
    				cn.setAccessible(true);
    				Entry entry = (Entry) cn.newInstance(rpr, myNewPack);
    				System.out.println(entry);

    This gets the private constructor of Entry and creates a new instance of it using the IResourcePack we made above.
     

    				List<Entry> repos = rpr.getRepositoryEntriesAll();
    				repos.add(entry);
    				rpr.setRepositories(repos)

    This is where I didn't really know where to go. I attempted to add the Entry into all of the entries (therefore enabling the resource pack), but it comes up with the error listed in the comment above.

  4. Actually, I've managed to successfully load and improve the class (the second you posted this lol). I do have a new issue now, though. Here's my current code:
     

    			try {
    				ResourcePackRepository rpr = Minecraft.getMinecraft().getResourcePackRepository();
    				Class cls = ResourcePackRepository.class;
    				Method md = cls.getDeclaredMethod("getResourcePack", File.class);
    				md.setAccessible(true);
    				IResourcePack myNewPack = (IResourcePack) md.invoke(rpr, new File(
    						"E:\\\\Users\\\\FireController1847\\\\Desktop\\\\Forge\\\\Testing\\\\run\\\\resourcepacks\\\\Faithful1.12.2-rv4.zip"));
    
    				Class cls2 = Entry.class;
    				Constructor cn = cls2.getDeclaredConstructor(ResourcePackRepository.class, IResourcePack.class);
    				cn.setAccessible(true);
    				Entry entry = (Entry) cn.newInstance(rpr, myNewPack);
    				System.out.println(entry);
    				
    				List<Entry> repos = rpr.getRepositoryEntriesAll();
    				repos.add(entry);
    				rpr.setRepositories(repos);
    			} catch (Exception e) {
    				LogManager.getLogger().error(e);
    				StackTraceElement[] stack = e.getStackTrace();
    				for (StackTraceElement trace : stack) {
    					LogManager.getLogger().error(trace);
    				}
    			}

    The error comes on the repos.add(entry) line.
     

    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: java.lang.UnsupportedOperationException
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:218)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: com.firecontrol.testmod.Handlers.BlockHandler.onActionPerformed(BlockHandler.java:106)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_BlockHandler_onActionPerformed_Pre.invoke(.dynamic)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:489)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.gui.GuiMultiplayer.mouseClicked(GuiMultiplayer.java:441)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.gui.GuiMultiplayer.handleMouseInput(GuiMultiplayer.java:90)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.Minecraft.runTick(Minecraft.java:1884)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.Minecraft.run(Minecraft.java:441)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.client.main.Main.main(Main.java:118)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: java.lang.reflect.Method.invoke(Unknown Source)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: java.lang.reflect.Method.invoke(Unknown Source)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    [21:21:14] [main/ERROR] [com.firecontrol.testmod.Handlers.BlockHandler]: GradleStart.main(GradleStart.java:26)

     

  5. So I'm attempting the Reflection method, but it's saying it cannot find the constructor? (Sorry, this is my first time with relfections and AHHHHHHHHH)
     

    Constructor entry = ReflectionHelper.findConstructor(Entry.class, File.class);
    System.out.println(entry);


    Error
     

    [19:49:40] [main/ERROR] [FML]: Exception caught during firing event net.minecraftforge.client.event.GuiScreenEvent$ActionPerformedEvent$Pre@65b11833:
    net.minecraftforge.fml.relauncher.ReflectionHelper$UnknownConstructorException: Could not find constructor 'Entry(java.io.File)' in class net.minecraft.client.resources.ResourcePackRepository$Entry
    	at net.minecraftforge.fml.relauncher.ReflectionHelper.findConstructor(ReflectionHelper.java:270) ~[forgeSrc-1.12.2-14.23.0.2503.jar:?]
    	at com.firecontrol.testmod.Handlers.BlockHandler.onActionPerformed(BlockHandler.java:92) ~[BlockHandler.class:?]
    	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_9_BlockHandler_onActionPerformed_Pre.invoke(.dynamic) ~[?:?]
    	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179) [EventBus.class:?]
    	at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:489) [GuiScreen.class:?]
    	at net.minecraft.client.gui.GuiMultiplayer.mouseClicked(GuiMultiplayer.java:441) [GuiMultiplayer.class:?]
    	at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) [GuiScreen.class:?]
    	at net.minecraft.client.gui.GuiMultiplayer.handleMouseInput(GuiMultiplayer.java:90) [GuiMultiplayer.class:?]
    	at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) [GuiScreen.class:?]
    	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1884) [Minecraft.class:?]
    	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) [Minecraft.class:?]
    	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
    	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
    	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
    	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
    	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
    	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    	at GradleStart.main(GradleStart.java:26) [start/:?]
    [19:49:40] [main/ERROR] [FML]: Index: 1 Listeners:
    [19:49:40] [main/ERROR] [FML]: 0: NORMAL
    [19:49:40] [main/ERROR] [FML]: 1: ASM: com.firecontrol.testmod.Handlers.BlockHandler@16858bf6 onActionPerformed(Lnet/minecraftforge/client/event/GuiScreenEvent$ActionPerformedEvent$Pre;)V

     

  6. To be honest, my first issue comes into place where I'm not exactly sure if I'm even using the right components. As of right now, I'm attempting to create a new "Entry" (ResourcePackRepository$Entry) and insert it into Minecraft.getMinecraft().getResourcePackRepository(). But due to the fact the constructor of Entry is private, I can't create a new Entry therefore I can't test by adding a new element into the ResourcePackRepository

    net.minecraft.client.resources.ResourcePackRepository$Entry

        @SideOnly(Side.CLIENT)
        public class Entry
        {
            private final IResourcePack reResourcePack;
            private PackMetadataSection rePackMetadataSection;
            private ResourceLocation locationTexturePackIcon;
    
            // Private
            private Entry(File resourcePackFileIn)
            {
                this(ResourcePackRepository.this.getResourcePack(resourcePackFileIn));
            }
    
            // Private
            private Entry(IResourcePack reResourcePackIn)
            {
                this.reResourcePack = reResourcePackIn;
            }

     

  7. Think of it this way: You have some modpacks on technic, ftb, some custom mods on the main thing, and ATLauncher, but you want all of them to access the same resourcepack file. This file would have to be literally copied (on windows) to each resourcepack file, and if it's a large resourcepack this could take quite a bit of space. This is supposed to allow you to load only one file without the need to copy it at all.

  8. I've been poking around the ResourcePackRepository files and a bunch similar to it, and I have yet to find a way to insert my own resource pack manually into the list. This is what I'm attempting to do: I'll add a button to the resource pack screen that says "Add External Pack...", and when the user clicks this button it will load a ResourcePack from wherever the file was. This provides temporary or permanent ways to not have to find the .resourcepacks folder. For example, if you don't want to copy the same resource pack over and over and over again. I know how to get the file path and location, but I'm having issues adding it manually. I've tested by creating a new ResourcePackRepository$Entry, and due to the fact that the constructors are private, I cannot do this. Am I looking through the wrong files? Is there something else I should be doing entirely? How do I do this? xD

    Here's what I've got so far (ignore the fact the button is in the Multiplayer screen, I was messing around):
     

    	@SubscribeEvent
    	public void onActionPerformed(ActionPerformedEvent.Pre event) {
    		if (event.getGui() instanceof GuiMultiplayer && event.getButton().id == 9) {
    			// JFileChooser fc = new JFileChooser();
    			// fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    			// fc.getActionMap().get("viewTypeDetails").actionPerformed(null);
    			// fc.setPreferredSize(new Dimension(1200, 900));
    			// try {
    			// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    			// } catch (Exception e) {
    			// }
    			// if (fc.showOpenDialog(fc) == JFileChooser.APPROVE_OPTION) {
    			// System.out.println(fc.getSelectedFile().getAbsolutePath());
    			// }
    			ResourcePackRepository rpr = Minecraft.getMinecraft().getResourcePackRepository();
    			List<Entry> repos = rpr.getRepositoryEntriesAll();
    			System.out.println(repos);
    			for (Entry repo : repos) {
    				System.out.println(repo);
    			}
    			Entry e = new Entry(new File("E:\\Users\\xxxx\\Desktop\\xxxx\\xxxx\\run\\resourcepacks\\Faithful 1.12.2-rv4.zip"));
    			System.out.println(e);
    			// repos.add(e);
    
    			// rpr.setRepositories(repos);
    		}
    	}

     

  9. Well, it seems the problem happened to solve itself I guess. Mine stops when I shut off my resource pack (64x), so obviously that's from my GPU on my laptop not being powerful enough. My friend's stops after about 10-15 minutes of playing, so I guess it's fixed. Unless you still want those logs.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.