Search in sources :

Example 1 with EntitySize

use of net.minecraft.server.v1_14_R1.EntitySize in project Citizens2 by CitizensDev.

the class NMSImpl method setSize.

public static void setSize(Entity entity, boolean justCreated) {
    try {
        EntitySize entitysize = (EntitySize) SIZE_FIELD_GETTER.invoke(entity);
        EntityPose entitypose = entity.getPose();
        EntitySize entitysize1 = entity.a(entitypose);
        SIZE_FIELD_SETTER.invoke(entity, entitysize1);
        HEAD_HEIGHT.invoke(entity, HEAD_HEIGHT_METHOD.invoke(entity, entitypose, entitysize1));
        if (entitysize1.width < entitysize.width && false) /* TODO: PREVIOUS CITIZENS ADDITION ?reason */
        {
            double d0 = entitysize1.width / 2.0D;
            entity.a(new AxisAlignedBB(entity.locX() - d0, entity.locY(), entity.locZ() - d0, entity.locX() + d0, entity.locY() + entitysize1.height, entity.locZ() + d0));
        } else {
            AxisAlignedBB axisalignedbb = entity.getBoundingBox();
            entity.a(new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ, axisalignedbb.minX + entitysize1.width, axisalignedbb.minY + entitysize1.height, axisalignedbb.minZ + entitysize1.width));
            if (entitysize1.width > entitysize.width && !justCreated && !entity.world.isClientSide) {
                float f = entitysize.width - entitysize1.width;
                entity.move(EnumMoveType.SELF, new Vec3D(f, 0.0D, f));
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_16_R3.AxisAlignedBB) EntitySize(net.minecraft.server.v1_16_R3.EntitySize) Vec3D(net.minecraft.server.v1_16_R3.Vec3D) EntityPose(net.minecraft.server.v1_16_R3.EntityPose)

Example 2 with EntitySize

use of net.minecraft.server.v1_14_R1.EntitySize in project Citizens2 by CitizensDev.

the class NMSImpl method checkAndUpdateHeight.

public static void checkAndUpdateHeight(EntityLiving living, DataWatcherObject<?> datawatcherobject) {
    EntitySize size;
    try {
        size = (EntitySize) SIZE_FIELD_GETTER.invoke(living);
    } catch (Throwable e) {
        e.printStackTrace();
        living.a(datawatcherobject);
        return;
    }
    float oldw = size.width;
    float oldl = size.height;
    living.a(datawatcherobject);
    if (oldw != size.width || size.height != oldl) {
        living.setPosition(living.locX() - 0.01, living.locY(), living.locZ() - 0.01);
        living.setPosition(living.locX() + 0.01, living.locY(), living.locZ() + 0.01);
    }
}
Also used : EntitySize(net.minecraft.server.v1_15_R1.EntitySize)

Example 3 with EntitySize

use of net.minecraft.server.v1_14_R1.EntitySize in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
    net.minecraft.server.v1_14_R1.Entity raw = getHandle(entity);
    raw.onGround = true;
    // not sure of a better way around this - if onGround is false, then
    // navigation won't execute, and calling entity.move doesn't
    // entirely fix the problem.
    final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof EntityPlayer) {
            ((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
        } else {
            ((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
        }
    }
    return new MCNavigator() {

        float lastSpeed;

        CancelReason reason;

        @Override
        public CancelReason getCancelReason() {
            return reason;
        }

        @Override
        public Iterable<Vector> getPath() {
            return new NavigationIterable(navigation);
        }

        @Override
        public void stop() {
            if (params.debug() && navigation.l() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.l().e(); i++) {
                        PathPoint pp = navigation.l().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getBlockData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof EntityPlayer) {
                    ((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
                } else {
                    ((EntityInsentient) raw).a(PathType.WATER, oldWater);
                }
            }
            stopNavigation(navigation);
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change");
                }
                Entity handle = getHandle(entity);
                EntitySize size = null;
                try {
                    size = (EntitySize) SIZE_FIELD_GETTER.invoke(handle);
                    if (handle instanceof EntityHorse) {
                        SIZE_FIELD_SETTER.invoke(handle, new EntitySize(Math.min(0.99F, size.width), size.height, false));
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                try {
                    SIZE_FIELD_SETTER.invoke(handle, size);
                } catch (Throwable e) {
                    e.printStackTrace();
                // minecraft requires that an entity fit onto both blocks if width >= 1f, but we'd prefer to
                // make it just fit on 1 so hack around it a bit.
                }
                lastSpeed = params.speed();
            }
            if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
                BlockData data = Material.DANDELION.createBlockData();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.l().e(); i++) {
                        PathPoint pp = navigation.l().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), data);
                    }
                }
            }
            navigation.a(params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_14_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) EntityPlayer(net.minecraft.server.v1_14_R1.EntityPlayer) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) AdvancementDataPlayer(net.minecraft.server.v1_14_R1.AdvancementDataPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntitySize(net.minecraft.server.v1_14_R1.EntitySize) EntityInsentient(net.minecraft.server.v1_14_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_14_R1.NavigationAbstract) PathPoint(net.minecraft.server.v1_14_R1.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC) PathPoint(net.minecraft.server.v1_14_R1.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_14_R1.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) Entity(net.minecraft.server.v1_14_R1.Entity) EntityPlayer(net.minecraft.server.v1_14_R1.EntityPlayer) IBlockData(net.minecraft.server.v1_14_R1.IBlockData) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector)

Example 4 with EntitySize

use of net.minecraft.server.v1_14_R1.EntitySize in project Citizens2 by CitizensDev.

the class NMSImpl method checkAndUpdateHeight.

public static void checkAndUpdateHeight(EntityLiving living, DataWatcherObject<?> datawatcherobject) {
    EntitySize size;
    try {
        size = (EntitySize) SIZE_FIELD_GETTER.invoke(living);
    } catch (Throwable e) {
        e.printStackTrace();
        living.a(datawatcherobject);
        return;
    }
    float oldw = size.width;
    float oldl = size.height;
    living.a(datawatcherobject);
    if (oldw != size.width || size.height != oldl) {
        living.setPosition(living.locX - 0.01, living.locY, living.locZ - 0.01);
        living.setPosition(living.locX + 0.01, living.locY, living.locZ + 0.01);
    }
}
Also used : EntitySize(net.minecraft.server.v1_14_R1.EntitySize)

Example 5 with EntitySize

use of net.minecraft.server.v1_14_R1.EntitySize in project MyPet by xXKeyleXx.

the class EntityRegistry method registerEntityType.

@SuppressWarnings("unchecked")
protected void registerEntityType(MyPetType petType, String key, RegistryBlocks<EntityTypes<?>> entityRegistry) {
    EntitySize size = entityRegistry.get(new MinecraftKey(key.toLowerCase())).l();
    entityTypes.put(petType, IRegistry.a(entityRegistry, "mypet_" + key.toLowerCase(), EntityTypes.Builder.a(EnumCreatureType.CREATURE).b().a().a(size.width, size.height).a(key)));
    registerDefaultAttributes(entityTypes.get(petType), (EntityTypes<? extends EntityLiving>) ReflectionUtil.getFieldValue(EntityTypes.class, null, ("" + petType.getTypeID()).toUpperCase()));
    overwriteEntityID(entityTypes.get(petType), getEntityTypeId(petType, entityRegistry), entityRegistry);
}
Also used : EntitySize(net.minecraft.server.v1_16_R3.EntitySize) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Aggregations

EntitySize (net.minecraft.server.v1_16_R3.EntitySize)4 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)3 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)3 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)3 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)3 EntitySize (net.minecraft.server.v1_14_R1.EntitySize)3 EntitySize (net.minecraft.server.v1_15_R1.EntitySize)3 BlockData (org.bukkit.block.data.BlockData)3 LivingEntity (org.bukkit.entity.LivingEntity)3 Player (org.bukkit.entity.Player)3 Vector (org.bukkit.util.Vector)3 EntityHumanNPC (net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)1 EntityHumanNPC (net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)1 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)1 AdvancementDataPlayer (net.minecraft.server.v1_14_R1.AdvancementDataPlayer)1 AxisAlignedBB (net.minecraft.server.v1_14_R1.AxisAlignedBB)1 Entity (net.minecraft.server.v1_14_R1.Entity)1 EntityHorse (net.minecraft.server.v1_14_R1.EntityHorse)1 EntityInsentient (net.minecraft.server.v1_14_R1.EntityInsentient)1 EntityPlayer (net.minecraft.server.v1_14_R1.EntityPlayer)1