Search in sources :

Example 1 with Extent

use of org.spongepowered.api.world.extent.Extent in project Skree by Skelril.

the class WildernessWorldWrapper method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> block : transactions) {
        BlockSnapshot original = block.getOriginal();
        Optional<Location<World>> optLoc = original.getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Integer> optLevel = getLevel(optLoc.get());
        if (!optLevel.isPresent()) {
            continue;
        }
        int level = optLevel.get();
        Location<World> loc = optLoc.get();
        BlockState state = original.getState();
        BlockType type = state.getType();
        // Prevent item dupe glitch by removing the position before subsequent breaks
        markedOrePoints.remove(loc);
        if (config.getDropAmplificationConfig().amplifies(state)) {
            markedOrePoints.add(loc);
        }
        if (srcEnt instanceof Player && type.equals(BlockTypes.STONE) && Probability.getChance(Math.max(12, 250 - level))) {
            Vector3d max = loc.getPosition().add(1, 1, 1);
            Vector3d min = loc.getPosition().sub(1, 1, 1);
            Extent world = loc.getExtent();
            if (Probability.getChance(3)) {
                Entity entity = world.createEntity(EntityTypes.SILVERFISH, loc.getPosition().add(.5, 0, .5));
                world.spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
            }
            // Do this one tick later to guarantee no collision with transaction data
            Task.builder().delayTicks(1).execute(() -> {
                for (int x = min.getFloorX(); x <= max.getFloorX(); ++x) {
                    for (int z = min.getFloorZ(); z <= max.getFloorZ(); ++z) {
                        for (int y = min.getFloorY(); y <= max.getFloorY(); ++y) {
                            if (!world.containsBlock(x, y, z)) {
                                continue;
                            }
                            if (world.getBlockType(x, y, z) == BlockTypes.STONE) {
                                world.setBlockType(x, y, z, BlockTypes.MONSTER_EGG, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
                            }
                        }
                    }
                }
            }).submit(SkreePlugin.inst());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Extent(org.spongepowered.api.world.extent.Extent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

Vector3d (com.flowpowered.math.vector.Vector3d)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 BlockState (org.spongepowered.api.block.BlockState)1 BlockType (org.spongepowered.api.block.BlockType)1 Transaction (org.spongepowered.api.data.Transaction)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1 Extent (org.spongepowered.api.world.extent.Extent)1