use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class EntityUtil method getPlayerRespawnLocation.
// Internal to MixinPlayerList. has side effects
public static Location<World> getPlayerRespawnLocation(EntityPlayerMP playerIn, @Nullable WorldServer targetWorld) {
final Location<World> location = ((World) playerIn.world).getSpawnLocation();
tempIsBedSpawn = false;
if (targetWorld == null) {
// Target world doesn't exist? Use global
return location;
}
final Dimension targetDimension = (Dimension) targetWorld.provider;
int targetDimensionId = ((IMixinWorldServer) targetWorld).getDimensionId();
// that world. (Usually overworld unless a mod says otherwise).
if (!targetDimension.allowsPlayerRespawns()) {
targetDimensionId = SpongeImplHooks.getRespawnDimension((WorldProvider) targetDimension, playerIn);
targetWorld = targetWorld.getMinecraftServer().getWorld(targetDimensionId);
}
Vector3d targetSpawnVec = VecHelper.toVector3d(targetWorld.getSpawnPoint());
BlockPos bedPos = SpongeImplHooks.getBedLocation(playerIn, targetDimensionId);
if (bedPos != null) {
// Player has a bed
boolean forceBedSpawn = SpongeImplHooks.isSpawnForced(playerIn, targetDimensionId);
BlockPos bedSpawnLoc = EntityPlayer.getBedSpawnLocation(targetWorld, bedPos, forceBedSpawn);
if (bedSpawnLoc != null) {
// The bed exists and is not obstructed
tempIsBedSpawn = true;
targetSpawnVec = new Vector3d(bedSpawnLoc.getX() + 0.5D, bedSpawnLoc.getY() + 0.1D, bedSpawnLoc.getZ() + 0.5D);
} else {
// Bed invalid
playerIn.connection.sendPacket(new SPacketChangeGameState(0, 0.0F));
// Vanilla behaviour - Delete the known bed location if invalid
// null = remove location
bedPos = null;
}
// Set the new bed location for the new dimension
// Temporarily for setSpawnPoint
int prevDim = playerIn.dimension;
playerIn.dimension = targetDimensionId;
playerIn.setSpawnPoint(bedPos, forceBedSpawn);
playerIn.dimension = prevDim;
}
return new Location<>((World) targetWorld, targetSpawnVec);
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method offer.
@Override
public <E> DataTransactionResult offer(int x, int y, int z, Key<? extends BaseValue<E>> key, E value) {
final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
if (blockState.supports(key)) {
ImmutableValue<E> old = ((Value<E>) getValue(x, y, z, (Key) key).get()).asImmutable();
setBlock(x, y, z, blockState.with(key, value).get());
ImmutableValue<E> newVal = ((Value<E>) getValue(x, y, z, (Key) key).get()).asImmutable();
return DataTransactionResult.successReplaceResult(newVal, old);
}
return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(key, value)).orElseGet(DataTransactionResult::failNoData);
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinWorld_Data method getFacesWithProperty.
@Override
public Collection<Direction> getFacesWithProperty(int x, int y, int z, Class<? extends Property<?, ?>> propertyClass) {
final Optional<? extends PropertyStore<? extends Property<?, ?>>> optional = Sponge.getPropertyRegistry().getStore(propertyClass);
if (!optional.isPresent()) {
return Collections.emptyList();
}
final PropertyStore<? extends Property<?, ?>> store = optional.get();
final Location<World> loc = new Location<>(this, x, y, z);
ImmutableList.Builder<Direction> faces = ImmutableList.builder();
for (EnumFacing facing : EnumFacing.values()) {
Direction direction = DirectionFacingProvider.getInstance().getKey(facing).get();
if (store.getFor(loc, direction).isPresent()) {
faces.add(direction);
}
}
return faces.build();
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class MixinWorldGenBush method populate.
@Override
public void populate(org.spongepowered.api.world.World worldIn, Extent extent, Random random) {
Vector3i min = extent.getBlockMin();
Vector3i size = extent.getBlockSize();
World world = (World) worldIn;
BlockPos chunkPos = new BlockPos(min.getX(), min.getY(), min.getZ());
int x, y, z;
int n = this.mushroomsPerChunk.getFlooredAmount(random);
MushroomType type = MushroomTypes.BROWN;
List<MushroomType> result;
for (int i = 0; i < n; ++i) {
x = random.nextInt(size.getX());
z = random.nextInt(size.getZ());
y = nextInt(random, world.getHeight(chunkPos.add(x, 0, z)).getY() * 2);
BlockPos height = chunkPos.add(x, y, z);
if (this.override != null) {
Location<Extent> pos2 = new Location<>(extent, VecHelper.toVector3i(height));
type = this.override.apply(pos2);
} else {
result = this.types.get(random);
if (result.isEmpty()) {
continue;
}
type = result.get(0);
}
if (type == MushroomTypes.BROWN) {
this.block = Blocks.BROWN_MUSHROOM;
} else {
this.block = Blocks.RED_MUSHROOM;
}
generate(world, random, height);
}
}
use of org.spongepowered.api.world.Location in project SpongeCommon by SpongePowered.
the class HellMushroomPopulator method populate.
@Override
public void populate(org.spongepowered.api.world.World world, Extent extent, Random random) {
Vector3i min = extent.getBlockMin();
Vector3i size = extent.getBlockSize();
BlockPos chunkPos = new BlockPos(min.getX(), min.getY(), min.getZ());
int x;
int y;
int z;
int n = this.featureM.getMushroomsPerChunk().getFlooredAmount(random);
MushroomType type;
List<MushroomType> result;
for (int i = 0; i < n; ++i) {
x = random.nextInt(size.getX());
z = random.nextInt(size.getZ());
y = random.nextInt(128);
BlockPos height = chunkPos.add(x, y, z);
if (this.featureM.getSupplierOverride().isPresent()) {
Location<Extent> pos2 = new Location<>(extent, VecHelper.toVector3i(height));
type = this.featureM.getSupplierOverride().get().apply(pos2);
} else {
result = this.featureM.getTypes().get(random);
if (result.isEmpty()) {
continue;
}
type = result.get(0);
}
if (type == MushroomTypes.BROWN) {
this.feature.block = Blocks.BROWN_MUSHROOM;
} else {
this.feature.block = Blocks.RED_MUSHROOM;
}
this.feature.generate((World) world, random, height);
}
}
Aggregations