use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockFire method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (!block.getWorld().getGameRuleMap().getBoolean("doFireTick")) {
return;
}
GlowWorld world = block.getWorld();
Material type = block.getRelative(BlockFace.DOWN).getType();
boolean isInfiniteFire;
switch(type) {
case NETHERRACK:
isInfiniteFire = true;
break;
case BEDROCK:
if (world.getEnvironment() == Environment.THE_END) {
isInfiniteFire = true;
break;
}
default:
isInfiniteFire = false;
break;
}
if (!isInfiniteFire && world.hasStorm() && isRainingAround(block)) {
// if it's raining around, stop fire
block.breakNaturally();
return;
}
// increase fire age
GlowBlockState state = block.getState();
int age = state.getRawData();
if (age < MAX_FIRE_AGE) {
// increase fire age
state.setRawData((byte) (age + random.nextInt(3) / 2));
state.update(true);
}
if (!isInfiniteFire) {
if (!hasNearFlammableBlock(block)) {
// there's no flammable blocks around, stop fire
if (age > 3 || block.getRelative(BlockFace.DOWN).isEmpty()) {
block.breakNaturally();
world.cancelPulse(block);
}
} else if (age == MAX_FIRE_AGE && !block.getRelative(BlockFace.DOWN).isFlammable() && random.nextInt(4) == 0) {
// if fire reached max age, bottom block is not flammable, 25% chance to stop fire
block.breakNaturally();
world.cancelPulse(block);
} else {
// fire propagation / block burning
// burn blocks around
boolean isWet = GlowBiomeClimate.isWet(block);
for (Entry<BlockFace, Integer> entry : BURNRESISTANCE_MAP.entrySet()) {
burnBlock(block.getRelative(entry.getKey()), entry.getValue() - (isWet ? 50 : 0), age);
}
Difficulty difficulty = world.getDifficulty();
int difficultyModifier;
switch(difficulty) {
case EASY:
difficultyModifier = 7;
break;
case NORMAL:
difficultyModifier = 14;
break;
case HARD:
difficultyModifier = 21;
break;
default:
difficultyModifier = 0;
break;
}
// try to propagate fire in a 3x3x6 box
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
for (int y = -1; y <= 4; y++) {
if (x != 0 || z != 0 || y != 0) {
GlowBlock propagationBlock = world.getBlockAt(block.getLocation().add(x, y, z));
int flameResistance = getFlameResistance(propagationBlock);
if (flameResistance > 0) {
int resistance = (40 + difficultyModifier + flameResistance) / (30 + age);
if (isWet) {
resistance /= 2;
}
if ((!world.hasStorm() || !isRainingAround(propagationBlock)) && resistance > 0 && random.nextInt(y > 1 ? 100 + 100 * (y - 1) : 100) <= resistance) {
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(propagationBlock, IgniteCause.SPREAD, block);
EventFactory.callEvent(igniteEvent);
if (!igniteEvent.isCancelled()) {
if (propagationBlock.getType() == Material.TNT) {
BlockTNT.igniteBlock(propagationBlock, false);
} else {
int increasedAge = increaseFireAge(age);
state = propagationBlock.getState();
state.setType(Material.FIRE);
state.setRawData((byte) (increasedAge > MAX_FIRE_AGE ? MAX_FIRE_AGE : increasedAge));
state.update(true);
world.requestPulse(propagationBlock);
}
}
}
}
}
}
}
}
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockGrass method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
GlowWorld world = block.getWorld();
int i = 0;
do {
int j = 0;
while (true) {
// if there's available space
if (block.getRelative(BlockFace.UP).getType() == Material.AIR) {
GlowBlock b = block.getRelative(BlockFace.UP);
GlowBlockState blockState = b.getState();
if (random.nextFloat() < 0.125D) {
// sometimes grow random flower
// would be better to call a method that choose a random
// flower depending on the biome
FlowerType[] flowers = FlowerForestPopulator.FLOWERS;
Material flower = flowers[random.nextInt(flowers.length)].getType();
if (ItemTable.instance().getBlock(flower).canPlaceAt(b, BlockFace.DOWN)) {
blockState.setType(flower);
}
} else {
Material tallGrass = Material.LONG_GRASS;
if (ItemTable.instance().getBlock(tallGrass).canPlaceAt(b, BlockFace.DOWN)) {
// grow tall grass if possible
blockState.setType(tallGrass);
blockState.setData(new LongGrass(GrassSpecies.NORMAL));
}
}
BlockGrowEvent growEvent = new BlockGrowEvent(b, blockState);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
blockState.update(true);
}
} else if (j < i / 16) {
// look around for grass block
int x = block.getX();
int y = block.getY();
int z = block.getZ();
x += random.nextInt(3) - 1;
y += random.nextInt(3) * random.nextInt(3) / 2;
z += random.nextInt(3) - 1;
if (world.getBlockAt(x, y, z).getType() == Material.GRASS) {
j++;
continue;
}
}
i++;
break;
}
} while (i < 128);
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockLog2 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.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockDispenser method updatePhysics.
@Override
public void updatePhysics(GlowBlock block) {
GlowBlock up = block.getRelative(BlockFace.UP);
boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered() || up.isBlockPowered() || up.isBlockIndirectlyPowered();
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (!(data instanceof Dispenser)) {
return;
}
boolean isTriggered = (data.getData() >> 3 & 1) != 0;
if (powered && !isTriggered) {
new BukkitRunnable() {
@Override
public void run() {
trigger(block);
}
}.runTaskLater(null, 4);
// TODO replace this with dispenser materialdata class (as soon as it provides access to this property)
data.setData((byte) (data.getData() | 0x8));
state.update();
} else if (!powered && isTriggered) {
data.setData((byte) (data.getData() & ~0x8));
state.update();
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockDoor method onBlockChanged.
@Override
public void onBlockChanged(GlowBlock block, Material oldType, byte oldData, Material newType, byte newData) {
if (newType != Material.AIR) {
return;
}
if (oldType.getData() == Door.class) {
Door door = new Door(oldType);
door.setData(oldData);
if (door.isTopHalf()) {
Block b = block.getRelative(BlockFace.DOWN);
if (b.getState().getData() instanceof Door) {
b.setType(Material.AIR);
}
} else {
Block b = block.getRelative(BlockFace.UP);
if (b.getState().getData() instanceof Door) {
b.setType(Material.AIR);
}
}
}
}
Aggregations