Search in sources :

Example 1 with ImmutableSpongeValue

use of org.spongepowered.common.data.value.immutable.ImmutableSpongeValue in project SpongeCommon by SpongePowered.

the class MinecartBlockDataProcessor method remove.

@Override
public DataTransactionResult remove(DataHolder dataHolder) {
    if (dataHolder instanceof EntityMinecart) {
        EntityMinecart cart = (EntityMinecart) dataHolder;
        DataTransactionResult.Builder builder = DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS);
        if (cart.hasDisplayTile()) {
            ImmutableValue<BlockState> block = new ImmutableSpongeValue<>(Keys.REPRESENTED_BLOCK, (BlockState) cart.getDisplayTile());
            ImmutableValue<Integer> offset = new ImmutableSpongeValue<>(Keys.OFFSET, cart.getDisplayTileOffset());
            cart.setHasDisplayTile(false);
            builder.replace(block).replace(offset);
        }
        return builder.build();
    }
    return DataTransactionResult.failNoData();
}
Also used : BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) EntityMinecart(net.minecraft.entity.item.EntityMinecart) ImmutableSpongeValue(org.spongepowered.common.data.value.immutable.ImmutableSpongeValue)

Example 2 with ImmutableSpongeValue

use of org.spongepowered.common.data.value.immutable.ImmutableSpongeValue in project SpongeCommon by SpongePowered.

the class EntityCustomNameConverter method createTransaction.

@Override
public Optional<DataTransactionResult> createTransaction(String currentValue, String value) {
    Text currentText = SpongeTexts.fromLegacy(currentValue);
    Text newValue = SpongeTexts.fromLegacy(value);
    return Optional.of(DataTransactionResult.builder().replace(new ImmutableSpongeValue<>(Keys.DISPLAY_NAME, Text.of(), currentText)).success(new ImmutableSpongeValue<>(Keys.DISPLAY_NAME, Text.of(), newValue)).result(DataTransactionResult.Type.SUCCESS).build());
}
Also used : Text(org.spongepowered.api.text.Text) ImmutableSpongeValue(org.spongepowered.common.data.value.immutable.ImmutableSpongeValue)

Example 3 with ImmutableSpongeValue

use of org.spongepowered.common.data.value.immutable.ImmutableSpongeValue in project SpongeCommon by SpongePowered.

the class RepresentedBlockValueProcessor method removeFrom.

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (container instanceof EntityMinecart) {
        EntityMinecart cart = (EntityMinecart) container;
        ImmutableValue<BlockState> block = new ImmutableSpongeValue<>(Keys.REPRESENTED_BLOCK, (BlockState) cart.getDisplayTile());
        cart.setHasDisplayTile(false);
        return DataTransactionResult.builder().replace(block).build();
    }
    return DataTransactionResult.failNoData();
}
Also used : BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) EntityMinecart(net.minecraft.entity.item.EntityMinecart) ImmutableSpongeValue(org.spongepowered.common.data.value.immutable.ImmutableSpongeValue)

Aggregations

ImmutableSpongeValue (org.spongepowered.common.data.value.immutable.ImmutableSpongeValue)3 IBlockState (net.minecraft.block.state.IBlockState)2 EntityMinecart (net.minecraft.entity.item.EntityMinecart)2 BlockState (org.spongepowered.api.block.BlockState)2 DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)1 Text (org.spongepowered.api.text.Text)1