Search in sources :

Example 16 with Location

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

the class MixinWorld_Data method offer.

@Override
public DataTransactionResult offer(int x, int y, int z, DataManipulator<?, ?> manipulator, MergeFunction function) {
    final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
    final ImmutableDataManipulator<?, ?> immutableDataManipulator = manipulator.asImmutable();
    if (blockState.supports((Class) immutableDataManipulator.getClass())) {
        final List<ImmutableValue<?>> old = new ArrayList<>(blockState.getValues());
        final BlockState newState = blockState.with(immutableDataManipulator).get();
        old.removeAll(newState.getValues());
        setBlock(x, y, z, newState);
        return DataTransactionResult.successReplaceResult(old, manipulator.getValues());
    }
    return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(manipulator, function)).orElseGet(() -> DataTransactionResult.failResult(manipulator.getValues()));
}
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) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) BlockState(org.spongepowered.api.block.BlockState) ArrayList(java.util.ArrayList)

Example 17 with Location

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

the class MixinWorldGenBigMushroom 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;
    int z;
    int n = this.mushroomsPerChunk.getFlooredAmount(random);
    PopulatorObject type = MushroomTypes.BROWN.getPopulatorObject();
    List<PopulatorObject> result;
    for (int i = 0; i < n; ++i) {
        x = random.nextInt(size.getX());
        z = random.nextInt(size.getZ());
        BlockPos pos = world.getHeight(chunkPos.add(x, 0, z));
        if (this.override != null) {
            Location<Extent> pos2 = new Location<>(extent, VecHelper.toVector3i(pos));
            type = this.override.apply(pos2);
        } else {
            result = this.types.get(random);
            if (result.isEmpty()) {
                continue;
            }
            type = result.get(0);
        }
        if (type.canPlaceAt((org.spongepowered.api.world.World) world, pos.getX(), pos.getY(), pos.getZ())) {
            type.placeObject((org.spongepowered.api.world.World) world, random, pos.getX(), pos.getY(), pos.getZ());
        }
    }
}
Also used : PopulatorObject(org.spongepowered.api.world.gen.PopulatorObject) Extent(org.spongepowered.api.world.extent.Extent) Vector3i(com.flowpowered.math.vector.Vector3i) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Location(org.spongepowered.api.world.Location)

Example 18 with Location

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

the class MixinWorldGenFlowers 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;
    BlockPos blockpos;
    // TODO should we actually do this division or let the x64 just be part
    // of the contract
    // The generate method makes 64 attempts, so divide the count by 64
    int n = (int) Math.ceil(this.count.getFlooredAmount(random) / 64f);
    PlantType type = PlantTypes.DANDELION;
    List<PlantType> 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() + 32);
        blockpos = chunkPos.add(x, y, z);
        if (this.override != null) {
            Location<Extent> pos = new Location<>(extent, VecHelper.toVector3i(blockpos));
            type = this.override.apply(pos);
        } else {
            result = this.flowers.get(random);
            if (result.isEmpty()) {
                continue;
            }
            type = result.get(0);
        }
        BlockFlower.EnumFlowerType enumflowertype = (BlockFlower.EnumFlowerType) (Object) type;
        BlockFlower blockflower = enumflowertype.getBlockType().getBlock();
        if (enumflowertype != null && blockflower.getDefaultState().getMaterial() != Material.AIR) {
            setGeneratedBlock(blockflower, enumflowertype);
            generate(world, random, blockpos);
        }
    }
}
Also used : Extent(org.spongepowered.api.world.extent.Extent) Vector3i(com.flowpowered.math.vector.Vector3i) PlantType(org.spongepowered.api.data.type.PlantType) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) BlockFlower(net.minecraft.block.BlockFlower) Location(org.spongepowered.api.world.Location)

Example 19 with Location

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

the class MixinBlockDynamicLiquid method beforeSetBlockState.

// Capture Lava falling on Water forming Stone
@Inject(method = "updateTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z"))
private void beforeSetBlockState(net.minecraft.world.World worldIn, BlockPos sourcePos, IBlockState state, Random rand, CallbackInfo ci) {
    Location<org.spongepowered.api.world.World> loc = new Location<>(((org.spongepowered.api.world.World) worldIn), sourcePos.getX(), sourcePos.getY(), sourcePos.getZ());
    LocatableBlock source = LocatableBlock.builder().location(loc).build();
    IBlockState newState = Blocks.STONE.getDefaultState();
    ChangeBlockEvent.Modify event = SpongeCommonEventFactory.callChangeBlockEventModifyLiquidMix(worldIn, sourcePos, newState, source);
    Transaction<BlockSnapshot> transaction = event.getTransactions().get(0);
    if (event.isCancelled() || !transaction.isValid()) {
        ci.cancel();
        return;
    }
    if (!worldIn.setBlockState(sourcePos.down(), BlockUtil.toNative(transaction.getFinal().getState()))) {
        ci.cancel();
    }
}
Also used : ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) IBlockState(net.minecraft.block.state.IBlockState) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Location(org.spongepowered.api.world.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 20 with Location

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

the class DamageEventHandler method findFirstMatchingBlock.

public static Location<World> findFirstMatchingBlock(Entity entity, AxisAlignedBB bb, Predicate<IBlockState> predicate) {
    int i = MathHelper.floor(bb.minX);
    int j = MathHelper.floor(bb.maxX + 1.0D);
    int k = MathHelper.floor(bb.minY);
    int l = MathHelper.floor(bb.maxY + 1.0D);
    int i1 = MathHelper.floor(bb.minZ);
    int j1 = MathHelper.floor(bb.maxZ + 1.0D);
    final IMixinChunkProviderServer spongeChunkProvider = (IMixinChunkProviderServer) entity.world.getChunkProvider();
    for (int k1 = i; k1 < j; ++k1) {
        for (int l1 = k; l1 < l; ++l1) {
            for (int i2 = i1; i2 < j1; ++i2) {
                BlockPos blockPos = new BlockPos(k1, l1, i2);
                final Chunk chunk = spongeChunkProvider.getLoadedChunkWithoutMarkingActive(blockPos.getX() >> 4, blockPos.getZ() >> 4);
                if (chunk == null) {
                    continue;
                }
                if (predicate.test(chunk.getBlockState(blockPos))) {
                    return new Location<>((World) entity.world, k1, l1, i2);
                }
            }
        }
    }
    // Entity is source of fire
    return ((org.spongepowered.api.entity.Entity) entity).getLocation();
}
Also used : IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation)

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