Search in sources :

Example 1 with PlayerLookControl

use of net.citizensnpcs.nms.v1_18_R2.util.PlayerLookControl in project Citizens2 by CitizensDev.

the class EntityHumanNPC method initialise.

private void initialise(MinecraftServer minecraftServer) {
    Socket socket = new EmptySocket();
    EmptyNetworkManager conn = null;
    try {
        conn = new EmptyNetworkManager(PacketFlow.CLIENTBOUND);
        connection = new EmptyNetHandler(minecraftServer, conn, this);
        conn.setListener(connection);
        socket.close();
    } catch (IOException e) {
    // swallow
    }
    AttributeInstance range = getAttribute(Attributes.FOLLOW_RANGE);
    if (range == null) {
        try {
            AttributeSupplier provider = (AttributeSupplier) ATTRIBUTE_SUPPLIER.invoke(getAttributes());
            Map<Attribute, AttributeInstance> all = Maps.newHashMap((Map<Attribute, AttributeInstance>) ATTRIBUTE_PROVIDER_MAP.invoke(provider));
            all.put(Attributes.FOLLOW_RANGE, new AttributeInstance(Attributes.FOLLOW_RANGE, new Consumer<AttributeInstance>() {

                @Override
                public void accept(AttributeInstance att) {
                    throw new UnsupportedOperationException("Tried to change value for default attribute instance FOLLOW_RANGE");
                }
            }));
            ATTRIBUTE_PROVIDER_MAP_SETTER.invoke(provider, ImmutableMap.copyOf(all));
        } catch (Throwable e) {
            e.printStackTrace();
        }
        range = getAttribute(Attributes.FOLLOW_RANGE);
    }
    range.setBaseValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
    controllerJump = new PlayerControllerJump(this);
    controllerLook = new PlayerLookControl(this);
    controllerMove = new PlayerMoveControl(this);
    navigation = new PlayerNavigation(this, level);
    this.invulnerableTime = 0;
    // the default (0) breaks step climbing
    NMS.setStepHeight(getBukkitEntity(), 1);
    setSkinFlags((byte) 0xFF);
    EmptyAdvancementDataPlayer.clear(this.getAdvancements());
    NMSImpl.setAdvancement(this.getBukkitEntity(), new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(), minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
Also used : EmptyNetworkManager(net.citizensnpcs.nms.v1_17_R1.network.EmptyNetworkManager) EmptySocket(net.citizensnpcs.nms.v1_17_R1.network.EmptySocket) AttributeSupplier(net.minecraft.world.entity.ai.attributes.AttributeSupplier) Attribute(net.minecraft.world.entity.ai.attributes.Attribute) PlayerLookControl(net.citizensnpcs.nms.v1_17_R1.util.PlayerLookControl) IOException(java.io.IOException) EmptyNetHandler(net.citizensnpcs.nms.v1_17_R1.network.EmptyNetHandler) Consumer(java.util.function.Consumer) PlayerNavigation(net.citizensnpcs.nms.v1_17_R1.util.PlayerNavigation) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) PlayerControllerJump(net.citizensnpcs.nms.v1_17_R1.util.PlayerControllerJump) EmptyAdvancementDataPlayer(net.citizensnpcs.nms.v1_17_R1.util.EmptyAdvancementDataPlayer) PlayerMoveControl(net.citizensnpcs.nms.v1_17_R1.util.PlayerMoveControl) EmptySocket(net.citizensnpcs.nms.v1_17_R1.network.EmptySocket) Socket(java.net.Socket)

Example 2 with PlayerLookControl

use of net.citizensnpcs.nms.v1_18_R2.util.PlayerLookControl in project Citizens2 by CitizensDev.

the class EntityHumanNPC method initialise.

private void initialise(MinecraftServer minecraftServer) {
    Socket socket = new EmptySocket();
    EmptyNetworkManager conn = null;
    try {
        conn = new EmptyNetworkManager(PacketFlow.CLIENTBOUND);
        connection = new EmptyNetHandler(minecraftServer, conn, this);
        conn.setListener(connection);
        socket.close();
    } catch (IOException e) {
    // swallow
    }
    AttributeInstance range = getAttribute(Attributes.FOLLOW_RANGE);
    if (range == null) {
        try {
            AttributeSupplier provider = (AttributeSupplier) ATTRIBUTE_SUPPLIER.invoke(getAttributes());
            Map<Attribute, AttributeInstance> all = Maps.newHashMap((Map<Attribute, AttributeInstance>) ATTRIBUTE_PROVIDER_MAP.invoke(provider));
            all.put(Attributes.FOLLOW_RANGE, new AttributeInstance(Attributes.FOLLOW_RANGE, new Consumer<AttributeInstance>() {

                @Override
                public void accept(AttributeInstance att) {
                    throw new UnsupportedOperationException("Tried to change value for default attribute instance FOLLOW_RANGE");
                }
            }));
            ATTRIBUTE_PROVIDER_MAP_SETTER.invoke(provider, ImmutableMap.copyOf(all));
        } catch (Throwable e) {
            e.printStackTrace();
        }
        range = getAttribute(Attributes.FOLLOW_RANGE);
    }
    range.setBaseValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
    controllerJump = new PlayerControllerJump(this);
    controllerLook = new PlayerLookControl(this);
    controllerMove = new PlayerMoveControl(this);
    navigation = new PlayerNavigation(this, level);
    this.invulnerableTime = 0;
    // the default (0) breaks step climbing
    NMS.setStepHeight(getBukkitEntity(), 1);
    setSkinFlags((byte) 0xFF);
    EmptyAdvancementDataPlayer.clear(this.getAdvancements());
    NMSImpl.setAdvancement(this.getBukkitEntity(), new EmptyAdvancementDataPlayer(minecraftServer.getFixerUpper(), minecraftServer.getPlayerList(), minecraftServer.getAdvancements(), CitizensAPI.getDataFolder().getParentFile(), this));
}
Also used : EmptyNetworkManager(net.citizensnpcs.nms.v1_18_R2.network.EmptyNetworkManager) EmptySocket(net.citizensnpcs.nms.v1_18_R2.network.EmptySocket) AttributeSupplier(net.minecraft.world.entity.ai.attributes.AttributeSupplier) Attribute(net.minecraft.world.entity.ai.attributes.Attribute) PlayerLookControl(net.citizensnpcs.nms.v1_18_R2.util.PlayerLookControl) IOException(java.io.IOException) EmptyNetHandler(net.citizensnpcs.nms.v1_18_R2.network.EmptyNetHandler) Consumer(java.util.function.Consumer) PlayerNavigation(net.citizensnpcs.nms.v1_18_R2.util.PlayerNavigation) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) PlayerControllerJump(net.citizensnpcs.nms.v1_18_R2.util.PlayerControllerJump) EmptyAdvancementDataPlayer(net.citizensnpcs.nms.v1_18_R2.util.EmptyAdvancementDataPlayer) PlayerMoveControl(net.citizensnpcs.nms.v1_18_R2.util.PlayerMoveControl) EmptySocket(net.citizensnpcs.nms.v1_18_R2.network.EmptySocket) Socket(java.net.Socket)

