use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.
the class GlowWorld method updateBlocksInSection.
private void updateBlocksInSection(GlowChunk chunk, ChunkSection section, int i) {
if (section != null) {
for (int j = 0; j < 3; j++) {
int n = random.nextInt();
int x = n & 0xF;
int z = n >> 8 & 0xF;
int y = n >> 16 & 0xF;
int type = section.getType(x, y, z) >> 4;
if (type != 0) {
// filter air blocks
BlockType blockType = ItemTable.instance().getBlock(type);
// does this block needs random tick ?
if (blockType != null && blockType.canTickRandomly()) {
blockType.updateBlock(chunk.getBlock(x, y + (i << 4), z));
}
}
}
}
}
use of net.glowstone.block.blocktype.BlockType 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);
}
}
}
use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.
the class ItemBucket method rightClickAir.
@Override
public void rightClickAir(GlowPlayer player, ItemStack holding) {
Iterator<Block> itr = new BlockIterator(player, 5);
Block target = null;
// Used to determine the side the block was clicked on:
Block previousTarget = null;
BlockType targetBlockType = null;
boolean validTarget = false;
// Find the next available non-air liquid block type which is collectible in a radius of 5 blocks
while (itr.hasNext()) {
previousTarget = target;
target = itr.next();
targetBlockType = ItemTable.instance().getBlock(target.getType());
if (targetBlockType instanceof BlockLiquid) {
if (((BlockLiquid) targetBlockType).isCollectible((GlowBlockState) target.getState())) {
validTarget = true;
break;
}
}
}
if (target != null && validTarget) {
// Get the direction of the bucket fill
BlockFace face;
if (previousTarget != null) {
face = target.getFace(previousTarget);
} else {
face = BlockFace.SELF;
}
Material replaceWith = ((BlockLiquid) targetBlockType).getBucketType();
PlayerBucketFillEvent event = EventFactory.callEvent(new PlayerBucketFillEvent(player, target, face, holding.getType(), holding));
if (event.isCancelled()) {
return;
}
if (player.getGameMode() != GameMode.CREATIVE) {
if (holding.getAmount() == 1) {
holding.setType(replaceWith);
} else {
holding.setAmount(holding.getAmount() - 1);
player.getInventory().addItem(new ItemStack(replaceWith));
}
}
target.setType(Material.AIR);
}
}
use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.
the class GlowChunk method createEntity.
/**
* If needed, create a new block entity at the given location.
*/
public BlockEntity createEntity(int cx, int cy, int cz, int type) {
Material material = Material.getMaterial(type);
switch(material) {
case SIGN:
case SIGN_POST:
case WALL_SIGN:
case CHEST:
case TRAPPED_CHEST:
case BURNING_FURNACE:
case FURNACE:
case DISPENSER:
case DROPPER:
case END_GATEWAY:
case HOPPER:
case MOB_SPAWNER:
case NOTE_BLOCK:
case JUKEBOX:
case BREWING_STAND:
case SKULL:
case COMMAND:
case COMMAND_CHAIN:
case COMMAND_REPEATING:
case BEACON:
case BANNER:
case WALL_BANNER:
case STANDING_BANNER:
case FLOWER_POT:
case STRUCTURE_BLOCK:
case WHITE_SHULKER_BOX:
case ORANGE_SHULKER_BOX:
case MAGENTA_SHULKER_BOX:
case LIGHT_BLUE_SHULKER_BOX:
case YELLOW_SHULKER_BOX:
case LIME_SHULKER_BOX:
case PINK_SHULKER_BOX:
case GRAY_SHULKER_BOX:
case SILVER_SHULKER_BOX:
case CYAN_SHULKER_BOX:
case PURPLE_SHULKER_BOX:
case BLUE_SHULKER_BOX:
case BROWN_SHULKER_BOX:
case GREEN_SHULKER_BOX:
case RED_SHULKER_BOX:
case BLACK_SHULKER_BOX:
case ENCHANTMENT_TABLE:
case ENDER_CHEST:
case DAYLIGHT_DETECTOR:
case DAYLIGHT_DETECTOR_INVERTED:
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON:
BlockType blockType = ItemTable.instance().getBlock(type);
if (blockType == null)
return null;
try {
BlockEntity entity = blockType.createBlockEntity(this, cx, cy, cz);
if (entity == null)
return null;
blockEntities.put(coordinateToIndex(cx, cz, cy), entity);
return entity;
} catch (Exception ex) {
GlowServer.logger.log(Level.SEVERE, "Unable to initialize block entity for " + type, ex);
}
}
return null;
}
use of net.glowstone.block.blocktype.BlockType in project Glowstone by GlowstoneMC.
the class EmptyBucketDispenseBehavior method collectableLiquidAtBlock.
private BlockLiquid collectableLiquidAtBlock(GlowBlock target) {
Material material = target.getType();
if (material == null || material == Material.AIR) {
return null;
}
BlockType type = ItemTable.instance().getBlock(material);
if (!(type instanceof BlockLiquid)) {
return null;
}
BlockLiquid liquid = (BlockLiquid) type;
if (!liquid.isCollectible(target.getState())) {
return null;
}
return liquid;
}
Aggregations