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);
}
}
}
}
}
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);
}
}
}
}
}
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);
}
}
}
}
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);
}
}
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());
}
}
}
Aggregations