use of io.xol.chunkstories.api.world.WorldMaster in project chunkstories-core by Hugobros3.
the class VoxelDoor method onRemove.
@Override
public void onRemove(ChunkCell context, WorldModificationCause cause) {
// Don't interfere with system pokes, else we get stuck in a loop
if (cause == null || !(cause instanceof Entity))
return;
World world = context.getWorld();
int x = context.getX();
int y = context.getY();
int z = context.getZ();
// Ignore all that crap on a slave world
if (!(world instanceof WorldMaster))
return;
int otherPartOfTheDoorY = y;
if (top)
otherPartOfTheDoorY--;
else
otherPartOfTheDoorY++;
Voxel restOfTheDoorVoxel = world.peekSimple(x, otherPartOfTheDoorY, z);
// Remove the other part as well, if it still exists
if (restOfTheDoorVoxel instanceof VoxelDoor)
world.pokeSimple(x, otherPartOfTheDoorY, z, store().air(), -1, -1, 0);
}
use of io.xol.chunkstories.api.world.WorldMaster in project chunkstories-core by Hugobros3.
the class VoxelDoor method onPlace.
@Override
public void onPlace(FutureCell cell, WorldModificationCause cause) throws IllegalBlockModificationException {
// Ignore all that crap on a slave world
if (!(cell.getWorld() instanceof WorldMaster))
return;
// We should only place the lower part, prevent entities from doing so !
if (top && cause != null && cause instanceof Entity)
throw new IllegalBlockModificationException(cell, "Entities can't place upper doors parts");
// If the system adds the upper part, no modifications to be done on it
if (top)
return;
World world = cell.getWorld();
int x = cell.getX();
int y = cell.getY();
int z = cell.getZ();
// Check top is free
int topData = world.peekRaw(x, y + 1, z);
if (VoxelFormat.id(topData) != 0)
throw new IllegalBlockModificationException(cell, "Top part isn't free");
// grab our attributes
boolean isOpen = ((cell.getMetaData() >> 0) & 0x1) == 1;
boolean hingeSide = ((cell.getMetaData() >> 1) & 0x1) == 1;
int facingPassed = (cell.getMetaData() >> 2) & 0x3;
// Default face is given by passed metadata
VoxelSide doorSideFacing = VoxelSide.values()[facingPassed];
// Determine side if placed by an entity and not internal code
if (cause != null && cause instanceof Entity) {
Location loc = ((Entity) cause).getLocation();
double dx = loc.x() - (x + 0.5);
double dz = loc.z() - (z + 0.5);
if (Math.abs(dx) > Math.abs(dz)) {
if (dx > 0)
doorSideFacing = VoxelSide.RIGHT;
else
doorSideFacing = VoxelSide.LEFT;
} else {
if (dz > 0)
doorSideFacing = VoxelSide.FRONT;
else
doorSideFacing = VoxelSide.BACK;
}
// If there is an adjacent one, set the hinge to right
Voxel adjacent = null;
switch(doorSideFacing) {
case LEFT:
adjacent = world.peekSimple(x, y, z - 1);
break;
case RIGHT:
adjacent = world.peekSimple(x, y, z + 1);
break;
case FRONT:
adjacent = world.peekSimple(x - 1, y, z);
break;
case BACK:
adjacent = world.peekSimple(x + 1, y, z);
break;
default:
break;
}
if (adjacent instanceof VoxelDoor) {
hingeSide = true;
}
cell.setMetaData(computeMeta(isOpen, hingeSide, doorSideFacing));
}
// Place the upper part and we're good to go
world.pokeSimple(x, y + 1, z, this.getUpperPart(), -1, -1, cell.getMetaData());
}
Aggregations