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

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?

  • Author

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

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.