Skip to content

Commit

Permalink
Support getting chunk bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon5550 committed Feb 14, 2015
1 parent 9955aa0 commit a79bd04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class BukkitCommandRegistrar implements CommandRegistrar

/**
* A reference to bukkit's {@link CommandMap}.
* <p>
* TODO: possible memory leak if bukkit attempts to recreate this map,
* perhaps across reloads.
*/
private CommandMap commands;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.voxelplugineering.voxelsniper.api.entity.Entity;
import com.voxelplugineering.voxelsniper.api.world.World;
import com.voxelplugineering.voxelsniper.api.world.material.Material;
import com.voxelplugineering.voxelsniper.util.math.Vector3i;
import com.voxelplugineering.voxelsniper.world.material.BukkitMaterial;

/**
Expand All @@ -38,6 +39,10 @@
public class BukkitChunk extends AbstractChunk<Chunk>
{

private final Vector3i min;
private final Vector3i max;
private static final Vector3i CHUNK_SIZE = new Vector3i(16, 256, 16);

/**
* Creates a new {@link BukkitChunk} wrapping the given bukkit {@link Chunk}
* .
Expand All @@ -48,6 +53,8 @@ public class BukkitChunk extends AbstractChunk<Chunk>
public BukkitChunk(Chunk chunk, World world)
{
super(chunk, world);
this.min = new Vector3i(chunk.getX() * 16, 0, chunk.getZ() * 16);
this.max = new Vector3i(chunk.getX() * 16 + 15, 255, chunk.getZ() * 16 + 15);
}

/**
Expand All @@ -56,14 +63,18 @@ public BukkitChunk(Chunk chunk, World world)
@Override
public Optional<com.voxelplugineering.voxelsniper.api.world.Block> getBlock(int x, int y, int z)
{
if (x < 0 || x > 15 || z < 0 || z > 15 || y < 0 || y > 255)
{
return Optional.absent();
}
Block b = getThis().getBlock(x, y, z);
CommonLocation l = new CommonLocation(this.getWorld(), b.getX(), b.getY(), b.getZ());
Optional<Material> m = this.getWorld().getMaterialRegistry().getMaterial(b.getType().name());
if (!m.isPresent())
{
return Optional.absent();
}
return Optional.<com.voxelplugineering.voxelsniper.api.world.Block>of(new CommonBlock(l, m.get()));
return Optional.<com.voxelplugineering.voxelsniper.api.world.Block> of(new CommonBlock(l, m.get()));
}

/**
Expand All @@ -72,7 +83,7 @@ public Optional<com.voxelplugineering.voxelsniper.api.world.Block> getBlock(int
@Override
public void setBlock(Material material, int x, int y, int z)
{
//TODO range checks
// TODO range checks
if (material instanceof BukkitMaterial)
{
BukkitMaterial bukkitMaterial = (BukkitMaterial) material;
Expand All @@ -86,16 +97,44 @@ public void setBlock(Material material, int x, int y, int z)
@Override
public Iterable<Entity> getLoadedEntities()
{
return null; //TODO
return null; // TODO
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("deprecation")
@Override
public void refreshChunk()
{
((BukkitWorld) this.getWorld()).getThis().refreshChunk(getThis().getX(), getThis().getZ());
}

/**
* {@inheritDoc}
*/
@Override
public Vector3i getMinBound()
{
return this.min;
}

/**
* {@inheritDoc}
*/
@Override
public Vector3i getMaxBound()
{
return this.max;
}

/**
* {@inheritDoc}
*/
@Override
public Vector3i getSize()
{
return CHUNK_SIZE;
}

}

0 comments on commit a79bd04

Please sign in to comment.