use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class CatacombsInstance method spawnNormalWave.
private void spawnNormalWave() {
Vector3i min = getRegion().getMinimumPoint();
Vector3i max = getRegion().getMaximumPoint();
int minX = min.getX();
int minZ = min.getZ();
int maxX = max.getX();
int maxZ = max.getZ();
final int y = min.getY() + 2;
int needed = getSpawnCount(wave);
for (int i = needed; i > 0; --i) {
int x;
int z;
BlockType type;
BlockType aboveType;
do {
x = Probability.getRangedRandom(minX, maxX);
z = Probability.getRangedRandom(minZ, maxZ);
type = getRegion().getExtent().getBlockType(x, y, z);
aboveType = getRegion().getExtent().getBlockType(x, y + 1, z);
} while (type != BlockTypes.AIR || aboveType != BlockTypes.AIR);
spawnWaveMob(new Location<>(getRegion().getExtent(), x + .5, y, z + .5));
}
}
use of org.spongepowered.api.block.BlockType in project SpongeForge by SpongePowered.
the class SpongeChunkGeneratorForge method checkForgeEvent.
private boolean checkForgeEvent(Populator populator, IChunkGenerator chunkProvider, int chunkX, int chunkZ, List<String> flags, Chunk chunk) {
boolean village_flag = flags.contains(WorldGenConstants.VILLAGE_FLAG);
if (populator instanceof Ore && populator instanceof WorldGenerator) {
BlockType type = ((Ore) populator).getOreBlock().getType();
GenerateMinable.EventType otype = null;
if (type.equals(BlockTypes.DIRT)) {
otype = GenerateMinable.EventType.DIRT;
} else if (type.equals(BlockTypes.GRAVEL)) {
otype = GenerateMinable.EventType.GRAVEL;
} else if (type.equals(BlockTypes.STONE)) {
BlockState state = ((Ore) populator).getOreBlock();
Optional<StoneType> stype;
if ((stype = state.get(Keys.STONE_TYPE)).isPresent()) {
StoneType stoneType = stype.get();
if (stoneType.equals(StoneTypes.DIORITE)) {
otype = GenerateMinable.EventType.DIORITE;
} else if (stoneType.equals(StoneTypes.ANDESITE)) {
otype = GenerateMinable.EventType.ANDESITE;
} else if (stoneType.equals(StoneTypes.GRANITE)) {
otype = GenerateMinable.EventType.GRANITE;
} else {
return true;
}
}
} else if (type.equals(BlockTypes.COAL_ORE)) {
otype = GenerateMinable.EventType.COAL;
} else if (type.equals(BlockTypes.IRON_ORE)) {
otype = GenerateMinable.EventType.IRON;
} else if (type.equals(BlockTypes.GOLD_ORE)) {
otype = GenerateMinable.EventType.GOLD;
} else if (type.equals(BlockTypes.REDSTONE_ORE)) {
otype = GenerateMinable.EventType.REDSTONE;
} else if (type.equals(BlockTypes.DIAMOND_ORE)) {
otype = GenerateMinable.EventType.DIAMOND;
} else if (type.equals(BlockTypes.LAPIS_ORE)) {
otype = GenerateMinable.EventType.LAPIS;
} else if (type.equals(BlockTypes.QUARTZ_ORE)) {
otype = GenerateMinable.EventType.QUARTZ;
} else if (type.equals(BlockTypes.EMERALD_ORE)) {
otype = GenerateMinable.EventType.EMERALD;
} else if (type.equals(BlockTypes.MONSTER_EGG)) {
otype = GenerateMinable.EventType.SILVERFISH;
}
return otype == null || TerrainGen.generateOre((World) chunk.getWorld(), this.rand, (WorldGenerator) populator, VecHelper.toBlockPos(chunk.getBlockMin()), otype);
}
Populate.EventType etype = this.getForgeEventTypeForPopulator(populator, chunk);
boolean populate = TerrainGen.populate(chunkProvider, (net.minecraft.world.World) chunk.getWorld(), this.rand, chunkX, chunkZ, village_flag, etype);
Decorate.EventType detype = this.getForgeDecorateEventTypeForPopulator(populator, chunk);
boolean decorate = TerrainGen.decorate((World) chunk.getWorld(), this.rand, VecHelper.toBlockPos(chunk.getBlockMin()), detype);
// TODO May need to separate this..
return populate && decorate;
}
use of org.spongepowered.api.block.BlockType in project guardian by ichorpowered.
the class RayUtil method getFirstBlock.
private static Optional<BlockRayHit> getFirstBlock(final Extent extent, final Vector3d from, final Vector3d direction, final Predicate<BlockType> skipFilter, final int distanceLimit) {
final BlockRay<Extent> blockRay = BlockRay.from(extent, from).direction(direction).distanceLimit(distanceLimit).build();
Optional<BlockRayHit> blockRayHit = Optional.empty();
while (blockRay.hasNext()) {
final BlockRayHit nextBlockRayHit = blockRay.next();
final BlockType blockType = extent.getBlockType(nextBlockRayHit.getBlockPosition());
if (!skipFilter.test(blockType)) {
blockRayHit = Optional.of(nextBlockRayHit);
break;
}
}
return blockRayHit;
}
use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class MarketSignListener method onClick.
@Listener
public void onClick(InteractBlockEvent event, @First Player player) {
if (!event.getTargetBlock().getLocation().isPresent()) {
return;
}
Location<World> loc = event.getTargetBlock().getLocation().get();
BlockType blockType = loc.getBlockType();
if (!Arrays.asList(STANDING_SIGN, WALL_SIGN).contains(blockType)) {
// Not even a sign -> ignore
return;
}
boolean editMode = module.getEditModeCommand().hasUser(player);
Boolean sneaking = player.get(Keys.IS_SNEAKING).get();
boolean punch = event instanceof Primary;
Optional<MarketSignData> mSignData = event.getTargetBlock().get(ImmutableMarketSignData.class).map(ImmutableMarketSignData::asMutable);
if (mSignData.isPresent()) {
manager.updateSignText(mSignData.get(), loc);
}
if (editMode) {
if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
i18n.send(player, NEGATIVE, "You are not allowed to edit MarketSigns here");
manager.exitEditMode(player);
module.getEditModeCommand().removeUser(player);
return;
}
if (// Its the active MarketSign -> Break or Modify Item
manager.isActive(loc, player)) {
if (// Do nothing if sneaking
sneaking) {
return;
}
if (punch) {
if (manager.tryBreakActive(player)) {
return;
} else {
// TODO resend signtext?
event.setCancelled(true);
}
}
if (!punch && player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
manager.modifyItemActive(player, player.getItemInHand(HandTypes.MAIN_HAND).get());
}
event.setCancelled(true);
return;
}
if (// Its another MarketSign
mSignData.isPresent()) {
// Set Current Sign
manager.setSign(loc, player);
event.setCancelled(true);
return;
}
// Its a sign ; but no data yet
if (// Sneak Interact -> Allow Interaction
sneaking && !punch) {
return;
}
if (// Sneak AND Punch to convert sign
sneaking && punch) {
// sneak + punch -> convert it!
MarketSignData data = new MarketSignData();
data.setID(UUID.randomUUID());
data.setOwner(player.getUniqueId());
// Sign converted! Now set active
loc.offer(data);
manager.setSign(loc, player);
event.setCancelled(true);
return;
}
i18n.send(player, NEGATIVE, "That is not a market sign!");
i18n.send(player, NEUTRAL, "Sneak and punch the sign convert it.");
event.setCancelled(true);
return;
}
if (!mSignData.isPresent()) {
return;
}
MarketSignData data = mSignData.get();
manager.executeSignAction(data, loc, player, event instanceof InteractBlockEvent.Secondary);
if (blockType != AIR) {
// TODO sign somehow is retained /w some invalid data
loc.offer(data);
manager.updateSignText(data, loc);
// event.setCancelled(true);
}
}
use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class Writer method editSignInSight.
/**
* Edits the sign the user is looking at
*
* @param user the user
* @param line1 the 1st line
* @param line2 the 2nd line
* @param line3 the 3rd line
* @param line4 the 4th line
*
* @return false if there is no sign to edit in sight
*/
public boolean editSignInSight(Player user, String line1, String line2, String line3, String line4) {
Iterator<BlockRayHit<World>> it = BlockRay.from(user).distanceLimit(10).iterator();
BlockRayHit<World> result = null;
while (it.hasNext()) {
BlockRayHit<World> next = it.next();
BlockType type = next.getLocation().getBlockType();
if (type == WALL_SIGN || type == STANDING_SIGN) {
result = next;
break;
}
}
if (result == null) {
return false;
}
Location<World> block = result.getLocation();
BlockType type = block.getBlockType();
if (type != WALL_SIGN && type != STANDING_SIGN) {
return false;
}
SignData signData = block.get(SignData.class).get();
ListValue<Text> lines = signData.lines();
lines.set(0, line1 == null ? lines.get(0) : Text.of(line1));
lines.set(1, line2 == null ? lines.get(1) : Text.of(line2));
lines.set(2, line3 == null ? lines.get(2) : Text.of(line3));
lines.set(3, line4 == null ? lines.get(3) : Text.of(line4));
System.out.println(block.offer(signData).isSuccessful());
i18n.send(user, POSITIVE, "The sign has been changed!");
return true;
}
Aggregations