use of com.flowpowered.math.vector.Vector3d in project Skree by Skelril.
the class RegionMaster method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
return;
}
RegionService service = optService.get();
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
if (!block.isValid()) {
continue;
}
if (block.getFinal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getFinal().getLocation();
if (optLoc.isPresent()) {
Optional<Region> optOriginRef = service.getSelectedRegion(player);
Optional<Region> optRef = service.getOrCreate(optLoc.get(), player);
if (optRef.isPresent()) {
Region ref = optRef.get();
Vector3d masterBlock = ref.getMasterBlock();
Vector3d blockPos = optLoc.get().getPosition();
// Determine if this is a new region or not
if (!masterBlock.equals(blockPos)) {
if (blockPos.equals(recentlyClicked.get(player))) {
// Update the master block
ref.setMasterBlock(new RegionPoint(blockPos));
// Delete the existing master block
optLoc.get().getExtent().setBlockType(masterBlock.toInt(), BlockTypes.AIR, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
player.sendMessage(Text.of(TextColors.YELLOW, "Master block moved."));
} else {
recentlyClicked.put(player, blockPos);
block.setValid(false);
player.sendMessage(Text.of(TextColors.YELLOW, "Place the master block again to move this region's master block."));
}
}
service.setSelectedRegion(player, ref);
if (!ref.equals(optOriginRef.orElse(null))) {
player.sendMessage(Text.of(TextColors.YELLOW, "Active region set!"));
}
}
}
}
}
use of com.flowpowered.math.vector.Vector3d 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 com.flowpowered.math.vector.Vector3d in project Skree by Skelril.
the class BringCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Vector3d dest;
Vector3d rotation;
World targetExtent;
if (src instanceof Player) {
Player srcPlayer = (Player) src;
Location<World> loc = srcPlayer.getLocation();
dest = loc.getPosition();
rotation = srcPlayer.getRotation();
targetExtent = loc.getExtent();
} else {
src.sendMessage(Text.of(TextColors.RED, "You are not a player and teleporting other players is not currently supported!"));
return CommandResult.empty();
}
Player target = args.<Player>getOne("target").get();
Optional<Location<World>> optSafeDest = SafeTeleportHelper.getSafeDest(target, new Location<>(targetExtent, dest));
if (optSafeDest.isPresent()) {
if (!WorldEntryPermissionCheck.checkDestination((Player) src, optSafeDest.get().getExtent())) {
src.sendMessage(Text.of(TextColors.RED, "You do not have permission to teleport players to worlds of this type."));
return CommandResult.empty();
}
target.setLocationAndRotation(optSafeDest.get(), rotation);
src.sendMessage(Text.of(TextColors.YELLOW, "Player brought to you, my lord."));
} else {
src.sendMessage(Text.of(TextColors.RED, "The player could not be safely teleported here."));
}
return CommandResult.success();
}
use of com.flowpowered.math.vector.Vector3d in project Skree by Skelril.
the class JungleRaidEffectListener method createFor.
private PlayerCombatParser createFor(Cancellable event, JungleRaidInstance inst) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
final boolean isDamageEntityEvent = event instanceof DamageEntityEvent;
// Do Death Touch before anything else
if (inst.isFlagEnabled(JungleRaidFlag.DEATH_TOUCH) && isDamageEntityEvent) {
((DamageEntityEvent) event).setBaseDamage(Math.pow(defender.get(Keys.MAX_HEALTH).orElse(20D), 3));
return;
}
Optional<JungleRaidClass> optClass = inst.getClass(attacker);
if (optClass.isPresent()) {
JungleRaidClass jrClass = optClass.get();
if (jrClass == JungleRaidClass.SNIPER) {
Optional<ItemStack> optHeld = attacker.getItemInHand(HandTypes.MAIN_HAND);
boolean hasWoodenSword = optHeld.isPresent() && optHeld.get().getItem() == ItemTypes.WOODEN_SWORD;
if (indirectSource != null || !hasWoodenSword) {
double distSq = attacker.getLocation().getPosition().distanceSquared(defender.getLocation().getPosition());
double targetDistSq = Math.pow(70, 2);
double ratio = Math.min(distSq, targetDistSq) / targetDistSq;
if (isDamageEntityEvent) {
// Handle damage modification
((DamageEntityEvent) event).setBaseDamage(((DamageEntityEvent) event).getBaseDamage() * ratio);
} else {
// Disable the arrow fire in the Impact event
if (ratio < .7 && indirectSource != null) {
indirectSource.offer(Keys.FIRE_TICKS, 0);
}
}
}
}
}
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && attacker.getUniqueId().equals(inst.getFlagData().titan) && isDamageEntityEvent) {
((DamageEntityEvent) event).setBaseDamage(((DamageEntityEvent) event).getBaseDamage() * 2);
}
}
@Override
public void processNonLivingAttack(DamageSource attacker, Player defender) {
if (!(event instanceof DamageEntityEvent)) {
return;
}
if (attacker.getType() == DamageTypes.FALL) {
BlockType belowType = defender.getLocation().add(0, -1, 0).getBlockType();
if (inst.isFlagEnabled(JungleRaidFlag.TRAMPOLINE)) {
Vector3d oldVel = defender.getVelocity();
Vector3d newVel = new Vector3d(oldVel.getX(), 0, oldVel.getZ());
defender.setVelocity(new Vector3d(0, .1, 0).mul(((DamageEntityEvent) event).getBaseDamage()).add(newVel));
event.setCancelled(true);
} else if (belowType == BlockTypes.LEAVES || belowType == BlockTypes.LEAVES2) {
if (Probability.getChance(2)) {
Vector3d oldVel = defender.getVelocity();
Vector3d newVel = new Vector3d(oldVel.getX() > 0 ? -.5 : .5, 0, oldVel.getZ() > 0 ? -.5 : .5);
defender.setVelocity(new Vector3d(0, .1, 0).mul(((DamageEntityEvent) event).getBaseDamage()).add(newVel));
}
event.setCancelled(true);
}
} else if (attacker.getType() == DamageTypes.CUSTOM) {
if (inst.isFlagEnabled(JungleRaidFlag.EXPLOSIVE_ARROWS) || inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
((DamageEntityEvent) event).setBaseDamage(Math.min(((DamageEntityEvent) event).getBaseDamage(), 2));
}
}
}
};
}
use of com.flowpowered.math.vector.Vector3d in project Skree by Skelril.
the class JungleRaidEffectProcessor method distributor.
private static void distributor(JungleRaidInstance inst) {
FlagEffectData data = inst.getFlagData();
boolean isSuddenDeath = inst.isSuddenDeath();
if (isSuddenDeath) {
data.amt = 100;
}
if (inst.isFlagEnabled(JungleRaidFlag.END_OF_DAYS) || inst.isFlagEnabled(JungleRaidFlag.GRENADES) || inst.isFlagEnabled(JungleRaidFlag.POTION_PLUMMET) || isSuddenDeath) {
Vector3i bvMax = inst.getRegion().getMaximumPoint();
Vector3i bvMin = inst.getRegion().getMinimumPoint();
for (int i = 0; i < Probability.getRangedRandom(data.amt / 3, data.amt); i++) {
Location<World> testLoc = new Location<>(inst.getRegion().getExtent(), Probability.getRangedRandom(bvMin.getX(), bvMax.getX()), bvMax.getY(), Probability.getRangedRandom(bvMin.getZ(), bvMax.getZ()));
if (testLoc.getBlockType() != BlockTypes.AIR)
continue;
if (inst.isFlagEnabled(JungleRaidFlag.END_OF_DAYS) || isSuddenDeath) {
PrimedTNT explosive = (PrimedTNT) inst.getRegion().getExtent().createEntity(EntityTypes.PRIMED_TNT, testLoc.getPosition());
explosive.setVelocity(new Vector3d(random.nextDouble() * 2.0 - 1, random.nextDouble() * 2 * -1, random.nextDouble() * 2.0 - 1));
explosive.offer(Keys.FUSE_DURATION, 20 * 4);
// TODO used to have a 1/4 chance of creating fire
inst.getRegion().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
if (inst.isFlagEnabled(JungleRaidFlag.POTION_PLUMMET)) {
PotionEffectType type = Probability.pickOneOf(Sponge.getRegistry().getAllOf(PotionEffectType.class));
for (int ii = Probability.getRandom(5); ii > 0; --ii) {
ThrownPotion potion = (ThrownPotion) inst.getRegion().getExtent().createEntity(EntityTypes.SPLASH_POTION, testLoc.getPosition());
potion.setVelocity(new Vector3d(random.nextDouble() * 2.0 - 1, 0, random.nextDouble() * 2.0 - 1));
potion.offer(Keys.POTION_EFFECTS, Lists.newArrayList(PotionEffect.of(type, 1, type.isInstant() ? 1 : 20 * 10)));
inst.getRegion().getExtent().spawnEntity(potion, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
}
if (inst.isFlagEnabled(JungleRaidFlag.GRENADES)) {
new ItemDropper(testLoc).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.SNOWBALL, Probability.getRandom(3))), SpawnTypes.PLUGIN);
}
}
if (data.amt < 150 && Probability.getChance(inst.isFlagEnabled(JungleRaidFlag.SUPER) ? 9 : 25))
++data.amt;
}
}
Aggregations