Posted July 16, 20178 yr 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?
July 22, 20178 yr 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.
November 13, 20177 yr On 7/22/2017 at 5:16 AM, diesieben07 said: Read the warning on the networking docs. Minecraft::world is the client world. What you are doing here is known as "reaching across logical sides" and it does not work. 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.