Jump to content

OnDeath


ashtonr12

Recommended Posts

i have made an event that spawns a modified zombie, potion effects items, etc.

and i have seen that there is the forgehook onlivingdeath and in the zombie class there is an ondeath event, bu i cant seem to figure out how to use them.

 

i want check (from a seperate class that the zombie is created from) that the zombie is dead before i allow somthing, how would i do this? nbt's?

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

ok so have done it with the custom name and it seems to work but i cant get the names to match up, in one class i have "entityZombie.setCustomNameTag("Mythical"+name2+name1);"

and name1 and name2 and random names.

and in my onDeath event i have "x = entityzombie.getCustomNameTag();

if(x == ("Mythical"+CriticalStrike.common.summoningStone.name2+CriticalStrike.common.summoningStone.name1)){

but it doesnt work, i have checked that the event is working i just cant seem to get the zombie? oh and x is a typical string just btw.

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

String comparison is not like it would first seem it would be. There can be two different String objects although both Strings could contain "Hello". This is like any other object, two objects with the same properties but they are not the same object (which would mean that they are stored at the same location in RAM, etc.). .equals is designed for that specifique case where you have two objects that have the same properties and somehow the user should know that (he can't know about private fields). So the mthod .equals in String is designed for the case that both Strings contain the same charsequence but are not really the same object. .equals return true in this case, == doesn't.

 

PS: String has a method named .intern(). All Strings charsequences are stored in an String-class intern list with exactly one String object as reference. Calling .intern() returns exactly that String object meaning that if you use this before comparing two string containing the same char** with ==, the operation would return true.

Example: x.intern() == ("Mythical"+CriticalStrike.common.summoningStone.name2+CriticalStrike.common.summoningStone.name1).intern().

 

PSS: All strings you literally type in like "Mythical" are automatically intern, this is why normally == would succeed. A random charsqeunce-generator though normally returns a new String-object, not the .intern() one.

 

PSSS: Use .equals() instead of .intern() twice, code style.

Link to comment
Share on other sites

Error

A detailed walkthrough of the error, its code path and all known details is as follows:
2013-09-12 21:12:10 [iNFO] [sTDOUT] ---------------------------------------------------------------------------------------
2013-09-12 21:12:10 [iNFO] [sTDOUT] 
2013-09-12 21:12:10 [iNFO] [sTDOUT] -- Head --
2013-09-12 21:12:10 [iNFO] [sTDOUT] Stacktrace:
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at CriticalStrike.common.CriticalStrikeMain.onDeath(CriticalStrikeMain.java:190)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraftforge.event.ASMEventHandler_5_CriticalStrikeMain_onDeath_LivingDeathEvent.invoke(.dynamic)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraftforge.event.EventBus.post(EventBus.java:108)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:340)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:982)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:945)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.entity.monster.EntityMob.attackEntityFrom(EntityMob.java:72)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.entity.monster.EntityZombie.attackEntityFrom(EntityZombie.java:196)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1362)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:845)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:57)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 
2013-09-12 21:12:10 [iNFO] [sTDOUT] -- Ticking connection --
2013-09-12 21:12:10 [iNFO] [sTDOUT] Details:
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Connection: net.minecraft.network.NetServerHandler@1f898a7
2013-09-12 21:12:10 [iNFO] [sTDOUT] Stacktrace:
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:689)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:585)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 
2013-09-12 21:12:10 [iNFO] [sTDOUT] -- System Details --
2013-09-12 21:12:10 [iNFO] [sTDOUT] Details:
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Minecraft Version: 1.6.2
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Operating System: Windows 7 (x86) version 6.1
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Java Version: 1.7.0_07, Oracle Corporation
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Memory: 914576744 bytes (872 MB) / 1046937600 bytes (998 MB) up to 1046937600 bytes (998 MB)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	AABB Pool Size: 2705 (151480 bytes; 0 MB) allocated, 2401 (134456 bytes; 0 MB) used
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Suspicious classes: FML and Forge are installed
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	IntCache: cache: 0, tcache: 0, allocated: 3, tallocated: 63
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	FML: MCP v8.04 FML v6.2.35.804 Minecraft Forge 9.10.0.804 4 mods loaded, 4 mods active
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	mcp{8.04} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	FML{6.2.35.804} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Forge{9.10.0.804} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	criticalstrikemod{1.00} [Critical$trike] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Profiler Position: N/A (disabled)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Vec3 Pool Size: 919 (51464 bytes; 0 MB) allocated, 895 (50120 bytes; 0 MB) used
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Player Count: 1 / 8; [EntityPlayerMP['Player251'/232, l='New World', x=-48.91, y=66.11, z=233.33]]
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Type: Integrated Server (map_client.txt)
2013-09-12 21:12:10 [iNFO] [sTDOUT] 	Is Modded: Definitely; Client brand changed to 'fml,forge'
2013-09-12 21:12:10 [iNFO] [sTDOUT] #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\owner\Documents\Rob's Crap\Minecraft\CriticalStrikeModEclipse 1.62\forge\mcp\jars\.\crash-reports\crash-2013-09-12_21.12.10-server.txt
2013-09-12 21:12:10 [iNFO] [Minecraft-Server] Stopping server
2013-09-12 21:12:10 [iNFO] [Minecraft-Server] Saving players
2013-09-12 21:12:10 [iNFO] [Minecraft-Server] Saving worlds
2013-09-12 21:12:10 [iNFO] [Minecraft-Server] Saving chunks for level 'New World'/Overworld
AL lib: (EE) alc_cleanup: 1 device not closed

 

Code

@ForgeSubscribe
public void onDeath(LivingDeathEvent e){
	Entity killed = e.entity;
	Entity killer = e.source.getEntity();	
	EntityZombie entityzombie = new EntityZombie(e.entity.worldObj);
	if(killer instanceof EntityPlayer && !e.entity.worldObj.isRemote){
		if(e.entity instanceof EntityZombie){
		x.equals(entityzombie.getCustomNameTag());
		if(x.equals("§6§oMythical~§r"+CriticalStrike.common.summoningStone.name2+CriticalStrike.common.summoningStone.name1)){
			CriticalStrike.common.CriticalStrikeMain.hasSummoned = 0;
			System.out.println(CriticalStrike.common.CriticalStrikeMain.hasSummoned);
	}
		}}}

 

x.equals(entityzombie.getCustomNameTag()); is line 190

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

ok i am a moron xD is this better? no errors but it doesnt work...

 

event

@ForgeSubscribe
public void onDeath(LivingDeathEvent e){
	Entity killed = e.entity;
	Entity killer = e.source.getEntity();	
	EntityZombie entityzombie = new EntityZombie(e.entity.worldObj);
	if(killer instanceof EntityPlayer && !e.entity.worldObj.isRemote){
		if(e.entity instanceof EntityZombie){
		if(entityzombie.getCustomNameTag().equals("§6§oMythical~§r"+CriticalStrike.common.summoningStone.name2+CriticalStrike.common.summoningStone.name1)){
			CriticalStrike.common.CriticalStrikeMain.hasSummoned = 0;
	}
		}}}

 

spawning naming code

entityZombie.setCustomNameTag("§6§oMythical~§r"+name2+name1);

Use examples, i have aspergers.

Examples make sense to me.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • rp.crazyheal.xyz mods  
    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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