use of org.spongepowered.api.block.BlockType 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 org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class GoldRushListener method onBlockChange.
@Listener
public void onBlockChange(ChangeBlockEvent event) {
Optional<Player> player = event.getCause().get(NamedCause.SOURCE, Player.class);
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
if (manager.getApplicableZone(transaction.getOriginal().getLocation().get()).isPresent()) {
BlockType originalType = transaction.getOriginal().getState().getType();
BlockType finalType = transaction.getFinal().getState().getType();
if (player.isPresent()) {
if (!isAllowedChange(originalType, finalType)) {
event.setCancelled(true);
break;
}
} else {
if (originalType == BlockTypes.LEVER && finalType != BlockTypes.LEVER) {
event.setCancelled(true);
break;
}
}
}
}
}
use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class GoldRushInstance method flood.
private void flood() {
if (getTimeSinceStart() >= getTimeTilFlood()) {
for (Location<World> floodBlock : floodBlocks) {
floodBlock.getExtent().setBlockType(floodBlock.getBlockPosition(), floodBlockType, Cause.source(SkreePlugin.container()).build());
}
if (System.currentTimeMillis() - lastFlood >= TimeUnit.SECONDS.toMillis(30 / getPlayerMod())) {
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 = minY; y <= maxY; y++) {
BlockType type = getRegion().getExtent().getBlockType(x, y, z);
if (type == BlockTypes.AIR) {
getRegion().getExtent().setBlockType(x, y, z, floodBlockType, Cause.source(SkreePlugin.container()).build());
break;
}
}
}
}
lastFlood = System.currentTimeMillis();
}
}
}
use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class ShnugglesPrimeInstance method probeArea.
public void probeArea() {
spawnPts.clear();
Vector3i min = getRegion().getMinimumPoint();
Vector3i max = getRegion().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) {
BlockType type = getRegion().getExtent().getBlockType(x, y, z);
if (type == BlockTypes.GOLD_BLOCK) {
Location<World> target = new Location<>(getRegion().getExtent(), x, y + 2, z);
if (target.getBlockType() == BlockTypes.AIR) {
spawnPts.add(target);
}
}
}
}
}
}
use of org.spongepowered.api.block.BlockType in project SpongeCommon by SpongePowered.
the class HarvestingPropertyStore method getFor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Optional<HarvestingProperty> getFor(ItemStack itemStack) {
final Item item = itemStack.getItem();
if (item instanceof ItemTool && !(item instanceof ItemPickaxe)) {
final ImmutableSet<BlockType> blocks = ImmutableSet.copyOf((Set) ((ItemTool) item).effectiveBlocks);
return Optional.of(new HarvestingProperty(blocks));
}
final Collection<BlockType> blockTypes = SpongeImpl.getRegistry().getAllOf(BlockType.class);
final ImmutableSet.Builder<BlockType> builder = ImmutableSet.builder();
blockTypes.stream().filter(blockType -> item.canHarvestBlock((IBlockState) blockType.getDefaultState())).forEach(builder::add);
final ImmutableSet<BlockType> blocks = builder.build();
if (blocks.isEmpty()) {
return Optional.empty();
}
return Optional.of(new HarvestingProperty(blocks));
}
Aggregations