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();
}
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);
}
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();
}
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);
}
}
}
});
}
}
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);
}
}
});
}
}
Aggregations