Search in sources :

Example 76 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class ProjectileWatcherServiceImpl method hasChanged.

public boolean hasChanged(TrackedProjectileInfo info) {
    Location newLoc = info.getProjectile().getLocation();
    Location oldLoc = info.getLastLocation();
    return !newLoc.equals(oldLoc);
}
Also used : Location(org.spongepowered.api.world.Location)

Example 77 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class SkyWarsInstance method spawnChickens.

private void spawnChickens() {
    Vector3i bvMax = getRegion().getMaximumPoint();
    Vector3i bvMin = getRegion().getMinimumPoint();
    for (int i = 0; i < getPlayers(PARTICIPANT).size(); ++i) {
        Location<World> testLoc = new Location<>(getRegion().getExtent(), Probability.getRangedRandom(bvMin.getX(), bvMax.getX()), bvMax.getY() - 10, Probability.getRangedRandom(bvMin.getZ(), bvMax.getZ()));
        Vector2d testPos = new Vector2d(testLoc.getX(), testLoc.getZ());
        Vector2d originPos = new Vector2d(startingLocation.getX(), startingLocation.getZ());
        if (testPos.distanceSquared(originPos) >= 70 * 70) {
            --i;
            continue;
        }
        Chicken chicken = (Chicken) testLoc.getExtent().createEntity(EntityTypes.CHICKEN, testLoc.getPosition());
        chicken.offer(Keys.PERSISTS, false);
        testLoc.getExtent().spawnEntity(chicken, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
    }
}
Also used : Vector2d(com.flowpowered.math.vector.Vector2d) Vector3i(com.flowpowered.math.vector.Vector3i) Chicken(org.spongepowered.api.entity.living.animal.Chicken) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Example 78 with Location

use of org.spongepowered.api.world.Location in project HuskyCrates-Sponge by codeHusky.

the class CrateUtilities method particleRunner.

private void particleRunner() {
    if (flag)
        return;
    try {
        ArrayList<Location<World>> invalidLocations = new ArrayList<>();
        HashSet<World> invalidLocationWorlds = new HashSet<>();
        for (Location<World> b : physicalCrates.keySet()) {
            PhysicalCrate c = physicalCrates.get(b);
            if (c.vc.crateBlockType != c.location.getBlock().getType() && c.location.getExtent().isLoaded() && c.location.getExtent().getChunk(c.location.getChunkPosition()).isPresent()) {
                if (c.location.getExtent().getChunk(c.location.getChunkPosition()).get().isLoaded()) {
                    invalidLocations.add(c.location);
                    invalidLocationWorlds.add(c.location.getExtent());
                    continue;
                }
            }
            c.runParticles();
        }
        for (World w : invalidLocationWorlds) {
            for (Entity e : w.getEntities()) {
                if (invalidLocations.contains(e.getLocation()) && e.getType() != EntityTypes.ARMOR_STAND) {
                    //System.out.println("woah");
                    invalidLocations.remove(e.getLocation());
                    physicalCrates.get(e.getLocation()).runParticles();
                }
            }
        }
        for (Location<World> l : invalidLocations) {
            PhysicalCrate c = physicalCrates.get(l);
            HuskyCrates.instance.logger.warn("Removing crate that no longer exists! " + c.location.getPosition().toString());
            c.as.remove();
            physicalCrates.remove(l);
            flag = true;
        }
    } catch (Exception e) {
    }
    if (flag)
        HuskyCrates.instance.updatePhysicalCrates();
}
Also used : Entity(org.spongepowered.api.entity.Entity) World(org.spongepowered.api.world.World) IOException(java.io.IOException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Location(org.spongepowered.api.world.Location)

Example 79 with Location

use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.

the class MixinEntityWitherSkull method onExplode.

@Redirect(method = "onImpact", at = @At(value = "INVOKE", target = EXPLOSION_TARGET))
protected net.minecraft.world.Explosion onExplode(net.minecraft.world.World worldObj, Entity self, double x, double y, double z, float strength, boolean flaming, boolean smoking) {
    boolean griefer = ((IMixinGriefer) this).canGrief();
    try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(this);
        Sponge.getCauseStackManager().addContext(EventContextKeys.THROWER, getShooter());
        Sponge.getCauseStackManager().pushCause(getShooter());
        return detonate(Explosion.builder().location(new Location<>((World) worldObj, new Vector3d(x, y, z))).sourceExplosive(this).radius(this.explosionRadius).canCauseFire(flaming).shouldPlaySmoke(smoking && griefer).shouldBreakBlocks(smoking && griefer)).orElse(null);
    }
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) IMixinGriefer(org.spongepowered.common.interfaces.entity.IMixinGriefer) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Location(org.spongepowered.api.world.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 80 with Location

use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.

the class MixinNetHandlerPlayServer method processVehicleMoveEvent.

/**
 * @author gabizou - June 22nd, 2016
 * @author blood - May 6th, 2017
 * @reason Redirects the {@link Entity#getLowestRidingEntity()} call to throw our
 * {@link MoveEntityEvent}. The peculiarity of this redirect is that the entity
 * returned is perfectly valid to be {@link this#player} since, if the player
 * is NOT riding anything, the lowest riding entity is themselves. This way, if
 * the event is cancelled, the player can be returned instead of the actual riding
 * entity.
 *
 * @param playerMP The player
 * @param packetIn The packet movement
 * @return The lowest riding entity
 */
@Redirect(method = "processVehicleMove", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayerMP;getLowestRidingEntity()Lnet/minecraft/entity/Entity;"))
private Entity processVehicleMoveEvent(EntityPlayerMP playerMP, CPacketVehicleMove packetIn) {
    final Entity ridingEntity = this.player.getLowestRidingEntity();
    if (ridingEntity == this.player || ridingEntity.getControllingPassenger() != this.player || ridingEntity != this.lowestRiddenEnt) {
        return ridingEntity;
    }
    // Sponge Start - Movement event
    org.spongepowered.api.entity.Entity spongeEntity = (org.spongepowered.api.entity.Entity) ridingEntity;
    Vector3d fromrot = spongeEntity.getRotation();
    Location<World> from = spongeEntity.getLocation();
    Vector3d torot = new Vector3d(packetIn.getPitch(), packetIn.getYaw(), 0);
    Location<World> to = new Location<>(spongeEntity.getWorld(), packetIn.getX(), packetIn.getY(), packetIn.getZ());
    Transform<World> fromTransform = spongeEntity.getTransform().setLocation(from).setRotation(fromrot);
    Transform<World> toTransform = spongeEntity.getTransform().setLocation(to).setRotation(torot);
    MoveEntityEvent event = SpongeEventFactory.createMoveEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), fromTransform, toTransform, this.getPlayer());
    SpongeImpl.postEvent(event);
    if (event.isCancelled()) {
        // There is no need to change the current riding entity position as it hasn't changed yet.
        // Send packet to client in order to update rider position.
        this.netManager.sendPacket(new SPacketMoveVehicle(ridingEntity));
        return this.player;
    }
    return ridingEntity;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Entity(net.minecraft.entity.Entity) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) SPacketMoveVehicle(net.minecraft.network.play.server.SPacketMoveVehicle) World(org.spongepowered.api.world.World) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14