/** * Multiply each dimension in the current position by the given factor. * @param factor - multiplier. * @return The new result. */ public ChunkPosition multiply(int factor) { return new ChunkPosition(x * factor, y * factor, z * factor); }
/** * Retrieve the equivalent chunk position. * @param y - the y position. * @return The chunk position. */ public ChunkPosition getPosition(int y) { return new ChunkPosition((chunkX << 4) + 8, y, (chunkZ << 4) + 8); }
/** * Adds the current position and a given position together, producing a result position. * @param other - the other position. * @return The new result position. */ public ChunkPosition subtract(ChunkPosition other) { if (other == null) throw new IllegalArgumentException("other cannot be NULL"); return new ChunkPosition(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 ChunkPosition add(ChunkPosition other) { if (other == null) throw new IllegalArgumentException("other cannot be NULL"); return new ChunkPosition(x + other.x, y + other.y, z + other.z); }
/** * Divide each dimension in the current position by the given divisor. * @param divisor - the divisor. * @return The new result. */ public ChunkPosition divide(int divisor) { if (divisor == 0) throw new IllegalArgumentException("Cannot divide by null."); return new ChunkPosition(x / divisor, y / divisor, z / divisor); }
/** * Create an immutable chunk position from this coordinate. * @return The new immutable chunk position. */ public ChunkPosition toPosition() { return new ChunkPosition(getX(), getY(), getZ()); }
@Override public ChunkPosition getSpecific(Object generic) { if (MinecraftReflection.isChunkPosition(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); ChunkPosition result = new ChunkPosition(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; }