Search in sources :

Example 1 with AbstractMinecartBridge

use of org.spongepowered.common.bridge.world.entity.vehicle.AbstractMinecartBridge in project SpongeCommon by SpongePowered.

the class AbstractMinecartData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(AbstractMinecart.class).create(Keys.BLOCK_STATE).get(h -> h.hasCustomDisplay() ? (BlockState) h.getDisplayBlockState() : null).set((h, v) -> h.setDisplayBlockState((net.minecraft.world.level.block.state.BlockState) v)).delete(h -> h.setCustomDisplay(false)).create(Keys.IS_ON_RAIL).get(h -> {
        final BlockPos pos = h.blockPosition();
        if (h.level.getBlockState(pos).is(BlockTags.RAILS)) {
            return true;
        }
        final BlockPos posBelow = pos.offset(0, -1, 0);
        return h.level.getBlockState(posBelow).is(BlockTags.RAILS);
    }).create(Keys.MINECART_BLOCK_OFFSET).get(AbstractMinecart::getDisplayOffset).setAnd(AbstractMinecartData::setBlockOffset).deleteAnd(h -> AbstractMinecartData.setBlockOffset(h, h.getDefaultDisplayOffset())).asMutable(AbstractMinecartBridge.class).create(Keys.AIRBORNE_VELOCITY_MODIFIER).get(AbstractMinecartBridge::bridge$getAirborneMod).set(AbstractMinecartBridge::bridge$setAirborneMod).create(Keys.SLOWS_UNOCCUPIED).get(AbstractMinecartBridge::bridge$getSlowWhenEmpty).set(AbstractMinecartBridge::bridge$setSlowWhenEmpty).create(Keys.DERAILED_VELOCITY_MODIFIER).get(AbstractMinecartBridge::bridge$getDerailedMod).set(AbstractMinecartBridge::bridge$setDerailedMod).create(Keys.POTENTIAL_MAX_SPEED).get(AbstractMinecartBridge::bridge$getMaxSpeed).set(AbstractMinecartBridge::bridge$setMaxSpeed);
    final ResourceKey minecartDataStoreKey = ResourceKey.sponge("minecart");
    registrator.spongeDataStore(minecartDataStoreKey, 2, new DataContentUpdater[] { AbstractMinecartData.MINECART_UPDATER_BYTE_TO_BOOL_FIX }, AbstractMinecartBridge.class, Keys.POTENTIAL_MAX_SPEED, Keys.SLOWS_UNOCCUPIED, Keys.AIRBORNE_VELOCITY_MODIFIER, Keys.DERAILED_VELOCITY_MODIFIER);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Minecart.MAX_SPEED, minecartDataStoreKey, Keys.POTENTIAL_MAX_SPEED);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Minecart.SLOW_WHEN_EMPTY, minecartDataStoreKey, Keys.SLOWS_UNOCCUPIED);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Minecart.AIRBORNE_MODIFIER, minecartDataStoreKey, Keys.AIRBORNE_VELOCITY_MODIFIER);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Minecart.DERAILED_MODIFIER, minecartDataStoreKey, Keys.DERAILED_VELOCITY_MODIFIER);
}
Also used : BlockState(org.spongepowered.api.block.BlockState) DataContentUpdater(org.spongepowered.api.data.persistence.DataContentUpdater) Keys(org.spongepowered.api.data.Keys) BlockPos(net.minecraft.core.BlockPos) Constants(org.spongepowered.common.util.Constants) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) BlockTags(net.minecraft.tags.BlockTags) AbstractMinecartBridge(org.spongepowered.common.bridge.world.entity.vehicle.AbstractMinecartBridge) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) ResourceKey(org.spongepowered.api.ResourceKey) ByteToBooleanContentUpdater(org.spongepowered.common.data.ByteToBooleanContentUpdater) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) BlockState(org.spongepowered.api.block.BlockState) AbstractMinecartBridge(org.spongepowered.common.bridge.world.entity.vehicle.AbstractMinecartBridge) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) BlockPos(net.minecraft.core.BlockPos) ResourceKey(org.spongepowered.api.ResourceKey)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 BlockTags (net.minecraft.tags.BlockTags)1 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)1 ResourceKey (org.spongepowered.api.ResourceKey)1 BlockState (org.spongepowered.api.block.BlockState)1 Keys (org.spongepowered.api.data.Keys)1 DataContentUpdater (org.spongepowered.api.data.persistence.DataContentUpdater)1 AbstractMinecartBridge (org.spongepowered.common.bridge.world.entity.vehicle.AbstractMinecartBridge)1 ByteToBooleanContentUpdater (org.spongepowered.common.data.ByteToBooleanContentUpdater)1 SpongeDataManager (org.spongepowered.common.data.SpongeDataManager)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 Constants (org.spongepowered.common.util.Constants)1