Aggregations

IOException (java.io.IOException)2 Socket (java.net.Socket)2 Consumer (java.util.function.Consumer)2 Attribute (net.minecraft.world.entity.ai.attributes.Attribute)2 AttributeInstance (net.minecraft.world.entity.ai.attributes.AttributeInstance)2 AttributeSupplier (net.minecraft.world.entity.ai.attributes.AttributeSupplier)2 EmptyNetHandler (net.citizensnpcs.nms.v1_17_R1.network.EmptyNetHandler)1 EmptyNetworkManager (net.citizensnpcs.nms.v1_17_R1.network.EmptyNetworkManager)1 EmptySocket (net.citizensnpcs.nms.v1_17_R1.network.EmptySocket)1 EmptyAdvancementDataPlayer (net.citizensnpcs.nms.v1_17_R1.util.EmptyAdvancementDataPlayer)1 PlayerControllerJump (net.citizensnpcs.nms.v1_17_R1.util.PlayerControllerJump)1 PlayerLookControl (net.citizensnpcs.nms.v1_17_R1.util.PlayerLookControl)1 PlayerMoveControl (net.citizensnpcs.nms.v1_17_R1.util.PlayerMoveControl)1 PlayerNavigation (net.citizensnpcs.nms.v1_17_R1.util.PlayerNavigation)1 EmptyNetHandler (net.citizensnpcs.nms.v1_18_R2.network.EmptyNetHandler)1 EmptyNetworkManager (net.citizensnpcs.nms.v1_18_R2.network.EmptyNetworkManager)1 EmptySocket (net.citizensnpcs.nms.v1_18_R2.network.EmptySocket)1 EmptyAdvancementDataPlayer (net.citizensnpcs.nms.v1_18_R2.util.EmptyAdvancementDataPlayer)1 PlayerControllerJump (net.citizensnpcs.nms.v1_18_R2.util.PlayerControllerJump)1 PlayerLookControl (net.citizensnpcs.nms.v1_18_R2.util.PlayerLookControl)1