Search in sources :

Example 11 with Location

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

the class HuskyCrates method gameReloaded.

@Listener
public void gameReloaded(GameReloadEvent event) {
    for (World bit : Sponge.getServer().getWorlds()) {
        for (Entity ent : bit.getEntities()) {
            if (ent instanceof ArmorStand) {
                ArmorStand arm = (ArmorStand) ent;
                if (arm.getCreator().isPresent()) {
                    if (arm.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
                        arm.remove();
                    }
                }
            }
        }
    }
    langData = new SharedLangData("", "You won %a %R&rfrom a %C&r!", "&e%p just won %a %R&r&e from a %C&r!", "You need a %K&r to open this crate.");
    CommentedConfigurationNode conf = null;
    try {
        conf = crateConfig.load();
        if (!conf.getNode("lang").isVirtual())
            langData = new SharedLangData(conf.getNode("lang"));
        else
            logger.info("Using default lang settings.");
    } catch (IOException e) {
        e.printStackTrace();
        logger.warn("Lang load failed, using defaults.");
    }
    crateUtilities.generateVirtualCrates(crateConfig);
    CommentedConfigurationNode root = null;
    try {
        root = crateConfig.load();
        for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
            Location<World> ee;
            try {
                ee = node.getNode("location").getValue(TypeToken.of(Location.class));
            } catch (InvalidDataException err2) {
                logger.warn("Bug sponge developers about world UUIDs!");
                ee = new Location<World>(Sponge.getServer().getWorld(node.getNode("location", "WorldName").getString()).get(), node.getNode("location", "X").getDouble(), node.getNode("location", "Y").getDouble(), node.getNode("location", "Z").getDouble());
            }
            if (!crateUtilities.physicalCrates.containsKey(ee))
                crateUtilities.physicalCrates.put(ee, new PhysicalCrate(ee, node.getNode("crateID").getString(), HuskyCrates.instance));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
    crateUtilities.startParticleEffects();
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) PhysicalCrate(pw.codehusky.huskycrates.crate.PhysicalCrate) IOException(java.io.IOException) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

Example 12 with Location

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

the class SkyLuminancePropertyStore method getFor.

@Override
public Optional<SkyLuminanceProperty> getFor(PropertyHolder propertyHolder) {
    if (propertyHolder instanceof Location && ((Location<?>) propertyHolder).getExtent() instanceof Chunk) {
        final Chunk chunk = (Chunk) ((Location<?>) propertyHolder).getExtent();
        final float light = chunk.getLightFor(EnumSkyBlock.SKY, VecHelper.toBlockPos((Location<?>) propertyHolder));
        return Optional.of(new SkyLuminanceProperty(light));
    }
    return super.getFor(propertyHolder);
}
Also used : SkyLuminanceProperty(org.spongepowered.api.data.property.block.SkyLuminanceProperty) Chunk(net.minecraft.world.chunk.Chunk) Location(org.spongepowered.api.world.Location)

Example 13 with Location

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

the class MixinMinecraftServer method onServerTickEnd.

@Inject(method = "tick", at = @At(value = "RETURN"))
public void onServerTickEnd(CallbackInfo ci) {
    int lastAnimTick = SpongeCommonEventFactory.lastAnimationPacketTick;
    int lastPrimaryTick = SpongeCommonEventFactory.lastPrimaryPacketTick;
    int lastSecondaryTick = SpongeCommonEventFactory.lastSecondaryPacketTick;
    if (SpongeCommonEventFactory.lastAnimationPlayer != null) {
        EntityPlayerMP player = SpongeCommonEventFactory.lastAnimationPlayer.get();
        if (player != null && lastAnimTick != lastPrimaryTick && lastAnimTick != lastSecondaryTick && lastAnimTick != 0 && lastAnimTick - lastPrimaryTick > 3 && lastAnimTick - lastSecondaryTick > 3) {
            BlockSnapshot blockSnapshot = BlockSnapshot.NONE;
            EnumFacing side = null;
            final RayTraceResult result = SpongeImplHooks.rayTraceEyes(player, SpongeImplHooks.getBlockReachDistance(player) + 1);
            // Hit non-air block
            if (result != null && result.getBlockPos() != null) {
                blockSnapshot = new Location<>((World) player.world, VecHelper.toVector3d(result.getBlockPos())).createSnapshot();
                side = result.sideHit;
            }
            Sponge.getCauseStackManager().pushCause(player);
            if (!player.getHeldItemMainhand().isEmpty()) {
                if (SpongeCommonEventFactory.callInteractItemEventPrimary(player, player.getHeldItemMainhand(), EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec), blockSnapshot).isCancelled()) {
                    SpongeCommonEventFactory.lastAnimationPacketTick = 0;
                    Sponge.getCauseStackManager().popCause();
                    return;
                }
            }
            if (side != null) {
                SpongeCommonEventFactory.callInteractBlockEventPrimary(player, blockSnapshot, EnumHand.MAIN_HAND, side, VecHelper.toVector3d(result.hitVec));
            } else {
                SpongeCommonEventFactory.callInteractBlockEventPrimary(player, EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec));
            }
            Sponge.getCauseStackManager().popCause();
        }
    }
    SpongeCommonEventFactory.lastAnimationPacketTick = 0;
    TimingsManager.FULL_SERVER_TICK.stopTiming();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Location(org.spongepowered.api.world.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 14 with Location

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

the class BlockDecayPhaseState method unwind.

@SuppressWarnings("unchecked")
@Override
public void unwind(GeneralizedContext context) {
    final LocatableBlock locatable = context.getSource(LocatableBlock.class).orElseThrow(TrackingUtil.throwWithContext("Expected to be ticking over at a location!", context));
    final Location<World> worldLocation = locatable.getLocation();
    final IMixinWorldServer mixinWorld = ((IMixinWorldServer) worldLocation.getExtent());
    try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        frame.pushCause(locatable);
        context.addNotifierAndOwnerToCauseStack();
        context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
        frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.BLOCK_SPAWNING);
        context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
            final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(frame.getCurrentCause(), items);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                for (Entity entity : event.getEntities()) {
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
        });
        context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
            final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(frame.getCurrentCause(), entities);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                for (Entity entity : event.getEntities()) {
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
        });
        context.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(drops -> {
            final List<EntityItem> items = drops.stream().map(drop -> drop.create(mixinWorld.asMinecraftWorld())).collect(Collectors.toList());
            final List<Entity> entities = (List<Entity>) (List<?>) items;
            if (!entities.isEmpty()) {
                DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(frame.getCurrentCause(), entities);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    for (Entity droppedItem : event.getEntities()) {
                        mixinWorld.forceSpawnEntity(droppedItem);
                    }
                }
            }
        });
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) SpongeImpl(org.spongepowered.common.SpongeImpl) Location(org.spongepowered.api.world.Location) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) LocatableBlock(org.spongepowered.api.world.LocatableBlock) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Sponge(org.spongepowered.api.Sponge) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) EntityUtil(org.spongepowered.common.entity.EntityUtil) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) List(java.util.List) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) GeneralizedContext(org.spongepowered.common.event.tracking.context.GeneralizedContext) World(org.spongepowered.api.world.World) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(org.spongepowered.api.world.World) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) LocatableBlock(org.spongepowered.api.world.LocatableBlock) List(java.util.List) EntityItem(net.minecraft.entity.item.EntityItem)

