use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class MagicWand method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
boolean survival = player.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) == GameModes.SURVIVAL;
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (optHeldItem.get().getItem() != this) {
return;
}
event.setUseBlockResult(Tristate.FALSE);
Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
if (!optLoc.isPresent()) {
return;
}
Location<World> loc = optLoc.get();
BlockType targetType = loc.getBlockType();
if (targetType == CustomBlockTypes.MAGIC_LADDER) {
MagicBlockStateHelper.startLadder(loc);
} else if (targetType == CustomBlockTypes.MAGIC_PLATFORM) {
MagicBlockStateHelper.startPlatform(loc);
} else {
return;
}
if (!survival) {
MagicBlockStateHelper.resetCounts();
return;
}
MagicBlockStateHelper.dropItems(loc, event.getCause());
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class MainWorldWrapper method onBlockChange.
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (optLoc.isPresent() && isApplicable(optLoc.get())) {
boolean preventedFromBuilding = check(player, optLoc.get());
// Block players that are allowed to build, otherwise send the no build message
Text noEditMessage = Text.of(TextColors.RED, "You can't change blocks here!");
if (!preventedFromBuilding) {
if (player.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.CREATIVE) {
preventedFromBuilding = true;
noEditMessage = Text.of(TextColors.RED, "You must be in creative mode to edit!");
}
}
if (preventedFromBuilding) {
if (event.getCause().root().equals(player)) {
player.sendMessage(noEditMessage);
}
event.setCancelled(true);
return;
}
}
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class GoldRushInstance method randomizeLevers.
private void randomizeLevers() {
if (System.currentTimeMillis() - lastLeverSwitch >= TimeUnit.SECONDS.toMillis(14)) {
for (Location<World> entry : leverBlocks.keySet()) {
BlockState state = entry.getBlock();
entry.getExtent().setBlock(entry.getBlockPosition(), state.withTrait(BooleanTraits.LEVER_POWERED, false).orElse(state), Cause.source(SkreePlugin.container()).build());
leverBlocks.put(entry, !Probability.getChance(3));
}
lastLeverSwitch = System.currentTimeMillis();
randomizeLevers();
} else if (System.currentTimeMillis() - lastLeverSwitch == 0) {
for (Location<World> entry : leverBlocks.keySet()) {
Location<World> targLoc = entry.add(0, -2, 0);
targLoc.getExtent().setBlockType(targLoc.getBlockPosition(), BlockTypes.STONEBRICK, Cause.source(SkreePlugin.container()).build());
}
Task.builder().execute(() -> {
for (Map.Entry<Location<World>, Boolean> entry : leverBlocks.entrySet()) {
Location<World> targLoc = entry.getKey().add(0, -2, 0);
targLoc.getExtent().setBlockType(targLoc.getBlockPosition(), entry.getValue() ? BlockTypes.REDSTONE_BLOCK : BlockTypes.STONEBRICK, Cause.source(SkreePlugin.container()).build());
}
Task.builder().execute(this::randomizeLevers).delayTicks(15).submit(SkreePlugin.inst());
}).delayTicks(15).submit(SkreePlugin.inst());
} else {
for (Location<World> entry : leverBlocks.keySet()) {
Location<World> targLoc = entry.add(0, -2, 0);
targLoc.getExtent().setBlockType(targLoc.getBlockPosition(), BlockTypes.STONEBRICK, Cause.source(SkreePlugin.container()).build());
}
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class GoldRushInstance method findChestAndKeys.
private void findChestAndKeys() {
keyRoom.forAll((pt) -> {
BlockState block = getRegion().getExtent().getBlock(pt);
if (block.getType() == BlockTypes.CHEST) {
// TODO Sponge port
Optional<TileEntity> optTileEnt = getRegion().getExtent().getTileEntity(pt);
if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
((IInventory) optTileEnt.get()).clear();
}
chestBlocks.add(new Location<>(getRegion().getExtent(), pt));
} else if (block.getType() == BlockTypes.WALL_SIGN) {
Optional<org.spongepowered.api.block.tileentity.TileEntity> optTileEnt = getRegion().getExtent().getTileEntity(pt);
if (!optTileEnt.isPresent()) {
return;
}
locks.add(new Location<>(getRegion().getExtent(), pt));
}
});
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class ShnugglesPrimeInstance method probeArea.
public void probeArea() {
spawnPts.clear();
Vector3i min = getRegion().getMinimumPoint();
Vector3i max = getRegion().getMaximumPoint();
int minX = min.getX();
int minZ = min.getZ();
int minY = min.getY();
int maxX = max.getX();
int maxZ = max.getZ();
int maxY = max.getY();
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
for (int y = maxY; y >= minY; --y) {
BlockType type = getRegion().getExtent().getBlockType(x, y, z);
if (type == BlockTypes.GOLD_BLOCK) {
Location<World> target = new Location<>(getRegion().getExtent(), x, y + 2, z);
if (target.getBlockType() == BlockTypes.AIR) {
spawnPts.add(target);
}
}
}
}
}
}
Aggregations