use of net.minecraft.server.v1_15_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();
}
}
use of net.minecraft.server.v1_15_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);
}
}
use of net.minecraft.server.v1_15_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);
}
};
}
use of net.minecraft.server.v1_15_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);
}
}
use of net.minecraft.server.v1_15_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);
}
Aggregations