Jump to content

Recommended Posts

Posted

Hi,

 

I'm currently working on a PvP mod, and I would like to add a 'friends' feature, where you can add a player as friend so you won't be able to hit them. I can't seem to figure out how to detect if you hit a player though, all I found was LivingHurtEvent, but that doesn't work when using it in multiplayer. I assume I need to listen for a damage packet or something like that, then check the username and cancel it if the player is added to your friendslist, but I can't find much about packets either. Can anyone help me with this?

 

 

 

EDIT: After checking the source of Damage Indicators I found out that I could just listen for the AttackEntityEvent instead. I can detect when I try to hit a friend and display a message that I can't hurt him/her, but I can't figure out how to cancel it (e.setCanceled(true) doesn't seem to work for me).

 

 

SOLVED: I used the MouseEvent then checked if the entity was on my friends list with 'Minecraft.getMinecraft().objectMouseOver.entityHit'. Cancelling this prevented my from hitting people on my friends list.

Posted

I was looking into it some time ago, so it might have been changed, but it might be the server that actually decides about your attack.

 

Cancelling it on client won't do anything since server still receives packet that you clicked mouse in particular direction, and the server will manage that click on it's own, so you will still attack.

 

You would have to intercept MouseEvent get entity under mouse (MovingObjectPosition I think) and cancel MouseEvent client-side before anything happens.

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

Posted

It is a

@Cancelable

event, so canceling should work. Show us your code.

 

I don't really have any code yet, I tried to just cancel the event in general like this:

 

@SubscribeEvent
public void onAttackEntity(AttackEntityEvent e) {
e.setCanceled(true);
}

 

Using this code, I CAN'T damage entities in singeplayer, but in multiplayer it doesn't work (keep in mind this is a client mod and not a server mod).

Posted

I was looking into it some time ago, so it might have been changed, but it might be the server that actually decides about your attack.

 

Cancelling it on client won't do anything since server still receives packet that you clicked mouse in particular direction, and the server will manage that click on it's own, so you will still attack.

 

You would have to intercept MouseEvent get entity under mouse (MovingObjectPosition I think) and cancel MouseEvent client-side before anything happens.

 

Thanks, I'll start off with just cancelling the MouseEvent and check if that prevents me from hitting entities in multiplayer.

 

EDIT: I just did a quick test with pigs, using this code I can't hit pigs but can hit other entities (which is what I want):

 

@SubscribeEvent
public void onMouse(MouseEvent e) {
	if (mc.objectMouseOver.entityHit instanceof EntityPig) {
		e.setCanceled(true);	
	}
}

 

I'll try to implement this into my friends system now and will post here if it worked or not. Thanks for the help btw :D

 

EDIT2: This code works, I can't hit people on my friends list on :D Thanks a lot for you help, probably wouldn't have figured it out myself!

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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