Действие по нажатию кнопки.

Версия Minecraft
1.12.2
586
32
136
Нужно при нажатии кнопки Z , что-бы спавнилась пуля, которая при колизии с ентити пишет определённое значение в его нбт-тег .
 
586
32
136
При нажатии кнопки посылать пакет на сервер и спавнить пулю, в пуле есть метод onImpact или что-то типа такого, не помню точно. В нем делается остальное. Как вариант
Так и сделал, но значение не пишет, поушин тоже.
 
586
32
136
Отправка пакета:
Java:
    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void press(InputEvent.KeyInputEvent e){
        if (KeybindsRegister.FREEZE.isPressed()) {
            Packet.createPacket(2).sendToServer();
        }
    }

Java:
public class ServerPacketHandler implements ICustomPacketHandler.IServerPacketHandler
{
    @Override
    public void handlePacket(PacketCustom packetCustom, EntityPlayerMP player, INetHandlerPlayServer iNetHandlerPlayServer) {
        switch (packetCustom.getType()){
            case 1:{
                Item item = CrazyGangsSpells.FREEZE;
                if(player.getCooldownTracker().hasCooldown(item))break;
                EntityRay ray = new EntityRay(player.world,player,item,0);
                ray.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
                player.world.spawnEntity(ray);
                player.getCooldownTracker().setCooldown(item,220);
            }
        }
    }
}
EntityRay
Java:
public class EntityRay extends EntityThrowable {
    EntityPlayer thrower;
    int time;
        public EntityRay(World world) {
            super(world);
        }

        public EntityRay(World world, EntityPlayer thrower,Item item,int time) {
            super(world, thrower);
            this.thrower = thrower;
            this.getEntityData().setString("Type",item.getRegistryName().getResourcePath());
            this.time = time;
        }
    @Override
    public void onImpact(RayTraceResult rayTraceResult) {
        if (rayTraceResult.typeOfHit == RayTraceResult.Type.ENTITY) {
            if(rayTraceResult.entityHit == this){
                if (!this.world.isRemote) {
                    this.world.setEntityState(this, (byte)4);
                    this.setDead();
                    return;
                }
            }
            if(this.getEntityData().getString("Type") == CrazyGangsSpells.FREEZE.getRegistryName().getResourcePath()){
                if (!this.world.isRemote) {
                    rayTraceResult.entityHit.getEntityData().setBoolean("Freeze",true);
                    this.world.setEntityState(this, (byte)5);
                    this.setDead();
                    return;
                }
            }
        }
}


    @SideOnly(Side.CLIENT)
    @Override
    public void handleStatusUpdate(byte a) {
            switch (a){
                case 5:{
                    for(int i = 0; i < 64; ++i) {
                        this.world.spawnParticle(EnumParticleTypes.NOTE, this.posX, this.posY+1, this.posZ, rand.nextGaussian()/16,rand.nextGaussian()/16,rand.nextGaussian()/16);
                    }
                    return;
                }
            }
        }
}
 
Последнее редактирование модератором:
Сверху