Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

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.

  • Author

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!

  • Author

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!

  • Author

What I mean is isn't there suppose to be some kind of interger or double I'm suppose to get? Because right now, it says error about the souce nor convertable to double on Eclipse

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!

You got to check if the damage type is an explosion. Which is done. After you found that out you might want to access the value of the damage taken, which is event.ammount. This variable is the ammount of damage the player would take.

  • Author

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!

1. You need to initialize the entity (In this case EntityMetalZertum) before using it or youll get a nullpointerexception

2. You can cast a float to a double if needed

  • Author

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!

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.

 

  • Author

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!

  • Author

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!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.