use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockType method rightClickBlock.
@Override
public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
GlowBlock target = against.getRelative(face);
// prevent building above the height limit
if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
player.sendMessage(ChatColor.RED + "The height limit for this world is " + target.getWorld().getMaxHeight() + " blocks");
return;
}
// check whether the block clicked against should absorb the placement
BlockType againstType = ItemTable.instance().getBlock(against.getTypeId());
if (againstType != null) {
if (againstType.canAbsorb(against, face, holding)) {
target = against;
} else if (!target.isEmpty()) {
// air can always be overridden
BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
if (targetType != null && !targetType.canOverride(target, face, holding)) {
return;
}
}
}
if (getMaterial().isSolid()) {
BlockBoundingBox box = new BlockBoundingBox(target);
List<Entity> entities = target.getWorld().getEntityManager().getEntitiesInside(box, null);
for (Entity e : entities) {
if (e instanceof LivingEntity) {
return;
}
}
}
// call canBuild event
boolean canBuild = canPlaceAt(target, face);
BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(target, getId(), canBuild);
if (!EventFactory.callEvent(canBuildEvent).isBuildable()) {
//revert(player, target);
return;
}
// grab states and update block
GlowBlockState oldState = target.getState(), newState = target.getState();
ItemType itemType = ItemTable.instance().getItem(holding.getType());
if (itemType.getPlaceAs() == null) {
placeBlock(player, newState, face, holding, clickedLoc);
} else {
placeBlock(player, newState, face, new ItemStack(itemType.getPlaceAs().getMaterial(), holding.getAmount(), holding.getDurability()), clickedLoc);
}
newState.update(true);
// call blockPlace event
BlockPlaceEvent event = new BlockPlaceEvent(target, oldState, against, holding, player, canBuild);
EventFactory.callEvent(event);
if (event.isCancelled() || !event.canBuild()) {
oldState.update(true);
return;
}
// play the placement sound, except for the current player (handled by the client)
SoundUtil.playSoundAtLocationExcept(target.getLocation(), getPlaceSound().getSound(), (getPlaceSound().getVolume() + 1F) / 2F, getPlaceSound().getPitch() * 0.8F, player);
// do any after-place actions
afterPlace(player, target, holding, oldState);
// deduct from stack if not in creative mode
if (player.getGameMode() != GameMode.CREATIVE) {
holding.setAmount(holding.getAmount() - 1);
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockSugarCane method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (!canPlaceAt(block, BlockFace.DOWN)) {
block.breakNaturally();
return;
}
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
// check it's the highest block of cactus
if (blockAbove.isEmpty()) {
// check the current cane height
Block blockBelow = block.getRelative(BlockFace.DOWN);
int height = 1;
while (blockBelow.getType() == Material.SUGAR_CANE_BLOCK) {
height++;
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
}
if (height < 3) {
GlowBlockState state = block.getState();
if (state.getRawData() < 15) {
// increase age
state.setRawData((byte) (state.getRawData() + 1));
state.update(true);
} else {
// grow the sugar cane on the above block
state.setRawData((byte) 0);
state.update(true);
state = blockAbove.getState();
state.setType(Material.SUGAR_CANE_BLOCK);
state.setRawData((byte) 0);
BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
updatePhysics(blockAbove);
}
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRedstoneRepeater method receivePulse.
@Override
public void receivePulse(GlowBlock block) {
Diode diode = (Diode) block.getState().getData();
GlowBlock target = block.getRelative(diode.getFacing().getOppositeFace());
boolean powered = target.getType() == Material.REDSTONE_TORCH_ON || target.isBlockPowered() || target.getType() == Material.REDSTONE_WIRE && target.getData() > 0 && BlockRedstone.calculateConnections(target).contains(diode.getFacing()) || target.getType() == Material.DIODE_BLOCK_ON && ((Diode) target.getState().getData()).getFacing() == diode.getFacing();
if (!powered && block.getType() == Material.DIODE_BLOCK_ON) {
block.setTypeIdAndData(Material.DIODE_BLOCK_OFF.getId(), block.getData(), true);
extraUpdate(block);
} else if (powered && block.getType() == Material.DIODE_BLOCK_OFF) {
block.setTypeIdAndData(Material.DIODE_BLOCK_ON.getId(), block.getData(), true);
extraUpdate(block);
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRedstoneRepeater method extraUpdate.
private void extraUpdate(GlowBlock block) {
Diode diode = (Diode) block.getState().getData();
ItemTable itemTable = ItemTable.instance();
GlowBlock target = block.getRelative(diode.getFacing());
if (target.getType().isSolid()) {
for (BlockFace face2 : ADJACENT) {
GlowBlock target2 = target.getRelative(face2);
BlockType notifyType = itemTable.getBlock(target2.getTypeId());
if (notifyType != null) {
if (target2.getFace(block) == null) {
notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
}
notifyType.onRedstoneUpdate(target2);
}
}
}
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class BlockRedstoneTorch method extraUpdate.
private void extraUpdate(GlowBlock block) {
ItemTable itemTable = ItemTable.instance();
GlowBlock target = block.getRelative(BlockFace.UP);
if (target.getType().isSolid()) {
for (BlockFace face2 : ADJACENT) {
GlowBlock target2 = target.getRelative(face2);
BlockType notifyType = itemTable.getBlock(target2.getTypeId());
if (notifyType != null) {
if (target2.getFace(block) == null) {
notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
}
notifyType.onRedstoneUpdate(target2);
}
}
}
}
Aggregations