Jump to content

Recommended Posts

Posted

I have a keybind that will damage entities and of course keybinds are client-side. If I use entity.attackEntityFrom() it doesn't work because that is a server-side function. Is there a packet built in to damage entities or do I need to write my own one?

Posted

Here is the packet:

package com.leo.lbacraft.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.util.DamageSource;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class PacketDamageEntity implements IMessage {
	public static class Handler implements IMessageHandler<PacketDamageEntity, IMessage> {
		@Override
		public IMessage onMessage(PacketDamageEntity message, MessageContext ctx) {
			System.out.println("Server" + message.ID);
			
			Minecraft.getMinecraft().world.getEntityByID(message.ID).attackEntityFrom(DamageSource.MAGIC, message.damage);
			
			return null;
		}
		
	}
	
	public int ID;
	public float damage;
	
	public PacketDamageEntity() {
		
	}
	
	public PacketDamageEntity(int ID, float damage) {
		this.ID = ID;
		this.damage = damage;
	}
	
	@Override
	public void fromBytes(ByteBuf buf) {
		ID = buf.readInt();
		damage = buf.readFloat();
	}

	@Override
	public void toBytes(ByteBuf buf) {
		buf.writeInt(ID);
		buf.writeFloat(damage);
	}

}

It still doesn't damage the entities.

  • 3 months later...
Posted
On 7/22/2017 at 5:16 AM, diesieben07 said:

I think I'm having a similar problem, I'm trying to do:

 

boolean isSuccessfulAttack = target.attackEntityFrom(DamageSource.causePlayerDamage(player), damage);

 

But that doesn't work. Then I read this thread and thought it might work if I call it from the server but I don't know how to do that, I tried:

 

boolean isSuccessfulAttack = Minecraft.getMinecraft().getIntegratedServer().getEntityFromUuid(target.getUniqueID()).attackEntityFrom(DamageSource.causePlayerDamage(player), damage);

 

But that doesn't work either. I know about client side and server side and I have my proxies setup but I'm trying to do this in my event handler class so what should I do?

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



×
×
  • Create New...

Important Information

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