Skip to content

Commit

Permalink
Add Voxel class
Browse files Browse the repository at this point in the history
Got to merge that math branch…
  • Loading branch information
DDoS committed Sep 10, 2014
1 parent 49c4d1b commit 4c22bef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Abstract class for map block events
*/
public abstract class BlockEvent extends SpongeEvent {

// TODO: use voxel instead to provide the location and block at once?
public final Block block;

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/spongepowered/api/world/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public interface Chunk {
* @return The block
*/
Block getBlock(int x, int y, int z);

/**
* Gets the {@link org.spongepowered.api.world.Voxel} at the block coordinate x/y/z.
*
* @param x X block coordinate
* @param y Y block coordinate
* @param z Z block coordinate
* @throws IllegalArgumentException If coordinates given are outside the chunk's bounds
* @return The voxel
*/
Voxel getVoxel(int x, int y, int z);
}
52 changes: 52 additions & 0 deletions src/main/java/org/spongepowered/api/world/Voxel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) 2014 SpongePowered <http://spongepowered.org/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.world;

import org.spongepowered.api.block.Block;

/**
* Represents the smallest unit of the world map. This unit
* has a position with integer coordinates and a block reference
* which defines it's behaviour and attributes. Unlike a block,
* this object has a position attribute, and does not define any logic
* by itself.
*/
public interface Voxel {

/**
* Gets the voxel's position in the world map.
*
* @return position The voxel's position
*/
// TODO: uncomment this once the math branch is merged
//Vector3i getPosition();

/**
* Gets a reference to the block object that
* defines the voxel's logic.
*
* @return block The block defining the voxel
*/
Block getBlock();
}
9 changes: 9 additions & 0 deletions src/main/java/org/spongepowered/api/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ public interface World {
* @return The block
*/
Block getBlock(int x, int y, int z);

/**
* Gets a specific {@link org.spongepowered.api.world.Voxel} by its x/y/z block coordinate.
* @param x X block coordinate
* @param y Y block coordinate
* @param z Z block coordinate
* @return The voxel
*/
Voxel getVoxel(int x, int y, int z);
}

0 comments on commit 4c22bef

Please sign in to comment.