Search in sources :

Example 91 with Location

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);
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) WorldProvider(net.minecraft.world.WorldProvider) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) BlockPos(net.minecraft.util.math.BlockPos) Dimension(org.spongepowered.api.world.Dimension) World(org.spongepowered.api.world.World) SPacketChangeGameState(net.minecraft.network.play.server.SPacketChangeGameState) Location(org.spongepowered.api.world.Location) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 92 with Location

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);
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) Value(org.spongepowered.api.data.value.mutable.Value) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) PropertyStore(org.spongepowered.api.data.property.PropertyStore) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ImmutableList(com.google.common.collect.ImmutableList) Mixin(org.spongepowered.asm.mixin.Mixin) MergeFunction(org.spongepowered.api.data.merge.MergeFunction) Location(org.spongepowered.api.world.Location) ImmutableSet(com.google.common.collect.ImmutableSet) DirectionFacingProvider(org.spongepowered.common.registry.provider.DirectionFacingProvider) Collection(java.util.Collection) BaseValue(org.spongepowered.api.data.value.BaseValue) EnumFacing(net.minecraft.util.EnumFacing) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) DataHolder(org.spongepowered.api.data.DataHolder) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) List(java.util.List) DataView(org.spongepowered.api.data.DataView) World(org.spongepowered.api.world.World) Property(org.spongepowered.api.data.Property) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Optional(java.util.Optional) Collections(java.util.Collections) BlockState(org.spongepowered.api.block.BlockState) Value(org.spongepowered.api.data.value.mutable.Value) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) BaseValue(org.spongepowered.api.data.value.BaseValue) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult)

Example 93 with Location

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) EnumFacing(net.minecraft.util.EnumFacing) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Location(org.spongepowered.api.world.Location)

Example 94 with Location

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);
    }
}
Also used : Extent(org.spongepowered.api.world.extent.Extent) Vector3i(com.flowpowered.math.vector.Vector3i) MushroomType(org.spongepowered.api.world.gen.type.MushroomType) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Location(org.spongepowered.api.world.Location)

Example 95 with Location

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);
    }
}
Also used : Extent(org.spongepowered.api.world.extent.Extent) Vector3i(com.flowpowered.math.vector.Vector3i) MushroomType(org.spongepowered.api.world.gen.type.MushroomType) BlockPos(net.minecraft.util.math.BlockPos) Location(org.spongepowered.api.world.Location)

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