Search in sources :

Example 91 with BlockState

use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.

the class SpongeBlockVolumeWorker method map.

@Override
public void map(BlockVolumeMapper mapper, MutableBlockVolume destination) {
    final Vector3i offset = align(destination);
    final int xOffset = offset.getX();
    final int yOffset = offset.getY();
    final int zOffset = offset.getZ();
    final UnmodifiableBlockVolume unmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = unmodifiableVolume.getBlockMin().getX();
    final int yMin = unmodifiableVolume.getBlockMin().getY();
    final int zMin = unmodifiableVolume.getBlockMin().getZ();
    final int xMax = unmodifiableVolume.getBlockMax().getX();
    final int yMax = unmodifiableVolume.getBlockMax().getY();
    final int zMax = unmodifiableVolume.getBlockMax().getZ();
    // a single go, requiring only one event
    try (BasicPluginContext phaseState = PluginPhase.State.BLOCK_WORKER.createPhaseContext().source(this).buildAndSwitch()) {
        for (int z = zMin; z <= zMax; z++) {
            for (int y = yMin; y <= yMax; y++) {
                for (int x = xMin; x <= xMax; x++) {
                    final BlockState block = mapper.map(unmodifiableVolume, x, y, z);
                    destination.setBlock(x + xOffset, y + yOffset, z + zOffset, block);
                }
            }
        }
    }
}
Also used : BasicPluginContext(org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext) BlockState(org.spongepowered.api.block.BlockState) Vector3i(com.flowpowered.math.vector.Vector3i) UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Example 92 with BlockState

use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.

the class SpongeBlockVolumeWorker method merge.

@Override
public void merge(BlockVolume second, BlockVolumeMerger merger, MutableBlockVolume destination) {
    final Vector3i offsetSecond = align(second);
    final int xOffsetSecond = offsetSecond.getX();
    final int yOffsetSecond = offsetSecond.getY();
    final int zOffsetSecond = offsetSecond.getZ();
    final Vector3i offsetDestination = align(destination);
    final int xOffsetDestination = offsetDestination.getX();
    final int yOffsetDestination = offsetDestination.getY();
    final int zOffsetDestination = offsetDestination.getZ();
    final UnmodifiableBlockVolume firstUnmodifiableVolume = this.volume.getUnmodifiableBlockView();
    final int xMin = firstUnmodifiableVolume.getBlockMin().getX();
    final int yMin = firstUnmodifiableVolume.getBlockMin().getY();
    final int zMin = firstUnmodifiableVolume.getBlockMin().getZ();
    final int xMax = firstUnmodifiableVolume.getBlockMax().getX();
    final int yMax = firstUnmodifiableVolume.getBlockMax().getY();
    final int zMax = firstUnmodifiableVolume.getBlockMax().getZ();
    final UnmodifiableBlockVolume secondUnmodifiableVolume = second.getUnmodifiableBlockView();
    try (BasicPluginContext context = PluginPhase.State.BLOCK_WORKER.createPhaseContext().source(this).buildAndSwitch()) {
        for (int z = zMin; z <= zMax; z++) {
            for (int y = yMin; y <= yMax; y++) {
                for (int x = xMin; x <= xMax; x++) {
                    final BlockState block = merger.merge(firstUnmodifiableVolume, x, y, z, secondUnmodifiableVolume, x + xOffsetSecond, y + yOffsetSecond, z + zOffsetSecond);
                    destination.setBlock(x + xOffsetDestination, y + yOffsetDestination, z + zOffsetDestination, block);
                }
            }
        }
    }
}
Also used : BasicPluginContext(org.spongepowered.common.event.tracking.phase.plugin.BasicPluginContext) BlockState(org.spongepowered.api.block.BlockState) Vector3i(com.flowpowered.math.vector.Vector3i) UnmodifiableBlockVolume(org.spongepowered.api.world.extent.UnmodifiableBlockVolume)

Example 93 with BlockState

use of org.spongepowered.api.block.BlockState in project SpongeCommon by SpongePowered.

the class SpongeMutableBlockVolumeWorker method fill.

@Override
public void fill(BlockVolumeFiller filler) {
    final int xMin = this.volume.getBlockMin().getX();
    final int yMin = this.volume.getBlockMin().getY();
    final int zMin = this.volume.getBlockMin().getZ();
    final int xMax = this.volume.getBlockMax().getX();
    final int yMax = this.volume.getBlockMax().getY();
    final int zMax = this.volume.getBlockMax().getZ();
    for (int z = zMin; z <= zMax; z++) {
        for (int y = yMin; y <= yMax; y++) {
            for (int x = xMin; x <= xMax; x++) {
                final BlockState block = filler.produce(x, y, z);
                this.volume.setBlock(x, y, z, block);
            }
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState)

Example 94 with BlockState

use of org.spongepowered.api.block.BlockState in project RedProtect by FabioZumbi12.

the class RPGlobalListener method onBlockBreakGlobal.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) {
    RedProtect.get().logger.debug("default", "RPGlobalListener - Is BlockBreakEvent event! Cancelled? " + e.isCancelled());
    BlockSnapshot bt = e.getTransactions().get(0).getOriginal();
    BlockState b = bt.getState();
    World w = bt.getLocation().get().getExtent();
    Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get());
    if (r != null) {
        return;
    }
    if (!RPUtil.canBuildNear(p, bt.getLocation().get())) {
        e.setCancelled(true);
        return;
    }
    if (!bypassBuild(p, bt, 2)) {
        e.setCancelled(true);
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 95 with BlockState

use of org.spongepowered.api.block.BlockState 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) && !original.getCreator().isPresent()) {
            markedOrePoints.add(loc);
            if (srcEnt instanceof Player) {
                Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
                optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEnt, ScoreTypes.WILDERNESS_ORES_MINED, 1));
            }
        }
        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) HighScoreService(com.skelril.skree.service.HighScoreService) 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

BlockState (org.spongepowered.api.block.BlockState)133 World (org.spongepowered.api.world.World)39 IBlockState (net.minecraft.block.state.IBlockState)29 BlockType (org.spongepowered.api.block.BlockType)27 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)22 Direction (org.spongepowered.api.util.Direction)21 Optional (java.util.Optional)20 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)20 Vector3i (com.flowpowered.math.vector.Vector3i)19 Location (org.spongepowered.api.world.Location)18 ItemStack (org.spongepowered.api.item.inventory.ItemStack)17 LocatableBlock (org.spongepowered.api.world.LocatableBlock)14 Sponge (org.spongepowered.api.Sponge)13 ItemType (org.spongepowered.api.item.ItemType)13 ArrayList (java.util.ArrayList)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)11 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)11 Vector3d (com.flowpowered.math.vector.Vector3d)10 Listener (org.spongepowered.api.event.Listener)10