Posted September 4, 20178 yr Hey there! I'm new to modding and would like to get a List of all registered TileEntities. I tried: Minecraft.getMinecraft().world.loadedTileEntityList; But it only gives the TE's already in the World and I want a list with All registered TE's. Is that possible? If yes, how? I'd love to see an example Greetings -Dj Edited September 5, 20178 yr by MrDj200
September 4, 20178 yr TileEntity has a REGISTRY field that is like all other registries. You will need to use reflection to access it, however. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
September 4, 20178 yr Author Thanks for the reply! I tried using that. And it works in my IDE, however not on "real" servers. I think it has something to do with Obfuscation(?). Here is the Code I used: try { Field field = TileEntity.class.getDeclaredField("REGISTRY"); field.setAccessible(true); RegistryNamespaced<ResourceLocation, Class<? extends TileEntity>> reg = (RegistryNamespaced) field.get(null); for(ResourceLocation location : reg.getKeys()) { Class<? extends TileEntity> entity = reg.getObject(location); LogHelper.info("Registered TE: " + entity.getName()); } } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { LogHelper.error("An unexpected error occured ", ex); } Is there a way to use it on "real" servers/clients? -Dj
September 4, 20178 yr Author Spoiler java.lang.NoSuchFieldException: REGISTRY at java.lang.Class.getDeclaredField(Class.java:2070) ~[?:1.8.0_144] at me.dj.spatialserver.SpatialServer.init(SpatialServer.java:41) [SpatialServer.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144] at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:614) [FMLModContainer.class:?] at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144] at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76) [minecraft_server.1.12.jar:?] at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:217) [minecraft_server.1.12.jar:?] at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:252) [LoadController.class:?] at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:230) [LoadController.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_144] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144] at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144] at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76) [minecraft_server.1.12.jar:?] at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116) [minecraft_server.1.12.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:217) [minecraft_server.1.12.jar:?] at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:147) [LoadController.class:?] at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:781) [Loader.class:?] at net.minecraftforge.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:107) [FMLServerHandler.class:?] at net.minecraftforge.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:336) [FMLCommonHandler.class:?] at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:216) [nx.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:483) [MinecraftServer.class:?] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_144] Thats the info the LogHelper gives me on a real Server. Forgot to add it. -Dj
September 5, 20178 yr You need the SRG name as well. You can get it from MCPbot. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
September 5, 20178 yr Author Hmm, It gave me something, but it seems like it was wrong. I now use this: Class cls = Class.forName("avh.f"); field = cls.getDeclaredField("field_190562_f"); Instead of this: field = TileEntity.class.getDeclaredField("REGISTRY"); But neither works on servers. Do I have to type in something else in MCPbot? My input in MCP was this: Spoiler -Dj Edited September 5, 20178 yr by MrDj200
September 5, 20178 yr Use ReflectionHelper. (Note: The class name is not "avh.f" it's "avh" with a field name of "f", but you don't need Notch names anyway) Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
September 5, 20178 yr Author I cant seem to figure out how it works. As I said Im very new To mc modding even to Java. So if someone could provide an example, I'd be very grateful. -Dj
September 5, 20178 yr https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/util/AdvancementUtils.java#L20 Here's an example. It does not point to the same object you're interested in, it just shows how to use ReflectionHelper. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
September 5, 20178 yr Author Thanks. So like this? Field listField = ReflectionHelper.findField(TileEntity.class, "REGISTRY", "field_190562_f"); Or Like this: Field listField = ReflectionHelper.findField(avh.class, "REGISTRY", "field_190562_f"); Edited September 5, 20178 yr by MrDj200
September 5, 20178 yr Author It seems to work now! Thank you VERY much! It was: Field field = ReflectionHelper.findField(TileEntity.class, "REGISTRY", "field_190562_f"); Have a nice rest Day/night/whatever! -Dj
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.