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);
}
Aggregations