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