Jump to content

[1.15.2] Is it possible to modify a non-living Entities attackEntityFrom?


Fuffles
 Share

Recommended Posts

Hello there,

Im currently trying to change the Ender Crystal's behaviour of nuking everything when hit by something. This would be obviously not a problem if it weren't for the fact that its a non-LivingEntity, since there is an Event for LivingEnts called when they are damaged.
Is there any way to change this for it? Or do I have to drop that idea?

Link to comment
Share on other sites

You can override the entire entity with an implementation of your own.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

5 minutes ago, Fuffles said:

Aren't all Vanilla things set to final?

You can use reflection.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

11 hours ago, Fuffles said:

Welp, I feel like this whole Reflection thing is haunting me at every corner : /

Reflection itself is actually pretty to understand; however, Mojang's obfuscation complicates the matter. I would suggest to look into Java's reflection itself before trying out Forge's API for it.

 

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The version you are using is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. Currently supported versions are 1.19.2 (Latest) and 1.18.2 (LTS).
    • I was trying to change item models with Model backer and ItemOverrides but it's too annoying so I looked for alternative ways: but for that I need to make many items, in this case for each model one item, however each item would have five models and I want to make about 30 items. That way I would have to make 600 items? this is a lot, can the forge handle it?
    • I originally posted here in error, as the issue I was having was for fabric, not forge, so I don't know anything about your issue but I solved my issue by downgrading my graphics drivers, here's a link to a post I made on Minecraft forum, I made an edit on the post with the solution that worked for me:   https://www.minecraftforum.net/forums/support/java-edition-support/3164709-solved-minecraft-fabric-modpack-crash-when#c4
    • 20:14:21.373 net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer main Found mod file forge-1.19.2-43.1.43-universal.jar of type MOD with provider net.minecraftforge.fml.loading.moddiscovery.MinecraftLocator@5c92166b 20:14:21.386 net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer main Failed to build unique mod list after mod discovery. net.minecraftforge.fml.loading.EarlyLoadingException: Duplicate mods found at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.UniqueModListBuilder.buildUniqueList(UniqueModListBuilder.java:78) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer.discoverMods(ModDiscoverer.java:105) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.FMLLoader.beginModScan(FMLLoader.java:166) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.FMLServiceProvider.beginScanning(FMLServiceProvider.java:86) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServiceDecorator.runScan(TransformationServiceDecorator.java:112) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServicesHandler.lambda$runScanningTransformationServices$8(TransformationServicesHandler.java:100) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575) at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622) at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServicesHandler.runScanningTransformationServices(TransformationServicesHandler.java:102) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServicesHandler.initializeTransformationServices(TransformationServicesHandler.java:55) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.Launcher.run(Launcher.java:87) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.Launcher.main(Launcher.java:77) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) at cpw.mods.bootstraplauncher@1.1.2/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) 20:14:21.399 net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer main Mod Discovery failed. Skipping dependency discovery. 20:14:21.990 launcher main Exception in thread "main" java.lang.IllegalStateException: Failed to find system mod: minecraft at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.ModSorter.detectSystemMods(ModSorter.java:181) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.ModSorter.buildUniqueList(ModSorter.java:145) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.ModSorter.sort(ModSorter.java:53) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.moddiscovery.ModValidator.stage2Validation(ModValidator.java:101) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.FMLLoader.completeScan(FMLLoader.java:175) at MC-BOOTSTRAP/fmlloader@1.19.2-43.1.43/net.minecraftforge.fml.loading.FMLServiceProvider.completeScan(FMLServiceProvider.java:91) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServiceDecorator.onCompleteScan(TransformationServiceDecorator.java:174) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServicesHandler.lambda$triggerScanCompletion$24(TransformationServicesHandler.java:145) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575) at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616) at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622) at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.TransformationServicesHandler.triggerScanCompletion(TransformationServicesHandler.java:147) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.Launcher.run(Launcher.java:94) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.Launcher.main(Launcher.java:77) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.8/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) at cpw.mods.bootstraplauncher@1.1.2/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) 20:14:21.990 monitor Process Monitor Process crashed with exit code 1
    • I am created a packet that spawns 3 golems and adds a timer to their persistant data along with the name of the owner who spawned them. public boolean handle(Supplier<NetworkEvent.Context> supplier){ NetworkEvent.Context context = supplier.get(); context.enqueueWork(()-> { Player p = context.getSender(); if(p.getPersistentData().contains(XprtData.SALUS_CLASS)){ if(!p.getPersistentData().contains(XprtData.SALUS_DEFENDER_TIMER)){ for(int i=0;i<3;i++){ IronGolem golem = (IronGolem) EntityType.IRON_GOLEM.spawn(p.createCommandSourceStack().getLevel(), null, null, p.blockPosition(), MobSpawnType.MOB_SUMMONED, true, false); golem.getPersistentData().putInt(XprtData.SALUS_DEFENDER_TIMER, Utils.Seconds(50)); golem.getPersistentData().putString(XprtData.SALUS_DEFENDER_OWNER, p.getScoreboardName()); golem.setCustomName(Component.literal(ChatFormatting.GOLD + "" + p.getScoreboardName() + "'s Defender")); } p.getPersistentData().putInt(XprtData.SALUS_DEFENDER_TIMER, Utils.Seconds(5)); } else { int time = p.getPersistentData().getInt(XprtData.SALUS_DEFENDER_TIMER); Utils.Message(p, ChatFormatting.RED + "You cannot summon defenders right now, " + Utils.TicksToSeconds(time) + " seconds remaining."); } } }); return true; } the problem is when I call upon their data in an external class here @SubscribeEvent public static void onLivingTick(LivingEvent.LivingTickEvent e){ LivingEntity entity = e.getEntity(); if(entity instanceof IronGolem){ if(entity.getPersistentData().contains(XprtData.SALUS_DEFENDER_TIMER)){ Mob mob = (Mob)entity; for(LivingEntity target : Utils.getNear(entity, 8)){ if(target instanceof Player || target instanceof Villager || target instanceof Wolf || target instanceof IronGolem){ mob.setTarget(null); } else { mob.setTarget(target); } } } if(entity.getPersistentData().contains(XprtData.SALUS_DEFENDER_OWNER)){ String owner = entity.getPersistentData().getString(XprtData.SALUS_DEFENDER_OWNER); for(String pNames : entity.getServer().getPlayerNames()){ if(pNames.equals(owner)){ Player p = entity.getServer().getPlayerList().getPlayerByName(owner); if(entity.distanceTo(p) >= 7f){ entity.teleportTo(p.getBlockX(), p.getBlockY()+1, p.getBlockZ()); } } } } } } neither XprtData.SALUS_DEFENDER_TIMER nor XprtData.SALUS_DEFENDER_OWNER contain any data, for the timer it starts off at 0 when it should be (22*50) and defender owner should contain the players name which instead contains a blank.   This isnt my first time doing something like this, ive done it will illagers and it worked perfectly but when it comes to golems it doesnt work at all. I could do with it the timer killing them at -(22*50) but it wont help that i still need the owners name to teleport them to the owner if they move to far away. Any Ideas? Im calling this packet from a keybind by the way   EDIT:  I figured out the issue, I guess when the packet is received by server and the entity is created there is a delay before the persistant data is created I guess, im not too sure...  Anyways I fixed it by just calling the persistant data twice 
  • Topics

×
×
  • Create New...

Important Information

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