use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockSponge method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
// TODO: Move this to a new method when physics works and run this on neighbour change too.
MaterialData data = holding.getData();
if (!(data instanceof Sponge)) {
warnMaterialData(Sponge.class, data);
return;
}
Sponge sponge = (Sponge) data;
if (sponge.getType() == SpongeType.NORMAL) {
GlowBlock block = state.getBlock();
TaxicabBlockIterator iterator = new TaxicabBlockIterator(block);
iterator.setMaxDistance(7);
iterator.setMaxBlocks(66);
iterator.setValidator(new BlockMaterialValidator(WATER_MATERIALS));
if (iterator.hasNext()) {
sponge = sponge.clone();
sponge.setType(SpongeType.WET);
do {
iterator.next().setType(Material.AIR);
} while (iterator.hasNext());
}
}
state.setType(Material.SPONGE);
state.setData(sponge);
}
use of net.glowstone.block.GlowBlock 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.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockSugarCane method canPlaceAt.
@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
Block below = block.getRelative(BlockFace.DOWN);
Material type = below.getType();
switch(type) {
case SUGAR_CANE_BLOCK:
return true;
case DIRT:
case GRASS:
case SAND:
return isNearWater(below);
default:
return false;
}
}
use of net.glowstone.block.GlowBlock 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);
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class ItemArmorStand method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
BlockType type = ItemTable.instance().getBlock(target.getType());
GlowBlock newTarget = type.canAbsorb(target, face, holding) ? target : target.getRelative(face);
type = ItemTable.instance().getBlock(newTarget.getType());
GlowBlock upper = newTarget.getRelative(BlockFace.UP);
BlockType up = ItemTable.instance().getBlock(upper.getType());
Location loc = newTarget.getLocation().add(0.5, 0, 0.5);
if ((newTarget.isEmpty() || type == null || type.canAbsorb(target, face, holding)) && (upper.isEmpty() || up == null || up.canAbsorb(target, face, holding)) && loc.getWorld().getNearbyEntities(loc.clone().add(0, 0.5, 0), 0.5, 0.5, 0.5).isEmpty() && loc.getWorld().getNearbyEntities(loc.clone().add(0, 1.5, 0), 0.5, 0.5, 0.5).isEmpty()) {
newTarget.setType(Material.AIR);
upper.setType(Material.AIR);
float yaw = player.getLocation().getYaw();
float finalYaw = Math.round(yaw / 22.5f / 2) * 45;
loc.setYaw(finalYaw - 180);
((GlowWorld) loc.getWorld()).spawn(loc, GlowArmorStand.class, CreatureSpawnEvent.SpawnReason.DEFAULT);
if (player.getGameMode() != GameMode.CREATIVE) {
holding.setAmount(holding.getAmount() - 1);
}
}
}
Aggregations