Search in sources :

Example 1 with AttributeModifiable

use of net.minecraft.server.v1_16_R3.AttributeModifiable in project Citizens2 by CitizensDev.

the class PlayerControllerMove method a.

@Override
public void a() {
    this.a.aT = 0F;
    if (this.f) {
        this.f = false;
        int i = MathHelper.floor(this.a.getBoundingBox().minY + 0.5D);
        double d0 = this.b - this.a.locX();
        double d1 = this.d - this.a.locZ();
        double d2 = this.c - i;
        double d3 = d0 * d0 + d2 * d2 + d1 * d1;
        if (d3 < 2.500000277905201E-007D) {
            this.a.aT = 0.0F;
            return;
        }
        float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
        this.a.yaw = a(this.a.yaw, f, 90.0F);
        NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
        AttributeModifiable speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
        speed.setValue(0.3D * this.e);
        float movement = (float) (this.e * speed.getValue());
        this.a.q(movement);
        this.a.aT = movement;
        if (shouldSlimeJump() || (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D)) {
            this.h = cg();
            this.h /= 3;
            if (this.a instanceof EntityHumanNPC) {
                ((EntityHumanNPC) this.a).getControllerJump().jump();
            } else {
                ((EntityInsentient) this.a).getControllerJump().jump();
            }
        }
    }
}
Also used : AttributeModifiable(net.minecraft.server.v1_16_R3.AttributeModifiable) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)

Example 2 with AttributeModifiable

use of net.minecraft.server.v1_16_R3.AttributeModifiable in project Citizens2 by CitizensDev.

the class NMSImpl method attack.

@Override
public void attack(LivingEntity attacker, LivingEntity btarget) {
    EntityLiving handle = getHandle(attacker);
    EntityLiving target = getHandle(btarget);
    if (handle instanceof EntityPlayer) {
        ((EntityPlayer) handle).attack(target);
        PlayerAnimation.ARM_SWING.play((Player) handle.getBukkitEntity());
        return;
    }
    if (handle instanceof EntityInsentient) {
        ((EntityInsentient) handle).attackEntity(target);
        return;
    }
    AttributeModifiable attackDamage = handle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE);
    float f = (float) (attackDamage == null ? 1 : attackDamage.getValue());
    int i = 0;
    if (target instanceof EntityLiving) {
        f += EnchantmentManager.a(handle.getItemInMainHand(), target.getMonsterType());
        i += EnchantmentManager.a(Enchantments.KNOCKBACK, handle);
    }
    boolean flag = target.damageEntity(DamageSource.mobAttack(handle), f);
    if (!flag)
        return;
    if (i > 0) {
        target.f(-Math.sin(handle.yaw * Math.PI / 180.0F) * i * 0.5F, 0.1D, Math.cos(handle.yaw * Math.PI / 180.0F) * i * 0.5F);
        handle.setMot(handle.getMot().d(0.6, 1, 0.6));
    }
    int fireAspectLevel = EnchantmentManager.getFireAspectEnchantmentLevel(handle);
    if (fireAspectLevel > 0) {
        target.setOnFire(fireAspectLevel * 4);
    }
}
Also used : EntityLiving(net.minecraft.server.v1_16_R3.EntityLiving) AttributeModifiable(net.minecraft.server.v1_16_R3.AttributeModifiable) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) EntityInsentient(net.minecraft.server.v1_16_R3.EntityInsentient) PathPoint(net.minecraft.server.v1_16_R3.PathPoint)

Example 3 with AttributeModifiable

use of net.minecraft.server.v1_16_R3.AttributeModifiable in project Citizens2 by CitizensDev.

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (NAVIGATION_S == null)
        return;
    NavigationAbstract navigation = ((EntityInsentient) en).getNavigation();
    AttributeModifiable inst = en.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
    inst.setValue(pathfindingRange);
    int mc = MathHelper.floor(en.b(GenericAttributes.FOLLOW_RANGE) * 16.0D);
    try {
        NAVIGATION_S.invoke(navigation, NAVIGATION_A.invoke(navigation, mc));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_16_R3.EntityLiving) AttributeModifiable(net.minecraft.server.v1_16_R3.AttributeModifiable) EntityInsentient(net.minecraft.server.v1_16_R3.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_16_R3.NavigationAbstract) PathPoint(net.minecraft.server.v1_16_R3.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)

Example 4 with AttributeModifiable

use of net.minecraft.server.v1_16_R3.AttributeModifiable in project Citizens2 by CitizensDev.

the class EntityHumanNPC method initialise.