Example 15 with Location

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

the class BlockDropItemsPhaseState method unwind.

@SuppressWarnings("unchecked")
@Override
public void unwind(GeneralizedContext phaseContext) {
    final BlockSnapshot blockSnapshot = phaseContext.getSource(BlockSnapshot.class).orElseThrow(TrackingUtil.throwWithContext("Could not find a block dropping items!", phaseContext));
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(blockSnapshot);
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
        if (phaseContext.getNotifier().isPresent()) {
            Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, phaseContext.getNotifier().get());
        }
        if (phaseContext.getOwner().isPresent()) {
            Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, phaseContext.getOwner().get());
        }
        phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
            final ArrayList<Entity> entities = new ArrayList<>();
            for (EntityItem item : items) {
                entities.add(EntityUtil.fromNative(item));
            }
            final DropItemEvent.Destruct event = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), entities);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                for (Entity entity : event.getEntities()) {
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
        });
        phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
            final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), entities);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                for (Entity entity : event.getEntities()) {
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
            entities.clear();
        });
        final Location<World> worldLocation = blockSnapshot.getLocation().get();
        final IMixinWorldServer mixinWorld = ((IMixinWorldServer) worldLocation.getExtent());
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.BLOCK_SPAWNING);
        phaseContext.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, phaseContext));
        phaseContext.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(drops -> {
            final List<EntityItem> items = drops.stream().map(drop -> drop.create(mixinWorld.asMinecraftWorld())).collect(Collectors.toList());
            final List<Entity> entities = (List<Entity>) (List<?>) items;
            if (!entities.isEmpty()) {
                DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    for (Entity droppedItem : event.getEntities()) {
                        mixinWorld.forceSpawnEntity(droppedItem);
                    }
                }
            }
            drops.clear();
        });
        phaseContext.getBlockDropSupplier().acceptAndClearIfNotEmpty(drops -> {
            for (BlockPos key : drops.asMap().keySet()) {
                final List<ItemDropData> values = drops.get(key);
                if (!values.isEmpty()) {
                    TrackingUtil.spawnItemDataForBlockDrops(values, blockSnapshot, phaseContext, this);
                }
            }
        });
    }
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) SpongeImpl(org.spongepowered.common.SpongeImpl) Location(org.spongepowered.api.world.Location) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Sponge(org.spongepowered.api.Sponge) BlockPos(net.minecraft.util.math.BlockPos) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) InternalSpawnTypes(org.spongepowered.common.registry.type.event.InternalSpawnTypes) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) EntityUtil(org.spongepowered.common.entity.EntityUtil) ArrayList(java.util.ArrayList) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) List(java.util.List) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) GeneralizedContext(org.spongepowered.common.event.tracking.context.GeneralizedContext) World(org.spongepowered.api.world.World) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) CauseStackManager(org.spongepowered.api.event.CauseStackManager) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ArrayList(java.util.ArrayList) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(org.spongepowered.api.world.World) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ArrayList(java.util.ArrayList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) EntityItem(net.minecraft.entity.item.EntityItem)

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