use of net.minecraft.server.v1_16_R2.BlockPosition in project Citizens2 by CitizensDev.
the class PlayerPathfinderNormal method b.
@Override
public PathPoint b() {
int var0;
BlockPosition var1;
if (this.e() && this.b.isInWater()) {
var0 = MathHelper.floor(this.b.locY());
MutableBlockPosition varx = new MutableBlockPosition(this.b.locX(), var0, this.b.locZ());
for (IBlockData var2 = this.a.getType(varx); var2.getBlock() == Blocks.WATER || var2.getFluid() == FluidTypes.WATER.a(false); var2 = this.a.getType(varx)) {
++var0;
varx.c(this.b.locX(), var0, this.b.locZ());
}
--var0;
} else if (this.b.onGround) {
var0 = MathHelper.floor(this.b.locY() + 0.5D);
} else {
for (var1 = new BlockPosition(this.b); (this.a.getType(var1).isAir() || this.a.getType(var1).a(this.a, var1, PathMode.LAND)) && var1.getY() > 0; var1 = var1.down()) {
}
var0 = var1.up().getY();
}
var1 = new BlockPosition(this.b);
PathType var2 = this.a(this.b, var1.getX(), var0, var1.getZ());
if (this.b.a(var2) < 0.0F) {
Set<BlockPosition> var3 = Sets.newHashSet();
var3.add(new BlockPosition(this.b.getBoundingBox().minX, var0, this.b.getBoundingBox().minZ));
var3.add(new BlockPosition(this.b.getBoundingBox().minX, var0, this.b.getBoundingBox().maxZ));
var3.add(new BlockPosition(this.b.getBoundingBox().maxX, var0, this.b.getBoundingBox().minZ));
var3.add(new BlockPosition(this.b.getBoundingBox().maxX, var0, this.b.getBoundingBox().maxZ));
Iterator<BlockPosition> var5 = var3.iterator();
while (var5.hasNext()) {
BlockPosition varb = var5.next();
PathType var6 = this.a(this.b, varb);
if (this.b.a(var6) >= 0.0F) {
return this.a(varb.getX(), varb.getY(), varb.getZ());
}
}
}
return this.a(var1.getX(), var0, var1.getZ());
}
use of net.minecraft.server.v1_16_R2.BlockPosition in project Citizens2 by CitizensDev.
the class NMSImpl method getCollisionBox.
@Override
public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
WorldServer world = ((CraftWorld) block.getWorld()).getHandle();
BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ());
AxisAlignedBB aabb = world.getType(pos).c(world, pos);
if (aabb == null) {
aabb = world.getType(pos).d(world, pos);
}
return new BoundingBox(aabb.a, aabb.b, aabb.c, aabb.d, aabb.e, aabb.f);
}
use of net.minecraft.server.v1_16_R2.BlockPosition in project Citizens2 by CitizensDev.
the class PlayerAnimationImpl method play.
public static void play(PlayerAnimation animation, Player bplayer, int radius) {
// TODO: this is pretty gross
final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
if (DEFAULTS.containsKey(animation)) {
playDefaultAnimation(player, radius, DEFAULTS.get(animation));
return;
}
switch(animation) {
case SIT:
player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
if (registry == null) {
registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
}
final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
holder.spawn(player.getBukkitEntity().getLocation());
ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
trait.setGravity(false);
trait.setHasArms(false);
trait.setHasBaseplate(false);
trait.setSmall(true);
trait.setMarker(true);
trait.setVisible(false);
holder.getOrAddTrait(ArmorStandTrait.class).setVisible(false);
holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
new BukkitRunnable() {
@Override
public void cancel() {
super.cancel();
holder.destroy();
}
@Override
public void run() {
if (player.dead || !player.valid || !player.getBukkitEntity().hasMetadata("citizens.sitting") || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
cancel();
return;
}
if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
cancel();
return;
}
if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
NMS.mount(holder.getEntity(), player.getBukkitEntity());
}
}
}.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
break;
case START_ELYTRA:
player.M();
break;
case SLEEP:
PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
sendPacketNearby(packet, player, radius);
break;
case SNEAK:
player.getBukkitEntity().setSneaking(true);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case START_USE_MAINHAND_ITEM:
player.c(EnumHand.MAIN_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case START_USE_OFFHAND_ITEM:
player.c(EnumHand.OFF_HAND);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case STOP_SITTING:
player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
NMS.mount(player.getBukkitEntity(), null);
break;
case STOP_SLEEPING:
playDefaultAnimation(player, radius, 2);
break;
case STOP_SNEAKING:
player.getBukkitEntity().setSneaking(false);
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
case STOP_USE_ITEM:
player.clearActiveItem();
sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
break;
default:
throw new UnsupportedOperationException();
}
}
use of net.minecraft.server.v1_16_R2.BlockPosition in project Citizens2 by CitizensDev.
the class PlayerNavigation method a2.
public PathEntity a2(BlockPosition paramBlockPosition) {
if (!b()) {
return null;
}
if ((this.c != null) && (!this.c.b()) && (paramBlockPosition.equals(this.q))) {
return this.c;
}
this.q = paramBlockPosition;
float f1 = h();
this.b.methodProfiler.a("pathfind");
BlockPosition localBlockPosition = new BlockPosition(this.a);
int i1 = (int) (f1 + 8.0F);
ChunkCache localChunkCache = new ChunkCache(this.b, localBlockPosition.a(-i1, -i1, -i1), localBlockPosition.a(i1, i1, i1), 0);
PathEntity localPathEntity = this.r.a(localChunkCache, this.a, this.q, f1);
this.b.methodProfiler.b();
return localPathEntity;
}
use of net.minecraft.server.v1_16_R2.BlockPosition in project Citizens2 by CitizensDev.
the class PlayerPathfinderNormal method a.
@Override
public PathType a(IBlockAccess paramIBlockAccess, int paramInt1, int paramInt2, int paramInt3, EntityInsentient paramEntityInsentient, int paramInt4, int paramInt5, int paramInt6, boolean paramBoolean1, boolean paramBoolean2) {
EnumSet<PathType> localEnumSet = EnumSet.noneOf(PathType.class);
PathType localObject1 = PathType.BLOCKED;
BlockPosition localBlockPosition = new BlockPosition(paramEntityInsentient);
for (int i = 0; i < paramInt4; i++) {
for (int k = 0; k < paramInt5; k++) {
for (int m = 0; m < paramInt6; m++) {
int n = i + paramInt1;
int i1 = k + paramInt2;
int i2 = m + paramInt3;
PathType localPathType2 = a(paramIBlockAccess, n, i1, i2);
if ((localPathType2 == PathType.DOOR_WOOD_CLOSED) && (paramBoolean1) && (paramBoolean2)) {
localPathType2 = PathType.WALKABLE;
}
if ((localPathType2 == PathType.DOOR_OPEN) && (!paramBoolean2)) {
localPathType2 = PathType.BLOCKED;
}
if ((localPathType2 == PathType.RAIL) && (!(paramIBlockAccess.getType(localBlockPosition).getBlock() instanceof BlockMinecartTrackAbstract)) && (!(paramIBlockAccess.getType(localBlockPosition.down()).getBlock() instanceof BlockMinecartTrackAbstract))) {
localPathType2 = PathType.FENCE;
}
if ((i == 0) && (k == 0) && (m == 0)) {
localObject1 = localPathType2;
}
localEnumSet.add(localPathType2);
}
}
}
if (localEnumSet.contains(PathType.FENCE)) {
return PathType.FENCE;
}
PathType localObject2 = PathType.BLOCKED;
for (PathType localPathType1 : localEnumSet) {
if (paramEntityInsentient.a(localPathType1) < 0.0F) {
return localPathType1;
}
if (paramEntityInsentient.a(localPathType1) >= paramEntityInsentient.a(localObject2)) {
localObject2 = localPathType1;
}
}
if ((localObject1 == PathType.OPEN) && (paramEntityInsentient.a(localObject2) == 0.0F)) {
return PathType.OPEN;
}
return localObject2;
}
Aggregations