Search in sources :

Example 1 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class RegionManager method cleanup.

public int cleanup() {
    Optional<World> optWorld = Sponge.getServer().getWorld(worldName);
    int total = 0;
    if (optWorld.isPresent()) {
        World world = optWorld.get();
        for (CachedRegion region : regionList) {
            List<RegionPoint> toRemove = new ArrayList<>();
            for (RegionPoint point : region.getFullPoints()) {
                BlockType type = world.getBlockType(point.toInt());
                if (type != CustomBlockTypes.REGION_MASTER && type != CustomBlockTypes.REGION_MARKER) {
                    ++total;
                    toRemove.add(point);
                }
            }
            region.remPoint(toRemove);
        }
    }
    return total;
}
Also used : BlockType(org.spongepowered.api.block.BlockType) World(org.spongepowered.api.world.World)

Example 2 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class JungleRaidEffectListener method onBlockBurn.

@Listener
public void onBlockBurn(ChangeBlockEvent event) {
    if (event.getCause().root() instanceof Player) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType finalType = transaction.getFinal().getState().getType();
        if (finalType != BlockTypes.FIRE) {
            continue;
        }
        Optional<JungleRaidInstance> optInst = manager.getApplicableZone(transaction.getOriginal().getLocation().get());
        if (optInst.isPresent()) {
            JungleRaidInstance inst = optInst.get();
            if (inst.isFlagEnabled(JungleRaidFlag.NO_FIRE_SPREAD)) {
                event.setCancelled(true);
            }
            break;
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Example 3 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class GoldRushInstance method findLeversAndFloodBlocks.

private void findLeversAndFloodBlocks() {
    Vector3i min = flashMemoryRoom.getMinimumPoint();
    Vector3i max = flashMemoryRoom.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) {
                BlockState state = getRegion().getExtent().getBlock(x, y, z);
                if (state.getType() == BlockTypes.LEVER) {
                    Location<World> loc = new Location<>(getRegion().getExtent(), x, y, z);
                    loc.getExtent().setBlock(loc.getBlockPosition(), state.withTrait(BooleanTraits.LEVER_POWERED, false).orElse(state), Cause.source(SkreePlugin.container()).build());
                    leverBlocks.put(loc, !Probability.getChance(3));
                    for (int i = y; i < maxY; i++) {
                        BlockType type = getRegion().getExtent().getBlockType(x, i, z);
                        if (type == BlockTypes.AIR) {
                            floodBlocks.add(new Location<>(getRegion().getExtent(), x, i, z));
                            break;
                        }
                    }
                    // One lever a column only
                    break;
                }
            }
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Example 4 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class CursedMineInstance method changeWater.

private void changeWater() {
    BlockType targetType = BlockTypes.AIR;
    if (lastActivation == 0 || System.currentTimeMillis() - lastActivation >= timeTilPumpShutoff) {
        targetType = BlockTypes.PLANKS;
    }
    final BlockType finalTarget = targetType;
    floodGate.forAll((pt) -> {
        if (replaceableTypes.contains(getRegion().getExtent().getBlockType(pt))) {
            getRegion().getExtent().setBlockType(pt, finalTarget, Cause.source(SkreePlugin.container()).build());
        }
    });
}
Also used : BlockType(org.spongepowered.api.block.BlockType)

Example 5 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class CursedMineListener method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockType originalType = transaction.getFinal().getState().getType();
        BlockType finalType = transaction.getFinal().getState().getType();
        if (isRedstoneTransition(originalType, finalType)) {
            continue;
        }
        event.setCancelled(true);
        break;
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)91 World (org.spongepowered.api.world.World)34 BlockState (org.spongepowered.api.block.BlockState)23 Listener (org.spongepowered.api.event.Listener)21 Location (org.spongepowered.api.world.Location)17 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)16 ItemStack (org.spongepowered.api.item.inventory.ItemStack)14 Vector3i (com.flowpowered.math.vector.Vector3i)12 Optional (java.util.Optional)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)10 Set (java.util.Set)10 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 ArrayList (java.util.ArrayList)9 Keys (org.spongepowered.api.data.key.Keys)9 Sponge (org.spongepowered.api.Sponge)8 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6