use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class EntityStorage method loadEntity.
/**
* Load a new entity in the given world from the given data tag.
*
* @param world The target world.
* @param compound The tag to load from.
* @return The newly constructed entity.
* @throws IllegalArgumentException if there is an error in the data.
*/
public static GlowEntity loadEntity(GlowWorld world, CompoundTag compound) {
// look up the store by the tag's id
if (!compound.isString("id")) {
throw new IllegalArgumentException("Entity has no type");
}
String id = compound.getString("id");
if (id.startsWith("minecraft:")) {
id = id.substring("minecraft:".length());
}
EntityStore<?> store = idTable.get(id);
if (store == null) {
throw new IllegalArgumentException("Unknown entity type to load: \"" + compound.getString("id") + "\"");
}
// verify that, if the tag contains a world, it's correct
World checkWorld = NbtSerialization.readWorld(world.getServer(), compound);
if (checkWorld != null && checkWorld != world) {
throw new IllegalArgumentException("Entity in wrong world: stored in " + world + " but data says " + checkWorld);
}
// find out the entity's location
Location location = NbtSerialization.listTagsToLocation(world, compound);
if (location == null) {
throw new IllegalArgumentException("Entity has no location");
}
// create the entity instance and read the rest of the data
return createEntity(store, location, compound);
}
use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class BlockVine method hasNearVineBlocks.
private boolean hasNearVineBlocks(GlowBlock block) {
GlowWorld world = block.getWorld();
int vineCount = 0;
for (int x = 0; x < 9; x++) {
for (int z = 0; z < 9; z++) {
for (int y = 0; y < 3; y++) {
if (world.getBlockAt(block.getLocation().add(x - 4, y - 1, z - 4)).getType() == Material.VINE) {
if (++vineCount >= 5) {
return true;
}
}
}
}
}
return false;
}
use of net.glowstone.GlowWorld 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.GlowWorld in project Glowstone by GlowstoneMC.
the class BlockSapling method searchSourceBlockForHugeTree.
private GlowBlock searchSourceBlockForHugeTree(GlowBlock block) {
GlowWorld world = block.getWorld();
int sourceX = block.getX();
int sourceY = block.getY();
int sourceZ = block.getZ();
int data = block.getData();
for (int x = -1; x <= 0; x++) {
for (int z = -1; z <= 0; z++) {
GlowBlock b = world.getBlockAt(sourceX + x, sourceY, sourceZ + z);
if (b.getType() == Material.SAPLING && b.getData() == data && b.getRelative(BlockFace.SOUTH).getType() == Material.SAPLING && b.getRelative(BlockFace.SOUTH).getData() == data && b.getRelative(BlockFace.EAST).getType() == Material.SAPLING && b.getRelative(BlockFace.EAST).getData() == data && b.getRelative(BlockFace.SOUTH_EAST).getType() == Material.SAPLING && b.getRelative(BlockFace.SOUTH_EAST).getData() == data) {
return b;
}
}
}
return null;
}
use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class BlockGrass method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
// grass block turns into dirt block
GlowBlockState state = block.getState();
state.setType(Material.DIRT);
BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
EventFactory.callEvent(fadeEvent);
if (!fadeEvent.isCancelled()) {
state.update(true);
}
} else if (blockAbove.getLightLevel() >= 9) {
GlowWorld world = block.getWorld();
int sourceX = block.getX();
int sourceY = block.getY();
int sourceZ = block.getZ();
// grass spread randomly around
for (int i = 0; i < 4; i++) {
int x = sourceX + random.nextInt(3) - 1;
int z = sourceZ + random.nextInt(3) - 1;
int y = sourceY + random.nextInt(5) - 3;
GlowBlock targetBlock = world.getBlockAt(x, y, z);
GlowBlock targetAbove = targetBlock.getRelative(BlockFace.UP);
if (targetBlock.getChunk().isLoaded() && targetAbove.getChunk().isLoaded() && targetBlock.getType() == Material.DIRT && // only spread on normal dirt
targetBlock.getData() == 0 && targetAbove.getMaterialValues().getLightOpacity() <= 2 && targetAbove.getLightLevel() >= 4) {
GlowBlockState state = targetBlock.getState();
state.setType(Material.GRASS);
state.setRawData((byte) 0);
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state);
EventFactory.callEvent(spreadEvent);
if (!spreadEvent.isCancelled()) {
state.update(true);
}
}
}
}
}
Aggregations