/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
@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; }
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);
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);
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}; }