use of net.glowstone.block.GlowBlockState 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.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockCrops method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
GlowBlockState state = block.getState();
int cropState = block.getData() + random.nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal();
if (cropState > CropState.RIPE.ordinal()) {
cropState = CropState.RIPE.ordinal();
}
state.setRawData((byte) cropState);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockSoil method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (isNearWater(block) || GlowBiomeClimate.isRainy(block)) {
// set this block as fully wet
block.setData((byte) 7);
} else if (block.getData() > 0) {
// if this block is wet, it becomes less wet
block.setData((byte) (block.getData() - 1));
} else if (!Arrays.asList(possibleCrops).contains(block.getRelative(BlockFace.UP).getType())) {
// turns block back to dirt if nothing is planted on
GlowBlockState state = block.getState();
state.setType(Material.DIRT);
state.setRawData((byte) 0);
BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
EventFactory.callEvent(fadeEvent);
if (!fadeEvent.isCancelled()) {
state.update(true);
}
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockStem method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
// in order to grow naturally (vanilla behavior)
if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
int cropState = block.getData();
if (cropState >= CropState.RIPE.ordinal()) {
// check around there's not already a fruit
if (block.getRelative(BlockFace.EAST).getType() == fruitType || block.getRelative(BlockFace.WEST).getType() == fruitType || block.getRelative(BlockFace.NORTH).getType() == fruitType || block.getRelative(BlockFace.SOUTH).getType() == fruitType) {
return;
}
// produce a fruit if possible
int n = random.nextInt(4);
BlockFace face;
switch(n) {
case 1:
face = BlockFace.WEST;
break;
case 2:
face = BlockFace.NORTH;
break;
case 3:
face = BlockFace.SOUTH;
break;
default:
face = BlockFace.EAST;
}
GlowBlock targetBlock = block.getRelative(face);
GlowBlockState targetBlockState = targetBlock.getState();
GlowBlock belowTargetBlock = targetBlock.getRelative(BlockFace.DOWN);
if (targetBlock.getType() == Material.AIR && (belowTargetBlock.getType() == Material.SOIL || belowTargetBlock.getType() == Material.DIRT || belowTargetBlock.getType() == Material.GRASS)) {
targetBlockState.setType(fruitType);
if (fruitType == Material.PUMPKIN) {
targetBlockState.setData(new Pumpkin(face.getOppositeFace()));
}
targetBlockState.update(true);
}
} else {
cropState++;
GlowBlockState state = block.getState();
state.setRawData((byte) cropState);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
}
// we check for insufficient light on the block itself, then drop
if (block.getLightLevel() < 8) {
block.breakNaturally();
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockVine method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (random.nextInt(4) == 0) {
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (data instanceof Vine) {
Vine vine = (Vine) data;
boolean hasNearVineBlocks = hasNearVineBlocks(block);
BlockFace face = FACES[random.nextInt(FACES.length)];
if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
if (!hasNearVineBlocks) {
Vine v = (Vine) data;
for (BlockFace f : HORIZONTAL_FACES) {
if (random.nextInt(2) == 0 || !block.getRelative(f).getRelative(face).getType().isSolid()) {
v.removeFromFace(f);
}
}
putVineOnHorizontalBlockFace(block.getRelative(face), v, block);
}
} else if (Arrays.asList(HORIZONTAL_FACES).contains(face) && !vine.isOnFace(face)) {
if (!hasNearVineBlocks) {
GlowBlock b = block.getRelative(face);
if (b.isEmpty()) {
BlockFace clockwiseFace = getClockwiseFace(face);
BlockFace counterClockwiseFace = getCounterClockwiseFace(face);
GlowBlock clockwiseBlock = b.getRelative(clockwiseFace);
GlowBlock counterClockwiseBlock = b.getRelative(counterClockwiseFace);
boolean isOnCWFace = vine.isOnFace(clockwiseFace);
boolean isOnCCWFace = vine.isOnFace(counterClockwiseFace);
if (isOnCWFace && clockwiseBlock.getType().isSolid()) {
putVine(b, new Vine(clockwiseFace), block);
} else if (isOnCCWFace && counterClockwiseBlock.getType().isSolid()) {
putVine(b, new Vine(counterClockwiseFace), block);
} else if (isOnCWFace && clockwiseBlock.isEmpty() && block.getRelative(clockwiseFace).getType().isSolid()) {
putVine(clockwiseBlock, new Vine(face.getOppositeFace()), block);
} else if (isOnCCWFace && counterClockwiseBlock.isEmpty() && block.getRelative(counterClockwiseFace).getType().isSolid()) {
putVine(counterClockwiseBlock, new Vine(face.getOppositeFace()), block);
} else if (b.getRelative(BlockFace.UP).getType().isSolid()) {
putVine(b, new Vine(), block);
}
} else if (b.getType().isOccluding()) {
vine.putOnFace(face);
putVine(block, vine, null);
}
}
} else if (block.getY() > 1) {
GlowBlock b = block.getRelative(BlockFace.DOWN);
Vine v = (Vine) data;
if (b.getType() == Material.VINE || b.isEmpty()) {
for (BlockFace f : HORIZONTAL_FACES) {
if (random.nextInt(2) == 0) {
v.removeFromFace(f);
}
}
putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
}
}
} else {
warnMaterialData(Vine.class, data);
}
}
}
Aggregations