Jump to content

[1.10] LivingHurtEvent not damaging entities


tripl3dogdare

Recommended Posts

I'm working on a mod that requires some rather complex damage overrides, so I'm catching the LivingHurtEvent to apply those. However, in certain cases the damage is not applied, as if the event is being canceled, despite never canceling it in my code.

 

The code:

@SubscribeEvent public void onLivingHurt(LivingHurtEvent e) {
if(e.getSource().getEntity() instanceof EntityPlayer) {
	EntityPlayer player = (EntityPlayer)e.getSource().getEntity();

	boolean weaponEquipped = false, armorEquipped = false;
	Item weapon = null, armor = null;
	for(Item weapon_ : ItemRegistry.buffPairs.keySet()) {
		weapon = weapon_;
		armor = ItemRegistry.buffPairs.get(weapon);

		if(player.getHeldItemMainhand().getItem() == weapon) {
			if(!player.getHeldItemMainhand().getTagCompound().getBoolean("active")) return;
			weaponEquipped = true;

			for(ItemStack i : player.getArmorInventoryList()) {
				if(i.getItem() == armor) {
					armorEquipped = true;
					break;
				}
			}

			break;
		}
	}

	if(weaponEquipped) e.setAmount(e.getAmount()+(float)((ItemTimedWeapon)weapon).getAttackDamage()-1f);
	if(armorEquipped) e.setAmount(e.getAmount()*(float)((ItemCharacterArmor)armor).getDamageMultiplier());
}
}

 

Basically, I'm checking 1) if the player is holding a specific weapon and if so 2) if the weapon is in the "active" state based on it's NBT, and finally 3) whether a corresponding armor item is equipped. Then I apply changes to the damage based on whether the weapon/armor is equipped. However, the item only does damage if it is not in the active state, otherwise it acts like you didn't hit at all. Really having trouble... any ideas?

 

Edit: slight code updates, no fix

Link to comment
Share on other sites

So your problem is happening here

 

for(ItemStack i : player.getArmorInventoryList()) {
     if(i.getItem() == armor) {
          armorEquipped = true;
          break outer;
     }
}

 

Look at it closely.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I don't see what the issue is there, I'm simply breaking the outer loop rather than the inner one and that's the only thing I can see that you could be talking about. It's a rather obscure bit of Java syntax, but it should work perfectly fine.

 

Edit: removed it anyway as it was redundant, but it didn't change anything

Link to comment
Share on other sites

When you break to there instead of exiting the loop you actually start the next iteration.

 

*edit Don't question this I was thinking of something else sorry.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Basically the code checks three things:

 

1. Is a certain weapon in the player's main hand? If so:

2. Is the weapon active? and...

3. Is a specific piece of armor equipped?

 

If the weapon is in the main hand but inactive, it leaves it as is.

If the weapon is active, it adds the weapon's attack damage to the event damage.

If both the weapon and the armor are equipped, it multiplies that result by the armor's damage multiplier.

 

