use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockLever method extraUpdate.
private void extraUpdate(GlowBlock block) {
Lever lever = (Lever) block.getState().getData();
ItemTable itemTable = ItemTable.instance();
GlowBlock target = block.getRelative(lever.getAttachedFace());
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 org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class ProjectileDispenseBehavior method dispenseStack.
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
GlowWorld world = block.getWorld();
Vector position = BlockDispenser.getDispensePosition(block);
BlockFace face = BlockDispenser.getFacing(block);
Projectile entity = getProjectileEntity(world, position);
entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
stack.setAmount(stack.getAmount() - 1);
if (stack.getAmount() < 1) {
return null;
}
return stack;
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class ArmorDispenseBehavior method dispenseStack.
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
BlockFace facing = BlockDispenser.getFacing(block);
Location targetLocation = block.getLocation().clone().add(facing.getModX(), facing.getModY(), facing.getModZ());
// Find all nearby entities and see if they are players or armor stands
List<LivingEntity> entities = new ArrayList<>();
for (Entity entity : targetLocation.getWorld().getNearbyEntities(targetLocation, 3, 3, 3)) {
switch(entity.getType()) {
case PLAYER:
entities.add((LivingEntity) entity);
break;
}
}
boolean targetLocationTest1;
boolean targetLocationTest2;
// Loop through entities to see if any are in the location where armor would be dispensed
for (LivingEntity player : entities) {
targetLocationTest1 = (player.getLocation().getBlockX() == targetLocation.getX() && player.getLocation().getBlockY() == targetLocation.getY() && player.getLocation().getBlockZ() == targetLocation.getZ());
targetLocationTest2 = (player.getEyeLocation().getBlockX() == targetLocation.getX() && player.getEyeLocation().getBlockY() == targetLocation.getY() && player.getEyeLocation().getBlockZ() == targetLocation.getZ());
if ((targetLocationTest1 || targetLocationTest2)) {
return ((GlowInventory) ((Player) player).getInventory()).tryToFillSlots(stack, 36, 40);
}
}
// Fallback
return defaultBehavior.dispense(block, stack);
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class GlowChest method getInventory.
@Override
public Inventory getInventory() {
GlowBlock me = getBlock();
BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
BlockFace attachedChest = blockChest.getAttachedChest(me);
if (attachedChest != null) {
Block nearbyBlock = me.getRelative(attachedChest);
GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
switch(attachedChest) {
case SOUTH:
case EAST:
return new GlowDoubleChestInventory(this, nearbyChest);
case WEST:
case NORTH:
return new GlowDoubleChestInventory(nearbyChest, this);
default:
GlowServer.logger.warning("GlowChest#getInventory() can only handle N/O/S/W BlockFaces, got " + attachedChest);
return getBlockInventory();
}
}
return getBlockInventory();
}
use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.
the class BlockBed method getExitLocation.
/**
* Returns an 'empty' block next to the bed used to put the player at when they exit a bed / respawn.
*
* @param head head of the bed
* @param foot foot of the bed
* @return Exit block or {@code null} if all spots are blocked
*/
public static Block getExitLocation(GlowBlock head, GlowBlock foot) {
// First check blocks near head
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
Block b = head.getRelative(x, 0, z);
boolean floorValid = b.getRelative(BlockFace.DOWN).getType().isSolid();
boolean bottomValid = isValidSpawn(b.getType());
boolean topValid = isValidSpawn(b.getRelative(BlockFace.UP).getType());
if (floorValid && bottomValid && topValid) {
return b;
}
}
}
// Then check the last three blocks near foot
BlockFace face = head.getFace(foot);
int modX = face.getModX();
int modZ = face.getModZ();
for (int x = modX == 0 ? -1 : modX; x <= (modX == 0 ? 1 : modX); x++) {
for (int z = modZ == 0 ? -1 : modZ; z <= (modZ == 0 ? 1 : modZ); z++) {
Block b = foot.getRelative(x, 0, z);
boolean floorValid = b.getRelative(BlockFace.DOWN).getType().isSolid();
boolean bottomValid = isValidSpawn(b.getType());
boolean topValid = isValidSpawn(b.getRelative(BlockFace.UP).getType());
if (floorValid && bottomValid && topValid) {
return b;
}
}
}
return null;
}
Aggregations