public void face(BlockLocation target, int face) { BlockLocation offset = getOffsetBlock(target, face); if (offset == null) { face(target); return; } double x = offset.getX() + ((target.getX() - offset.getX()) / 2.0D) + 0.5; double y = offset.getY() + ((target.getY() - offset.getY()) / 2.0D); double z = offset.getZ() + ((target.getZ() - offset.getZ()) / 2.0D) + 0.5; face(x, y, z); }
@Override public void setBlockMetadataAt(int metadata, BlockLocation blockLocation) { ChunkLocation location = new ChunkLocation(blockLocation); BlockLocation chunkBlockOffset = new BlockLocation(location); Chunk chunk = getChunkAt(location); if (chunk == null) return; chunk.setBlockMetadataAt( metadata, blockLocation.getX() - chunkBlockOffset.getX(), blockLocation.getY() - chunkBlockOffset.getY(), blockLocation.getZ() - chunkBlockOffset.getZ()); }
@Override public int getBlockMetadataAt(BlockLocation blockLocation) { ChunkLocation location = new ChunkLocation(blockLocation); BlockLocation chunkBlockOffset = new BlockLocation(location); Chunk chunk = getChunkAt(location); if (chunk == null) return 0; int metadata = chunk.getBlockMetadataAt( blockLocation.getX() - chunkBlockOffset.getX(), blockLocation.getY() - chunkBlockOffset.getY(), blockLocation.getZ() - chunkBlockOffset.getZ()); return metadata; }
@Override public Block getBlockAt(BlockLocation location) { ChunkLocation chunkLocation = new ChunkLocation(location); Chunk chunk = getChunkAt(chunkLocation); if (chunk == null) return null; BlockLocation chunkBlockOffset = new BlockLocation(chunkLocation); int chunkOffsetX = location.getX() - chunkBlockOffset.getX(); int chunkOffsetY = location.getY() - chunkBlockOffset.getY(); int chunkOffsetZ = location.getZ() - chunkBlockOffset.getZ(); int id = chunk.getBlockIdAt(chunkOffsetX, chunkOffsetY, chunkOffsetZ); int metadata = chunk.getBlockMetadataAt(chunkOffsetX, chunkOffsetY, chunkOffsetZ); return new Block(this, chunk, location, id, metadata); }
private BlockLocation getOffsetBlock(BlockLocation location, int face) { int x = location.getX(), y = location.getY(), z = location.getZ(); switch (face) { case 0: return new BlockLocation(x, y + 1, z); case 1: return new BlockLocation(x, y - 1, z); case 2: return new BlockLocation(x, y, z + 1); case 3: return new BlockLocation(x, y, z - 1); case 4: return new BlockLocation(x + 1, y, z); case 5: return new BlockLocation(x - 1, y, z); default: return null; } }
public void face(BlockLocation target) { face(target.getX() + 0.5, target.getY() + 0.5, target.getZ() + 0.5); }