use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockLitRedstoneOre method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlockState state = block.getState();
state.setType(Material.REDSTONE_ORE);
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 BlockLog method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
// vanilla set leaf decay check in a 9x9x9 neighboring when a log block is removed
GlowWorld world = block.getWorld();
for (int x = 0; x < 9; x++) {
for (int z = 0; z < 9; z++) {
for (int y = 0; y < 9; y++) {
GlowBlock b = world.getBlockAt(block.getLocation().add(x - 4, y - 4, z - 4));
if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
GlowBlockState state = b.getState();
if ((state.getRawData() & 0x08) == 0 && (state.getRawData() & 0x04) == 0) {
// check decay is off and decay is on
// set decay check on for this leaves block
state.setRawData((byte) (state.getRawData() | 0x08));
state.update(true);
}
}
}
}
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockLava method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
super.updateBlock(block);
if (!block.getWorld().getGameRuleMap().getBoolean("doFireTick")) {
return;
}
int n = random.nextInt(3);
if (n == 0) {
for (int i = 0; i < 3; i++) {
GlowBlock b = (GlowBlock) block.getLocation().add(-1 + random.nextInt(3), 0, -1 + random.nextInt(3)).getBlock();
GlowBlock bAbove = b.getRelative(BlockFace.UP);
if (bAbove.isEmpty() && b.isFlammable()) {
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(bAbove, IgniteCause.LAVA, block);
EventFactory.callEvent(igniteEvent);
if (!igniteEvent.isCancelled()) {
GlowBlockState state = bAbove.getState();
state.setType(Material.FIRE);
state.update(true);
}
}
}
} else {
for (int i = 0; i < n; i++) {
GlowBlock b = (GlowBlock) block.getLocation().add(-1 + random.nextInt(3), 1, -1 + random.nextInt(3)).getBlock();
if (b.isEmpty()) {
if (hasNearFlammableBlock(b)) {
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(b, IgniteCause.LAVA, block);
EventFactory.callEvent(igniteEvent);
if (!igniteEvent.isCancelled()) {
GlowBlockState state = b.getState();
state.setType(Material.FIRE);
state.update(true);
}
break;
}
} else if (b.getType().isSolid()) {
break;
}
}
}
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockStateDelegate method setType.
/**
* Sets a block type and add it to the BlockState list.
*
* @param world the world which contains the block
* @param x the x-coordinate of this block
* @param y the y-coordinate of this block
* @param z the z-coordinate of this block
* @param type the new type of this block
*/
public void setType(World world, int x, int y, int z, Material type) {
GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
state.setType(type);
blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.
the class BlockCrops method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlockState state = block.getState();
int cropState = block.getData();
// in order to grow naturally (vanilla behavior)
if (cropState < CropState.RIPE.ordinal() && block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
cropState++;
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);
}
}
// we check for insufficient light on the block itself, then drop
if (block.getLightLevel() < 8) {
block.breakNaturally();
}
}
Aggregations