use of org.spongepowered.api.world.World in project Skree by Skelril.
the class CustomTerragu method destroyLine.
protected int destroyLine(Player player, Direction dir, int maxDist, BlockSnapshot state) {
Location<World> starting = state.getLocation().get();
int i;
for (i = 0; i < maxDist; ++i) {
starting = starting.add(dir.toVector3d());
if (starting.getBlockType() != state.getState().getType()) {
break;
}
/*if (!starting.getExtent().digBlock(starting.getBlockPosition(), Cause.of(NamedCause.simulated(player)))) {
break;
}*/
((net.minecraft.world.World) starting.getExtent()).destroyBlock(new BlockPos(starting.getX(), starting.getY(), starting.getZ()), true);
}
return i;
}
use of org.spongepowered.api.world.World 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.World 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());
}
}
}
use of org.spongepowered.api.world.World in project Skree by Skelril.
the class WildernessWorldWrapper method onItemDrop.
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> loc = optLocation.get();
if (!markedOrePoints.remove(loc)) {
return;
}
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
List<ItemStackSnapshot> itemStacks = new ArrayList<>();
event.getEntities().forEach((entity -> {
if (entity instanceof Item) {
ItemStackSnapshot snapshot = ((Item) entity).item().get();
itemStacks.add(getPoolItemDrop(snapshot));
}
}));
addPool(loc, () -> itemStacks);
}
use of org.spongepowered.api.world.World in project Skree by Skelril.
the class StormBringer method setupStormBringer.
private void setupStormBringer() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Skeleton.class));
List<Instruction<BindCondition, Boss<Skeleton, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Skeleton> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Skeleton bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Storm Bringer"));
double bossHealth = 20 * 30 * boss.getDetail().getLevel();
setMaxHealth(bossEnt, bossHealth, true);
}
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Skeleton, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
Entity eToHit = condition.getAttacked();
if (!(eToHit instanceof Living)) {
return Optional.empty();
}
Living toHit = (Living) eToHit;
Location<World> targetLocation = toHit.getLocation();
for (int i = boss.getDetail().getLevel() * Probability.getRangedRandom(1, 10); i >= 0; --i) {
Task.builder().execute(() -> {
Entity lightning = targetLocation.getExtent().createEntity(EntityTypes.LIGHTNING, targetLocation.getPosition());
targetLocation.getExtent().spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}).delayTicks(5 * (6 + i)).submit(SkreePlugin.inst());
}
return Optional.empty();
});
}
Aggregations