MrChoke Posted September 25, 2018 Posted September 25, 2018 I am writing my own custom PathNavigator and NodeProcessor. And I am finding I can't extend anything from existing code because Mojang decided to make PathNodeType an enum. This enum is used all over the place in path finding and even in some other entity code. What if I need to define my own path nodes types? For example, I want to be able to break fences. Well, too bad trying to use any of the existing code because with an enum I can't add anything to it nor can I extend it. I don't know how many people have seen the 1.13 code yet. Did Mojang change this? If not, can we change this in Forge? I'll write the code if I need to. Thoughts? Quote
Animefan8888 Posted September 25, 2018 Posted September 25, 2018 On 9/25/2018 at 1:49 AM, MrChoke said: seen the 1.13 code yet. Expand I have not seen this, however you could probably look for the mcp(minecraft coder pack for 1.13 and check. On 9/25/2018 at 1:49 AM, MrChoke said: If not, can we change this in Forge? Expand No. This is too bug of a change. On 9/25/2018 at 1:49 AM, MrChoke said: What if I need to define my own path nodes types Expand Use reflection and add another entry to the enum. Look at how the EnumHelper class does it if you need an example. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 On 9/25/2018 at 1:53 AM, Animefan8888 said: Use reflection and add another entry to the enum. Look at how the EnumHelper class does it if you need an example. Expand WOW, that code is deep. I read enums are read-only, PERIOD. That is some serious hack-like code. It is using "sun" objects for example. Oh well. If it works great. I will see if I can copy part of it. Too bad PathNodeType is not handled already. Can that be a Forge change? Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 (edited) It’s very deep code, which is why it breaks on everything except java 8. However it is the “proper” way of adding enum a in forge and is used by all Modders. See an example of adding an enum in the AddHorseArmor method. Don’t copy the forge method if that’s what you meant by this!!! On 9/25/2018 at 1:59 AM, MrChoke said: I will see if I can copy part of it. Expand Edited September 25, 2018 by Cadiboo Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 (edited) On 9/25/2018 at 2:00 AM, Cadiboo said: It’s very deep code, which is why it breaks on everything except java 8. However it is the “proper” way of adding enum a in forge and is used by all Modders. Expand Ok. Of course it still won't let me do something like this: PathNodeType.NEW_TYPE Since the compiler will fail that. But perhaps it will allow me to keep a lot of existing code at least. But how do I reference one of these new runtime enum values then??? So any chance of PathNodeType being added to EnumHelper? Edited September 25, 2018 by MrChoke Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 Take a look at https://github.com/Cadiboo/WIPTechAlpha/blob/master/src/main/java/cadiboo/wiptech/api/WIPTechAPI.java where I use forges reflection to add an enum Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 On 9/25/2018 at 2:00 AM, Cadiboo said: It’s very deep code, which is why it breaks on everything except java 8. However it is the “proper” way of adding enum a in forge and is used by all Modders. See an example of adding an enum in the AddHorseArmor method. Don’t copy the forge method if that’s what you meant by this!!! Expand A method like "addPathNodeType" would be great. It doesn't exist! We need one. I smell a forge pull request coming.... Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 Go ahead, but it’s not exactly required Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 On 9/25/2018 at 2:08 AM, Cadiboo said: Go ahead, but it’s not exactly required Expand Explain how its not required unless I start lifting EnumHelper code which I agree is a very bad idea. Though, please help me with my other question. How do you reference one of these new enums in code?? PathNodeType.NEW_TYPE sure won't work. Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 On 9/25/2018 at 2:06 AM, Cadiboo said: Take a look at https://github.com/Cadiboo/WIPTechAlpha/blob/master/src/main/java/cadiboo/wiptech/api/WIPTechAPI.java where I use forges reflection to add an enum Expand Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Cadiboo Posted September 25, 2018 Posted September 25, 2018 In pseudo code public static final EnumType NEW_ENUM = reflectionHelper.addEnum(EnumType.class, new Class[]{enum argument classes}, new enum argument values...); Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 (edited) On 9/25/2018 at 2:14 AM, Cadiboo said: In pseudo code public static final EnumType NEW_ENUM = reflectionHelper.addEnum(EnumType.class, new Class[]{enum argument classes}, new enum argument values...); Expand I will look at the code you sent me. Seems like I can call addENum() from EnumHelper. That is fine too. So for my question on referencing it at runtime, would this built-in Enum method work for the runtime entry? static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) If so, I think this will work. Edited September 25, 2018 by MrChoke Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 On 9/25/2018 at 2:18 AM, MrChoke said: I will look at the code you sent me. Seems like I can call addENum() from EnumHelper. That is fine too. So for my question on referencing it at runtime, would this built-in Enum method work for the runtime entry? static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) If so, I think this will work. Expand Maybe, but just reference your new enum that you added with enumhelper and stored in a constant field. Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 (edited) On 9/25/2018 at 2:20 AM, Cadiboo said: Maybe, but just reference your new enum that you added with enumhelper and stored in a constant field. Expand Still not seeing how I can reference the new enum value as a constant... I am looking at the HroseArmor stuff.... Edited September 25, 2018 by MrChoke Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 (edited) On 9/25/2018 at 2:29 AM, MrChoke said: Still not seeing how I can reference the new enum value as a constant... I am looking at the HroseArmor stuff.... Expand Enumhelper.addEnum returns the new enum created. Store it somewhere and reference it Edited September 25, 2018 by Cadiboo Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 On 9/25/2018 at 2:34 AM, Cadiboo said: Enumhelper.addEnum returns the new enum created. Store it somewhere and reference it Expand Oh ok. Yeah that makes sense. Thanks! Quote
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 Just wanted to let you know, that was a piece of cake to add. And the built-in valueOf() method works too: final Class[] parameterTypes = new Class[] { float.class }; PathNodeType FENCE_OPEN = EnumHelper.addEnum(PathNodeType.class, "FENCE_OPEN", parameterTypes, 0.0F); PathNodeType test1 = Enum.valueOf(PathNodeType.class, "FENCE_OPEN"); if(test1 == FENCE_OPEN) { System.out.println("PASSED!!"); } Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 (edited) Problematic code issue #10 Edited September 25, 2018 by Cadiboo Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
MrChoke Posted September 25, 2018 Author Posted September 25, 2018 On 9/25/2018 at 2:56 AM, Cadiboo said: Problematic code issue #10 Expand You mean I call the new field something like "MYMOD_FENCE_OPEN"? Quote
Cadiboo Posted September 25, 2018 Posted September 25, 2018 (edited) On 9/25/2018 at 3:00 AM, MrChoke said: You mean I call the new field something like "MYMOD_FENCE_OPEN"? Expand I recommend naming your enum a resource location (MODID, EnumName).toString(). What you name it in your field reference is up to you. I don’t know if having a semicolon in the enum name will cause issues though Edited September 26, 2018 by Cadiboo Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Draco18s Posted September 25, 2018 Posted September 25, 2018 On 9/25/2018 at 4:33 AM, Cadiboo said: I recommend naming your enum a resource location (MODID, EnumName).toString(). What you name it in your field reference is up to you. I don’t know if having a semicolon in the enum name will cause issues though Expand : is a colon. Quote 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.
quadraxis Posted September 25, 2018 Posted September 25, 2018 PathNodeType being an enum was discussed in https://github.com/MinecraftForge/MinecraftForge/pull/4598. Quote
Recommended Posts
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.