At least, that's what it should do. What it's actually doing, though, is preventing you from hitting at all if the weapon is active. (You can hit normally if it isn't.)

Link to comment
Share on other sites

Have you tried doing any debugging, like printing out what item it is currently on from the keyset (unlocalized name) into the console. To see if it is even detecting the item being there. Also are you sure that your buffPairs is gaining the items.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

No, I hadn't - however, attempting to do so led me to the problem(s), namely a NullPointerException when trying to get the item in an empty armor slot and an accidental recursive self-call in ItemCharacterArmor.getAttackMultiplier rather than referencing the desired variable. I apologize for my stupidity, and thank you for working through it with me.

Link to comment
Share on other sites

for(Item weapon_ : ItemRegistry.buffPairs.keySet()) {
		weapon = weapon_;
		armor = ItemRegistry.buffPairs.get(weapon);
		if(player.getHeldItemMainhand().getItem() == weapon) {

 

Uh.  Why are you setting the active weapon to the weapon_ keyvalue before checking if the player is actually wielding it?

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.

Link to comment
Share on other sites

I admit that that wasn't nearly the best way to go about it (the entire system). That's why I changed to this:

 

@SubscribeEvent public void onLivingHurt(LivingHurtEvent e) {
if(e.getSource().getEntity() instanceof EntityPlayer) {
	EntityPlayer player = (EntityPlayer)e.getSource().getEntity();
	if(player.getHeldItemMainhand() == null || !ItemRegistry.buffPairs.containsKey(player.getHeldItemMainhand().getItem())) return;
	if(!player.getHeldItemMainhand().getTagCompound().getBoolean("active")) return;

	ItemTimedWeapon weapon = (ItemTimedWeapon)player.getHeldItemMainhand().getItem();
	ItemCharacterArmor armor = (ItemCharacterArmor)ItemRegistry.buffPairs.get(weapon);

	for(ItemStack i : player.getArmorInventoryList()) {
		if(i != null && i.getItem() == armor) {
			e.setAmount(weapon.onActiveAttack(e, i));
			break;
		}

		e.setAmount(weapon.onActiveAttack(e, null));
	}
}
}

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When i try to launch Minecraft Java 1.20.1 forge with mods (82 mods),on start it loaded all mods,but at end Java just crashed.  p.s i allocated 8GB ram for minecraft and i didn't runned another instance.Log file pp.s I use ATlauncher   Environment: Organising filesystem [24/04/2024 23:40:08 PM] ATLauncher Version: 3.4.36.3 [11ae0b2334c236e93ee8128de980952b2a1b8900] [24/04/2024 23:40:08 PM] App Arguments: ["--install-method=aur","--no-launcher-update"] [24/04/2024 23:40:08 PM] JVM Arguments: ["-Dawt.useSystemAAFontSettings=on","-Dswing.aatext=true"] [24/04/2024 23:40:08 PM] Java Version: Java 22 (22) [24/04/2024 23:40:08 PM] Java Path: /usr/lib/jvm/java-22-openjdk [24/04/2024 23:40:08 PM] 64 Bit Java: true [24/04/2024 23:40:08 PM] RAM Available: 14931MB [24/04/2024 23:40:08 PM] Launcher Directory: **USERSDIR** [24/04/2024 23:40:08 PM] GPU: IvyBridge GT2 [HD Graphics 4000] (Intel Corporation (0x8086)) unknown 256MB VRAM [24/04/2024 23:40:08 PM] CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz 4 cores/8 threads [24/04/2024 23:40:08 PM] Operating System: EndeavourOS (unknown (unknown) build 6.8.7-arch1-1) [24/04/2024 23:40:08 PM] Bitness: 64 [24/04/2024 23:40:08 PM] Uptime: 15889 [24/04/2024 23:40:08 PM] Manufacturer: GNU/Linux
    • If you have nvidia graphics, don't touch your amd drivers, otherwise it might fix it but keep running on integrated graphics, which will result in terrible performance. For nvidia graphics, you need to tell windows and nvidia control panel that anything Minecraft related (the launcher, java, etc...) should prefer high performance graphics so that it actually uses your nvidia gpu
    • In the ever-evolving landscape of technology, the rise of cryptocurrencies and digital assets has introduced both unparalleled opportunities and unprecedented challenges. As these digital currencies become increasingly prevalent, so too does the risk of theft and loss. Yet, amidst the complexity and uncertainty, there exists a beacon of hope: ADRIAN LAMO HACKER. Technology has indeed become more sophisticated and enhanced, presenting new challenges in the realm of asset recovery. However, just as any other currency can be stolen or lost, crypto and digital assets are not beyond redemption. With the right expertise and guidance, recovery is possible and achievable. Contact ADRIAN LAMO HACKER via the website: https://adrianlamohackpro.online/ , a trusted, honest, and certified agency specializing in the retrieval of stolen or lost digital assets. In my own experience, I found myself in dire straits after falling victim to cybercriminals who absconded with a significant portion of my crypto holdings. It was a daunting situation, but I refused to succumb to despair. Upon engaging ADRIAN LAMO HACKER, their professionalism, and integrity immediately struck me, as an unwavering commitment to their clients. They deeply understand blockchain technology and utilize advanced methodologies to trace and recover lost or stolen funds. Their approach is meticulous, their expertise unparalleled, and their results speak for themselves. In a matter of days, ADRIAN LAMO HACKER successfully traced and recovered over 90% of my stolen funds, a feat I once believed to be unattainable. Their fees were fair and transparent, and communication throughout the process was nothing short of excellent. They kept me informed every step of the way, providing reassurance and guidance when I needed it most. For anyone who has fallen victim to crypto theft or loss, I wholeheartedly recommend ADRIAN LAMO HACKER. They are not just experts in their field; they are guardians of justice in the digital realm. With their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. So, if you find yourself grappling with the devastation of lost or stolen digital assets, don't despair. Reach out to ADRIAN LAMO HACKER via website: https://adrianlamohackpro.online/  / Telegram: @ADRIANLAMOHACKERTECH and let them guide you toward a brighter tomorrow.
  • Topics

×
×
  • Create New...

Important Information

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