private void initialise(MinecraftServer minecraftServer) {
    Socket socket = new EmptySocket();
    NetworkManager conn = null;
    try {
        conn = new EmptyNetworkManager(EnumProtocolDirection.CLIENTBOUND);
        playerConnection = new EmptyNetHandler(minecraftServer, conn, this);
        conn.setPacketListener(playerConnection);
        socket.close();
    } catch (IOException e) {
    // swallow
    }
    AttributeModifiable range = getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
    if (range == null) {
        try {
            AttributeProvider provider = (AttributeProvider) ATTRIBUTE_MAP.invoke(getAttributeMap());
            Map<AttributeBase, AttributeModifiable> all = Maps.newHashMap((Map<AttributeBase, AttributeModifiable>) ATTRIBUTE_PROVIDER_MAP.invoke(provider));
            all.put(GenericAttributes.FOLLOW_RANGE, new AttributeModifiable(GenericAttributes.FOLLOW_RANGE, new Consumer<AttributeModifiable>() {

                @Override
                public void accept(AttributeModifiable 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 = getAttributeMap().a(GenericAttributes.FOLLOW_RANGE);
    }
    range.setValue(Setting.DEFAULT_PATHFINDING_RANGE.asDouble());
    controllerJump = new PlayerControllerJump(this);
    controllerLook = new PlayerControllerLook(this);
    controllerMove = new PlayerControllerMove(this);
    navigation = new PlayerNavigation(this, world);
    invulnerableTicks = 0;
    // the default (0) breaks step climbing
    NMS.setStepHeight(getBukkitEntity(), 1);
    setSkinFlags((byte) 0xFF);
    EmptyAdvancementDataPlayer.clear(this.getAdvancementData());
    NMSImpl.setAdvancement(this.getBukkitEntity(), new EmptyAdvancementDataPlayer(minecraftServer.getDataFixer(), minecraftServer.getPlayerList(), minecraftServer.getAdvancementData(), CitizensAPI.getDataFolder().getParentFile(), this));
}
Also used : EmptyNetworkManager(net.citizensnpcs.nms.v1_16_R3.network.EmptyNetworkManager) PlayerControllerLook(net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerLook) EmptySocket(net.citizensnpcs.nms.v1_16_R3.network.EmptySocket) IOException(java.io.IOException) EmptyNetHandler(net.citizensnpcs.nms.v1_16_R3.network.EmptyNetHandler) PlayerControllerMove(net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerMove) Consumer(java.util.function.Consumer) AttributeModifiable(net.minecraft.server.v1_16_R3.AttributeModifiable) PlayerNavigation(net.citizensnpcs.nms.v1_16_R3.util.PlayerNavigation) PlayerControllerJump(net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerJump) AttributeBase(net.minecraft.server.v1_16_R3.AttributeBase) EmptyAdvancementDataPlayer(net.citizensnpcs.nms.v1_16_R3.util.EmptyAdvancementDataPlayer) EmptyNetworkManager(net.citizensnpcs.nms.v1_16_R3.network.EmptyNetworkManager) NetworkManager(net.minecraft.server.v1_16_R3.NetworkManager) Socket(java.net.Socket) EmptySocket(net.citizensnpcs.nms.v1_16_R3.network.EmptySocket) AttributeProvider(net.minecraft.server.v1_16_R3.AttributeProvider)

Aggregations

AttributeModifiable (net.minecraft.server.v1_16_R3.AttributeModifiable)4 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)2 EntityInsentient (net.minecraft.server.v1_16_R3.EntityInsentient)2 EntityLiving (net.minecraft.server.v1_16_R3.EntityLiving)2 PathPoint (net.minecraft.server.v1_16_R3.PathPoint)2 IOException (java.io.IOException)1 Socket (java.net.Socket)1 Consumer (java.util.function.Consumer)1 EmptyNetHandler (net.citizensnpcs.nms.v1_16_R3.network.EmptyNetHandler)1 EmptyNetworkManager (net.citizensnpcs.nms.v1_16_R3.network.EmptyNetworkManager)1 EmptySocket (net.citizensnpcs.nms.v1_16_R3.network.EmptySocket)1 EmptyAdvancementDataPlayer (net.citizensnpcs.nms.v1_16_R3.util.EmptyAdvancementDataPlayer)1 PlayerControllerJump (net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerJump)1 PlayerControllerLook (net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerLook)1 PlayerControllerMove (net.citizensnpcs.nms.v1_16_R3.util.PlayerControllerMove)1 PlayerNavigation (net.citizensnpcs.nms.v1_16_R3.util.PlayerNavigation)1 AttributeBase (net.minecraft.server.v1_16_R3.AttributeBase)1 AttributeProvider (net.minecraft.server.v1_16_R3.AttributeProvider)1 EntityPlayer (net.minecraft.server.v1_16_R3.EntityPlayer)1 NavigationAbstract (net.minecraft.server.v1_16_R3.NavigationAbstract)1