use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockSkull method afterPlace.
@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
GlowSkull skull = (GlowSkull) block.getState();
skull.setSkullType(getType(holding.getDurability()));
if (skull.getSkullType() == SkullType.PLAYER) {
SkullMeta meta = (SkullMeta) holding.getItemMeta();
if (meta != null) {
skull.setOwner(meta.getOwner());
}
}
MaterialData data = skull.getData();
if (!(data instanceof Skull)) {
warnMaterialData(Skull.class, data);
return;
}
Skull skullData = (Skull) data;
if (canRotate(skullData)) {
// Can be rotated
skull.setRotation(player.getFacing().getOppositeFace());
}
skull.update();
// Wither
for (int i = 0; i < 3; i++) {
if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) {
block.getWorld().spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER);
break;
}
}
}
use of org.bukkit.material.MaterialData 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();
boolean absorbedWater = false;
if (data.getItemType() == Material.SPONGE) {
GlowBlock block = state.getBlock();
TaxicabBlockIterator iterator = new TaxicabBlockIterator(block);
iterator.setMaxDistance(7);
iterator.setMaxBlocks(66);
iterator.setPredicate(b -> b.getType() == Material.WATER);
if (iterator.hasNext()) {
absorbedWater = true;
do {
iterator.next().setType(Material.AIR);
} while (iterator.hasNext());
}
}
state.setType(absorbedWater ? Material.WET_SPONGE : Material.SPONGE);
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockVine method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (ThreadLocalRandom.current().nextInt(4) == 0) {
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (!(data instanceof Vine)) {
warnMaterialData(Vine.class, data);
return;
}
Vine vine = (Vine) data;
boolean hasNearVineBlocks = hasNearVineBlocks(block);
BlockFace face = ADJACENT[ThreadLocalRandom.current().nextInt(ADJACENT.length)];
if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
if (!hasNearVineBlocks) {
Vine v = (Vine) data;
for (BlockFace f : HORIZONTAL_FACES) {
if (ThreadLocalRandom.current().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 (ThreadLocalRandom.current().nextInt(2) == 0) {
v.removeFromFace(f);
}
}
putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
}
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockWater method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
super.updateBlock(block);
if (block.getLightFromBlocks() <= 11 - block.getMaterialValues().getLightOpacity()) {
if (block.getRelative(BlockFace.UP).isEmpty() && hasNearSolidBlock(block) && GlowBiomeClimate.isCold(block)) {
GlowBlockState state = block.getState();
state.setType(Material.ICE);
state.setData(new MaterialData(Material.ICE));
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(state.getBlock(), block, state);
EventFactory.getInstance().callEvent(spreadEvent);
if (!spreadEvent.isCancelled()) {
state.update(true);
}
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockOpenable method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
GlowBlockState blockState = block.getState();
MaterialData materialData = blockState.getData();
if (materialData instanceof Openable) {
Openable toOpen = (Openable) materialData;
boolean wasOpen = toOpen.isOpen();
toOpen.setOpen(!wasOpen);
if (wasOpen) {
onClosed(player, block, face, clickedLoc, blockState, materialData);
} else {
onOpened(player, block, face, clickedLoc, blockState, materialData);
}
blockState.update(true);
return true;
} else {
warnMaterialData(Openable.class, materialData);
return false;
}
}
Aggregations