Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8][SOLVED] Custom Attribute/Attribute Modifier Help


NovaViper
 Share

Recommended Posts

Hey, I'm trying to make a new attribute that makes an entity that has it more resistant to explosions from creepers and TNT. This is my first time attempting this and I have no idea where to start off with it. I already created the attribute itself but I don't know how to create the events to activate it/utilize it. My code is on Github and here is attribute:

 

    public static final IAttribute blastResist = (new RangedAttribute((IAttribute)null, "generic.blastResist", 30.0D, 0.0D, Double.MAX_VALUE)).setDescription("Explosion Resistance").setShouldWatch(true);

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

Anything realted to dealing damage requires you to subscribe to LivingHurtEvent. There you will need to check DamageSource and if it's an explosion, do check for value of this attribute (example on how to get attribute are in vanilla) and compare values (do math) and then apply new damage (cancel old one).

 

Registering attribute should be done in EntityConstructing (instanceof EntityLivingBase). I mean - I THINK so.

To register it you use something like entity.registerBaseAttribute (I don't remember exact name)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Ok, here's what I started to do but I'm not sure how get the damage the entity has taken

 

	@SubscribeEvent
public void blastResist(LivingHurtEvent event){
	if(event.entity instanceof EntityMetalZertum){
		if(event.source.isExplosion()){

		}
	}

}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

How do I get the explosion damage type? I'm not exactly sure if I'm doing this correctly, here is what I have

 

	@SubscribeEvent
public void blastResist(LivingHurtEvent event){
	if(event.entity instanceof EntityMetalZertum){

		EntityMetalZertum entity;

		if(event.source.isExplosion()){
			event.ammount = event.source / entity.blastResist;
		}
	}

}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

I can't use the same thing again, it'll glitch it up. What I'm trying to do is take the damage and divide it.

 

Like this

 

	@SubscribeEvent
public void blastResist(LivingHurtEvent event){
	if(event.entity instanceof EntityMetalZertum){

		EntityMetalZertum entity;

		if(event.source.isExplosion()){
			event.ammount = event.ammount / entity.getEntityAttribute(entity.blastResist).getAttributeValue();
		}
	}

}

 

Also the ammount is a float, not a double

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

I'm getting a crash saying

 

 

[19:40:59] [Client thread/ERROR] [FML]: Caught exception from zero_quest

java.lang.IllegalArgumentException: Method public void common.zeroquest.events.LivingEvents.blastResist(net.minecraftforge.event.entity.living.LivingHurtEvent,common.zeroquest.entity.EntityMetalZertum) has @SubscribeEvent annotation, but requires 2 arguments.  Event handler methods must require a single argument.

at net.minecraftforge.fml.common.eventhandler.EventBus.register(EventBus.java:72) ~[forgeSrc-1.8-11.14.1.1325.jar:?]

at common.zeroquest.ZeroQuest.load(ZeroQuest.java:98) ~[bin/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:518) ~[forgeSrc-1.8-11.14.1.1325.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[forgeSrc-1.8-11.14.1.1325.jar:?]

at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[forgeSrc-1.8-11.14.1.1325.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]

at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]

at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]

at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]

at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]

at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:692) [Loader.class:?]

at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:291) [FMLClientHandler.class:?]

at net.minecraft.client.Minecraft.startGame(Minecraft.java:521) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:356) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_25]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:85) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

[19:40:59] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:660]: ---- Minecraft Crash Report ----

 

 

Here is my code now

	@SubscribeEvent
public void blastResist(LivingHurtEvent event, EntityMetalZertum entity){
	if(event.entity instanceof EntityMetalZertum){
		this.entity = entity;

		if(event.source.isExplosion()){
			event.ammount = (float)(event.ammount /entity.getEntityAttribute(entity.blastResist).getAttributeValue());
		}
	}

	System.out.println(event.ammount);
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

You cant just add another variable to the method.

I would highly recommend you to learn more about java and how it works.

For now.

 

I guess you want to reduce the damage taken from an explosion if the affected entity is an EntityMetalZertum.

 

The event got the event.entity .

You can check if the entity is an instance of EntityMetalZertum and if it is an EntityMetalZertum you can cast it to one and then get the blastResist from it.

 

Link to comment
Share on other sites

Ok, I can't tell if it's working exactly but I do notice that it takes alot more grenades to kill it than with normal Zertums, also here is some debug numbers I got

 

[20:12:54] [server thread/INFO] [sTDOUT]: [common.zeroquest.command.CommandZeroQuest$TameModifier:modify:231]: Tamed! //Taming Metal Zertum
2.0
2.0
0.0
4.6

With a normal Zertum, it takes 2 grenades to kill it, but with this on the Metal Zertums, it takes like, 8 or 9 grenades.

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Link to comment
Share on other sites

It seems to work, because if the attribute is set to 0, it instantly kills the entity (also in the debug, it says "Infinity" instead of a number). When I hit the grenade with a regular Zertum, it says like 5.0 - 19.0, for Metal Zertums though (when the attribute is set to 5.0), it says 0.0 - 3.0.

 

===EDIT===

Yeah, it's working. Thanks!

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

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

×
×
  • Create New...

Important Information

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