Search in sources :

Example 51 with BlockType

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));
                }
            }
        }
    };
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Nullable(javax.annotation.Nullable)

Example 52 with BlockType

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;
                }
            }
        }
    }
}
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 53 with BlockType

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();
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World)

Example 54 with BlockType

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);
                    }
                }
            }
        }
    }
}
Also used : 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 55 with BlockType

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));
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) ImmutableSet(com.google.common.collect.ImmutableSet) ItemTool(net.minecraft.item.ItemTool) Item(net.minecraft.item.Item) ItemPickaxe(net.minecraft.item.ItemPickaxe) Collection(java.util.Collection) Set(java.util.Set) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) BlockType(org.spongepowered.api.block.BlockType) Optional(java.util.Optional) AbstractItemStackPropertyStore(org.spongepowered.common.data.property.store.common.AbstractItemStackPropertyStore) HarvestingProperty(org.spongepowered.api.data.property.item.HarvestingProperty) Item(net.minecraft.item.Item) ItemTool(net.minecraft.item.ItemTool) ImmutableSet(com.google.common.collect.ImmutableSet) BlockType(org.spongepowered.api.block.BlockType) ItemPickaxe(net.minecraft.item.ItemPickaxe) HarvestingProperty(org.spongepowered.api.data.property.item.HarvestingProperty)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)80 World (org.spongepowered.api.world.World)34 Listener (org.spongepowered.api.event.Listener)21 BlockState (org.spongepowered.api.block.BlockState)18 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 Player (org.spongepowered.api.entity.living.player.Player)12 Optional (java.util.Optional)11 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 Keys (org.spongepowered.api.data.key.Keys)9 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Set (java.util.Set)7 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6