Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by MrDj200

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.

  • 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

  • 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

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.

  • 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

eb31982565.png

 

 

-Dj

Edited by MrDj200

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.

  • 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

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.

  • 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 by MrDj200

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.