/** * Multiply each dimension in the current position by the given factor. * @param factor - multiplier. * @return The new result. */ public BlockPosition multiply(int factor) { return new BlockPosition(x * factor, y * factor, z * factor); }
Players.sendBlockChange(player, location, Material.WALL_SIGN); BlockPosition position = new BlockPosition(location.toVector()); PacketContainer writeToSign = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA); writeToSign.getBlockPositionModifier().write(0, position); compound.put("x", position.getX()); compound.put("y", position.getY()); compound.put("z", position.getZ());
/** * Retrieves a read/write structure for block positions. * @return A modifier for a BlockPosition. */ public StructureModifier<BlockPosition> getBlockPositionModifier() { // Convert to and from the Bukkit wrapper return structureModifier.withType( MinecraftReflection.getBlockPositionClass(), BlockPosition.getConverter()); }
Players.sendBlockChange(player, location, Material.WALL_SIGN); BlockPosition position = new BlockPosition(location.toVector()); PacketContainer writeToSign = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA); writeToSign.getBlockPositionModifier().write(0, position); compound.put("x", position.getX()); compound.put("y", position.getY()); compound.put("z", position.getZ());
/** * Retrieves a read/write structure for collections of chunk positions. * <p> * This modifier will automatically marshal between the visible ProtocolLib BlockPosition and the * internal Minecraft BlockPosition. * * @return A modifier for ChunkPosition list fields. */ public StructureModifier<List<BlockPosition>> getBlockPositionCollectionModifier() { // Convert to and from the ProtocolLib wrapper return structureModifier.withType( Collection.class, BukkitConverters.getListConverter(BlockPosition.getConverter())); }
/** * Adds the current position and a given position together, producing a result position. * @param other - the other position. * @return The new result position. */ public BlockPosition add(BlockPosition other) { if (other == null) throw new IllegalArgumentException("other cannot be NULL"); return new BlockPosition(x + other.x, y + other.y, z + other.z); }
return Vector3F.getConverter().getGeneric((Vector3F) wrapped); } else if (wrapped instanceof BlockPosition) { return BlockPosition.getConverter().getGeneric((BlockPosition) wrapped); } else if (wrapped instanceof Direction) { return EnumWrappers.getDirectionConverter().getGeneric((Direction) wrapped);
/** * Adds the current position and a given position together, producing a result position. * @param other - the other position. * @return The new result position. */ public BlockPosition subtract(BlockPosition other) { if (other == null) throw new IllegalArgumentException("other cannot be NULL"); return new BlockPosition(x - other.x, y - other.y, z - other.z); }
return Vector3F.getConverter().getSpecific(value); } else if (is(MinecraftReflection.getBlockPositionClass(), value)) { return BlockPosition.getConverter().getSpecific(value); } else if (is(EnumWrappers.getDirectionClass(), value)) { return EnumWrappers.getDirectionConverter().getSpecific(value);
/** * Divide each dimension in the current position by the given divisor. * @param divisor - the divisor. * @return The new result. */ public BlockPosition divide(int divisor) { if (divisor == 0) throw new IllegalArgumentException("Cannot divide by null."); return new BlockPosition(x / divisor, y / divisor, z / divisor); }
@Override protected Object fromString(String string) { String[] split = string.split(","); if (split.length != 3) { return null; } return new BlockPosition(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])); } }
@Override public BlockPosition getSpecific(Object generic) { if (MinecraftReflection.isBlockPosition(generic)) { // Use a structure modifier intModifier = new StructureModifier<>(generic.getClass(), null, false).withType(int.class); // Damn it all if (intModifier.size() < 3) { throw new IllegalStateException("Cannot read class " + generic.getClass() + " for its integer fields."); } if (intModifier.size() >= 3) { try { StructureModifier<Integer> instance = intModifier.withTarget(generic); BlockPosition result = new BlockPosition(instance.read(0), instance.read(1), instance.read(2)); return result; } catch (FieldAccessException e) { // This is an exeptional work-around, so we don't want to burden the caller with the messy details throw new RuntimeException("Field access error.", e); } } } // Otherwise, return NULL return null; }
public static PacketContainer[] getBedPackets(Location sleepingLocation, Location playerLocation, PlayerDisguise disguise) { int entity = disguise.getEntity().getEntityId(); PlayerWatcher watcher = disguise.getWatcher(); PacketContainer setBed = new PacketContainer(Server.BED); int bX = (getChunkCord(playerLocation.getBlockX()) * 16) + 1 + watcher.getSleepingDirection().getModX(); int bZ = (getChunkCord(playerLocation.getBlockZ()) * 16) + 1 + watcher.getSleepingDirection().getModZ(); setBed.getIntegers().write(0, entity); setBed.getBlockPositionModifier().write(0, new BlockPosition(bX, 0, bZ)); PacketContainer teleport = new PacketContainer(Server.ENTITY_TELEPORT); StructureModifier<Double> doubles = teleport.getDoubles(); teleport.getIntegers().write(0, entity); doubles.write(0, sleepingLocation.getX()); doubles.write(1, DisguiseUtilities.getYModifier(disguise.getEntity(), disguise) + sleepingLocation.getY()); doubles.write(2, sleepingLocation.getZ()); return new PacketContainer[]{setBed, teleport}; }