use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockCactus method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
// TODO: Drop entity if the block has near blocks
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
// check it's the highest block of cactus
if (blockAbove.isEmpty()) {
// check the current cactus height
Block blockBelow = block.getRelative(BlockFace.DOWN);
int height = 1;
while (blockBelow.getType() == Material.CACTUS) {
height++;
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
}
if (height < 3) {
GlowBlockState state = block.getState();
if (state.getRawData() < 15) {
// increase age
state.setRawData((byte) (state.getRawData() + 1));
state.update(true);
} else {
// grow the cactus on the above block
state.setRawData((byte) 0);
state.update(true);
state = blockAbove.getState();
state.setType(Material.CACTUS);
state.setRawData((byte) 0);
BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
updatePhysics(blockAbove);
}
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockBed method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
if (block.getType() == Material.BED_BLOCK) {
BlockFace direction = ((Bed) block.getState().getData()).getFacing();
GlowBlock headBlock = block.getRelative(direction);
headBlock.setType(Material.BED_BLOCK);
GlowBlockState headBlockState = headBlock.getState();
MaterialData data = headBlockState.getData();
((Bed) data).setHeadOfBed(true);
((Bed) data).setFacingDirection(direction);
headBlockState.setData(data);
headBlockState.update(true);
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class GlowPlayer method leaveBed.
/**
* This player leaves their bed causing them to quit sleeping.
*
* @param setSpawn Whether to set the bed spawn of the player
*/
public void leaveBed(boolean setSpawn) {
Preconditions.checkState(bed != null, "Player is not in bed");
GlowBlock head = BlockBed.getHead(bed);
GlowBlock foot = BlockBed.getFoot(bed);
// Determine exit location
Block exitBlock = BlockBed.getExitLocation(head, foot);
if (exitBlock == null) {
// If no empty blocks were found fallback to block above bed
exitBlock = head.getRelative(BlockFace.UP);
}
// Use center of block
Location exitLocation = exitBlock.getLocation().add(0.5, 0.1, 0.5);
// Set their spawn (normally omitted if their bed gets destroyed instead of them leaving it)
if (setSpawn) {
setBedSpawnLocation(head.getLocation());
}
// Empty the bed
BlockBed.setOccupied(head, foot, false);
bed = null;
sleeping = false;
// And eject the player
setRawLocation(exitLocation, false);
teleported = true;
// Call event
EventFactory.callEvent(new PlayerBedLeaveEvent(this, head));
getSession().send(new AnimateEntityMessage(SELF_ID, AnimateEntityMessage.LEAVE_BED));
AnimateEntityMessage msg = new AnimateEntityMessage(getEntityId(), AnimateEntityMessage.LEAVE_BED);
world.getRawPlayers().stream().filter(p -> p != this && p.canSeeEntity(this)).forEach(p -> p.getSession().send(msg));
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class GlowPlayer method getBedSpawnLocation.
@Override
public Location getBedSpawnLocation() {
if (bedSpawn == null) {
return null;
}
// Find head of bed
GlowBlock block = (GlowBlock) bedSpawn.getBlock();
GlowBlock head = BlockBed.getHead(block);
GlowBlock foot = BlockBed.getFoot(block);
if (head != null) {
// If there is a bed, try to find an empty spot next to the bed
if (head.getType() == Material.BED_BLOCK) {
Block spawn = BlockBed.getExitLocation(head, foot);
return spawn == null ? null : spawn.getLocation().add(0.5, 0.1, 0.5);
}
if (bedSpawnForced) {
Material bottom = head.getType();
Material top = head.getRelative(BlockFace.UP).getType();
// Do not check floor when forcing spawn
if (BlockBed.isValidSpawn(bottom) && BlockBed.isValidSpawn(top)) {
// No blocks are blocking the spawn
return bedSpawn.clone().add(0.5, 0.1, 0.5);
}
}
}
return null;
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class GlowPlayer method broadcastBlockBreakAnimation.
private void broadcastBlockBreakAnimation(GlowBlock block, int destroyStage) {
GlowChunk.Key key = new GlowChunk.Key(block.getChunk().getX(), block.getChunk().getZ());
block.getWorld().getRawPlayers().stream().filter(player -> player.canSeeChunk(key) && player != this).forEach(player -> player.sendBlockBreakAnimation(block.getLocation(), destroyStage));
}
Aggregations