use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class BlockChest method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
BlockState state = block.getState();
if (state instanceof org.bukkit.block.Chest) {
org.bukkit.block.Chest chest = (org.bukkit.block.Chest) state;
player.openInventory(chest.getInventory());
player.incrementStatistic(Statistic.CHEST_OPENED);
return true;
}
ConsoleMessages.Warn.Block.Chest.INTERACT_WRONG_CLASS.log(state);
return false;
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class BlockChest method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Chest) {
Chest chest = (Chest) data;
GlowBlock chestBlock = state.getBlock();
BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
Collection<BlockFace> attachedChests = searchChests(chestBlock);
switch(attachedChests.size()) {
case 0:
chest.setFacingDirection(normalFacing);
state.setData(chest);
return;
case 1:
break;
default:
ConsoleMessages.Warn.Block.Chest.TRIPLE_MIDDLE.log();
return;
}
BlockFace otherPart = attachedChests.iterator().next();
GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
if (getAttachedChest(otherPartBlock) != null) {
ConsoleMessages.Warn.Block.Chest.TRIPLE_END.log();
return;
}
BlockState otherPartState = otherPartBlock.getState();
MaterialData otherPartData = otherPartState.getData();
if (otherPartData instanceof Chest) {
Chest otherChest = (Chest) otherPartData;
BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
chest.setFacingDirection(facing);
state.setData(chest);
otherChest.setFacingDirection(facing);
otherPartState.setData(otherChest);
otherPartState.update();
} else {
warnMaterialData(Chest.class, otherPartData);
}
} else {
warnMaterialData(Chest.class, data);
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class BlockEnderPortalFrame method createPortal.
/**
* Spawn the portal and call the {@link EntityCreatePortalEvent}.
*/
private void createPortal(GlowPlayer player, GlowBlock center) {
List<BlockState> blocks = new ArrayList<>(9);
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
BlockState state = center.getRelative(i, 0, j).getState();
state.setType(Material.END_PORTAL);
blocks.add(state);
}
}
if (!EventFactory.getInstance().callEvent(new EntityCreatePortalEvent(player, blocks, PortalType.ENDER)).isCancelled()) {
for (BlockState state : blocks) {
state.update(true);
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class BlockSapling method generateTree.
private void generateTree(TreeType type, GlowBlock block, GlowPlayer player) {
// get data but filters sapling age
int data = block.getData() & 0x7;
// replaces the sapling block(s)
block.setType(Material.AIR);
if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
block.getRelative(BlockFace.SOUTH).setType(Material.AIR);
block.getRelative(BlockFace.EAST).setType(Material.AIR);
block.getRelative(BlockFace.SOUTH_EAST).setType(Material.AIR);
}
// try to generate a tree
Location loc = block.getLocation();
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
boolean canGrow = false;
if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate).generate(loc)) {
List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, player != null, player, blockStates);
EventFactory.getInstance().callEvent(growEvent);
if (!growEvent.isCancelled()) {
canGrow = true;
for (BlockState state : blockStates) {
state.update(true);
}
}
}
if (!canGrow) {
// places the sapling block(s) back if the tree was not generated
// the sapling ages are overwritten but this is an expected
// vanilla behavior
// TODO: 1.13 sapling types
block.setType(Material.LEGACY_SAPLING);
block.setData((byte) data);
if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
block.getRelative(BlockFace.SOUTH).setType(Material.LEGACY_SAPLING);
block.getRelative(BlockFace.SOUTH).setData((byte) data);
block.getRelative(BlockFace.EAST).setType(Material.LEGACY_SAPLING);
block.getRelative(BlockFace.EAST).setData((byte) data);
block.getRelative(BlockFace.SOUTH_EAST).setType(Material.LEGACY_SAPLING);
block.getRelative(BlockFace.SOUTH_EAST).setData((byte) data);
}
}
}
use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class GlowstoneDecorator method decorate.
@Override
public void decorate(World world, Random random, Chunk source) {
int amount = variableAmount ? 1 + random.nextInt(1 + random.nextInt(10)) : 10;
for (int i = 0; i < amount; i++) {
int sourceX = (source.getX() << 4) + random.nextInt(16);
int sourceZ = (source.getZ() << 4) + random.nextInt(16);
int sourceY = 4 + random.nextInt(120);
Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
if (!block.isEmpty() || block.getRelative(BlockFace.UP).getType() != Material.NETHERRACK) {
continue;
}
BlockState state = block.getState();
state.setType(Material.GLOWSTONE);
state.update(true);
for (int j = 0; j < 1500; j++) {
int x = sourceX + random.nextInt(8) - random.nextInt(8);
int z = sourceZ + random.nextInt(8) - random.nextInt(8);
int y = sourceY - random.nextInt(12);
block = world.getBlockAt(x, y, z);
if (!block.isEmpty()) {
continue;
}
int glowstoneBlockCount = 0;
for (BlockFace face : SIDES) {
if (block.getRelative(face).getType() == Material.GLOWSTONE) {
glowstoneBlockCount++;
}
}
if (glowstoneBlockCount == 1) {
state = block.getState();
state.setType(Material.GLOWSTONE);
state.update(true);
}
}
}
}
Aggregations