Posted October 14, 20204 yr hello I am very new to minecraft forge modding a day ago when this post was made I started modding but I have a problem I making a mod that makes the game really hard and i want to make it so every creeper that spawns will become charged but there is no command that can make then charged so here is my code package ultrahardcore.ultrahardcore.events; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import ultrahardcore.ultrahardcore.UltraHardCore; @Mod.EventBusSubscriber(modid = UltraHardCore.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class Events { @SubscribeEvent public void autoChargeCreeper(LivingSpawnEvent event) { // help me make the creepers charged } }
October 14, 20204 yr Author @diesieben07 can you send me a basic code of a entity spawn event with the code that charges the creeper?
October 14, 20204 yr Author @diesieben07 normaly when i see code i dont copy it and if i do copy it i will look at the code and work out how to works so plz give me some basic code on how to do that
October 14, 20204 yr 37 minutes ago, diesieben07 said: You will copy the code, not understand it and end up here tomorrow with the next basic problem. I don't mean to sound rude, but I disagree with that. Many times when learning something new, I'd find some example code, or code that achieves a similar effect to what i need, I'd read through it, attempt to understand and learn from it, then maybe tweak it if needed. I'm sure I'm not the only one! I understand that not everybody does that, but if they are serious about learning whatever it is, then they would. That's just my opinion though. Edited October 14, 20204 yr by BlockyPenguin Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
October 14, 20204 yr Author @BlockyPenguin ok thats good to know that you dont learn of copying code or typing it manually i will note that in my brain to try to copy as less code as i can @diesieben07 ok but what do i need to do here then @Mod.EventBusSubscriber() do i need to do dist.client or dist.deticatedserver or dist.class or dist.new? and i need to do a if statement to detect the creeper how do i do that? and there is not setpowered or setcharged command on the CreeperEntity command Edited October 14, 20204 yr by Crazy_sheep
October 14, 20204 yr So, you have this: package ultrahardcore.ultrahardcore.events; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import ultrahardcore.ultrahardcore.UltraHardCore; @Mod.EventBusSubscriber(modid = UltraHardCore.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class Events { @SubscribeEvent public void autoChargeCreeper(LivingSpawnEvent event) { // help me make the creepers charged } } First, this is not necessary, but I would suggest changing your package declaration to be something like "crazy_sheep.ultrahardcore.events". However, as I said, this is not necessary and is just a good code practice. There are various other ways to style your package, I suggest you look into them 😄 Second, "value = Dist.CLIENT" is only going to be bad news. You want your events firing on both the server and client, so leave it blank. this way, forge will assume that you want your events to run on both sides. There are other ways to register an event handler, but I won't go over those here. However, to @diesieben07 I have now been looking through CreeperEntity for a while, and haven't found how to set it's powered state... EDIT: I guess nbt is a viable route Edited October 14, 20204 yr by BlockyPenguin Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
October 14, 20204 yr It would be something on the lines of CompoundNBT nbt = creeper.serializeNBT(); //edit nbt here, example: nbt.putBoolean("powered", true); creeper.deserializeNBT(nbt); I should imagine that would work, but I haven't tested it. By the sounds of it, you don't know much about modding for forge. That's ok, we've all been there at the beginning! I suggest you read the documentation (mcforge.readthedocs.io), watch/read tutorials (Cadiboo has some great ones), and go from there. Good luck! Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
October 14, 20204 yr Author @BlockyPenguin ok i will try i will edit this post if something is wrong else i will edit the post saying that it is working EDIT:nope it does not work the serializeNBT(); part does not work its not a command and where did you get the creeper command? should it not be CreeperEntity? Edited October 14, 20204 yr by Crazy_sheep
October 14, 20204 yr 1 hour ago, BlockyPenguin said: It would be something on the lines of CompoundNBT nbt = creeper.serializeNBT(); //edit nbt here, example: nbt.putBoolean("powered", true); creeper.deserializeNBT(nbt); I should imagine that would work, but I haven't tested it. By the sounds of it, you don't know much about modding for forge. That's ok, we've all been there at the beginning! I suggest you read the documentation (mcforge.readthedocs.io), watch/read tutorials (Cadiboo has some great ones), and go from there. Good luck! Don't serialize/deserialize entities to change their field values. That's disgusting. 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.
October 14, 20204 yr 3 minutes ago, Draco18s said: Don't serialize/deserialize entities to change their field values. That's disgusting. Oh? How would you do it then? @Crazy_sheep event.getEntity will give you the Entity, which I called creeper Edited October 14, 20204 yr by BlockyPenguin Today (22/10/20) I reached 100 posts! I'm probably more excited than I should be for something so realistically minor...
October 14, 20204 yr Author @Draco18s it would have been helpful if you show me then how to do it Edit ignore my comment Edited October 14, 20204 yr by Crazy_sheep
October 14, 20204 yr Author @BlockyPenguin but how would i do that in a if state ment EDIT: oh i was not for a if statement sorry 😅 Edited October 14, 20204 yr by Crazy_sheep
October 14, 20204 yr Author there is a setCreeperState() command can i do something with this to make it powered?
October 14, 20204 yr 1 hour ago, BlockyPenguin said: Oh? How would you do it then? @Crazy_sheep event.getEntity will give you the Entity, which I called creeper Let me pop my IDE open here and... Well, the POWERED value and the dataManager are both private, so.... Reflection. 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.
October 14, 20204 yr Author @Draco18s but how do i make a reflection or how do i make the creeper powered because i still dont have the awnser
October 14, 20204 yr 33 minutes ago, Crazy_sheep said: how do i make a reflection ReflectionObfuscationHelper if I remember the class's name correctly. You call getPrivateValue and pass in the SRG name of the field you want. 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.
October 15, 20204 yr Author @Draco18s but what is the charged ntb called is it called powered and if i make a Reflection do i need to do this ReflectionObfuscationHelper("powered", true)? and when i try to do this CreeperEntity creeper = (CreeperEntity) event.getEntity(); if (event.getEntity() instanceof CreeperEntity) { creeper.ReflectionObfuscationHelper } ReflectionObfuscationHelper is not a command Edited October 15, 20204 yr by Crazy_sheep
October 15, 20204 yr It is a class, and that's not how it works. 13 hours ago, Draco18s said: getPrivateValue Store the field you got in a static final variable, then access it when needed.
October 15, 20204 yr Author @loordgekif I learn java I then still don't know how to do stuff in forge and its a lot more fun to learn java with forge
October 15, 20204 yr 18 minutes ago, Crazy_sheep said: @loordgekif I learn java I then still don't know how to do stuff in forge and its a lot more fun to learn java with forge Trying to explore and understand forge/minecraft concepts and code without knowing java is pure madness...trying to learn java by doing stuff that, at the beginning, makes almost no sense even to experienced Java programmers is even more madness Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
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.