Search in sources :

Example 6 with ImmutableDataManipulator

use of org.spongepowered.api.data.manipulator.ImmutableDataManipulator in project LanternServer by LanternPowered.

the class LanternBlockState method merge.

@Override
public BlockState merge(BlockState that, MergeFunction function) {
    if (!getType().equals(that.getType())) {
        return this;
    } else {
        BlockState temp = this;
        for (ImmutableDataManipulator<?, ?> manipulator : that.getManipulators()) {
            final ImmutableDataManipulator old = temp.get(manipulator.getClass()).orElse(null);
            final Optional<BlockState> optional = temp.with(checkNotNull(function.merge(old, manipulator)));
            if (optional.isPresent()) {
                temp = optional.get();
            } else {
                return temp;
            }
        }
        return temp;
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator)

Example 7 with ImmutableDataManipulator

use of org.spongepowered.api.data.manipulator.ImmutableDataManipulator in project SpongeCommon by SpongePowered.

the class SpongeBlockSnapshot method with.

@Override
public Optional<BlockSnapshot> with(ImmutableDataManipulator<?, ?> valueContainer) {
    if (((IMixinBlock) this.blockState.getType()).supports((Class<ImmutableDataManipulator<?, ?>>) valueContainer.getClass())) {
        final BlockState newState;
        boolean changeState = false;
        if (this.blockState.supports((Class<ImmutableDataManipulator<?, ?>>) valueContainer.getClass())) {
            newState = this.blockState.with(valueContainer).get();
            changeState = true;
        } else {
            newState = this.blockState;
        }
        if (changeState) {
            return Optional.of(createBuilder().blockState(newState).build());
        }
        final SpongeBlockSnapshotBuilder builder = createBuilder();
        builder.add(valueContainer);
        return Optional.of(builder.build());
    }
    return Optional.of(createBuilder().add(valueContainer).build());
}
Also used : IMixinBlock(org.spongepowered.common.interfaces.block.IMixinBlock) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator)

Example 8 with ImmutableDataManipulator

use of org.spongepowered.api.data.manipulator.ImmutableDataManipulator in project SpongeCommon by SpongePowered.

the class MixinWorld_Data method supports.

@Override
public boolean supports(int x, int y, int z, Class<? extends DataManipulator<?, ?>> manipulatorClass) {
    final BlockState blockState = getBlock(x, y, z);
    final List<ImmutableDataManipulator<?, ?>> immutableDataManipulators = blockState.getManipulators();
    boolean blockSupports = false;
    for (ImmutableDataManipulator<?, ?> manipulator : immutableDataManipulators) {
        if (manipulator.asMutable().getClass().isAssignableFrom(manipulatorClass)) {
            blockSupports = true;
            break;
        }
    }
    if (!blockSupports) {
        final Optional<TileEntity> tileEntity = getTileEntity(x, y, z);
        final boolean tileEntitySupports;
        tileEntitySupports = tileEntity.isPresent() && tileEntity.get().supports(manipulatorClass);
        return tileEntitySupports;
    }
    return true;
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator)

Aggregations

ImmutableDataManipulator (org.spongepowered.api.data.manipulator.ImmutableDataManipulator)8 ImmutableList (com.google.common.collect.ImmutableList)4 BlockState (org.spongepowered.api.block.BlockState)4 ImmutableSet (com.google.common.collect.ImmutableSet)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)2 DataView (org.spongepowered.api.data.DataView)2 DataManipulator (org.spongepowered.api.data.manipulator.DataManipulator)2 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableTable (com.google.common.collect.ImmutableTable)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1