use of org.spongepowered.common.data.provider.DataProviderRegistrator 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);
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class EndermiteData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Endermite.class).create(Keys.DESPAWN_DELAY).get(h -> {
if (h.isPersistenceRequired()) {
return null;
}
return new SpongeTicks(((EndermiteAccessor) h).accessor$life());
}).setAnd((h, v) -> {
if (h.isPersistenceRequired()) {
return false;
}
final int ticks = (int) v.ticks();
if (ticks < 0 || ticks > EndermiteData.DESPAWN_DELAY_MAX) {
return false;
}
((EndermiteAccessor) h).accessor$life(ticks);
return true;
});
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class ShieldItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.DYE_COLOR).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null || tag.contains(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_LIST)) {
return DyeColors.WHITE.get();
}
final int id = tag.getInt(Constants.TileEntity.Banner.BANNER_BASE);
return (DyeColor) (Object) net.minecraft.world.item.DyeColor.byId(id);
}).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
tag.putInt(Constants.TileEntity.Banner.BANNER_BASE, ((net.minecraft.world.item.DyeColor) (Object) v).getId());
}).supports(h -> h.getItem() instanceof ShieldItem).create(Keys.BANNER_PATTERN_LAYERS).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null || !tag.contains(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_LIST)) {
return new ArrayList<>();
}
final ListTag layersList = tag.getList(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_COMPOUND);
return layersList.stream().map(layer -> ShieldItemStackData.layerFromNbt((CompoundTag) layer)).collect(Collectors.toList());
}).set((h, v) -> {
final ListTag layersTag = v.stream().filter(layer -> layer.shape() != BannerPatternShapes.BASE.get()).map(ShieldItemStackData::layerToNbt).collect(NBTCollectors.toTagList());
final CompoundTag blockEntity = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
blockEntity.put(Constants.TileEntity.Banner.BANNER_PATTERNS, layersTag);
if (h.getItem() instanceof ShieldItem) {
// TODO reject BannerPatternShapes.BASE for BannerItem?
v.stream().filter(layer -> layer.shape() == BannerPatternShapes.BASE.get()).forEach(layer -> {
blockEntity.putInt(Constants.TileEntity.Banner.BANNER_BASE, ((net.minecraft.world.item.DyeColor) (Object) layer.color()).getId());
});
}
}).supports(h -> h.getItem() instanceof ShieldItem || h.getItem() instanceof BannerItem);
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class SkullItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.GAME_PROFILE).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.Skull.ITEM_SKULL_OWNER);
final GameProfile mcProfile = tag == null ? null : NbtUtils.readGameProfile(tag);
return mcProfile == null ? null : SpongeGameProfile.of(mcProfile);
}).set((h, v) -> {
final com.mojang.authlib.GameProfile mcProfile = SpongeGameProfile.toMcProfile(v);
final CompoundTag tag = NbtUtils.writeGameProfile(new CompoundTag(), mcProfile);
h.addTagElement(Constants.Item.Skull.ITEM_SKULL_OWNER, tag);
}).delete(h -> h.removeTagKey(Constants.Item.Skull.ITEM_SKULL_OWNER)).supports(h -> h.getItem() instanceof PlayerHeadItem);
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class ServerPlayerData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ServerPlayer.class).create(Keys.GAME_MODE).get(h -> (GameMode) (Object) h.gameMode.getGameModeForPlayer()).set((h, v) -> h.setGameMode((GameType) (Object) v)).create(Keys.SKIN_PROFILE_PROPERTY).get(h -> {
final Collection<Property> properties = h.getGameProfile().getProperties().get(ProfileProperty.TEXTURES);
if (properties.isEmpty()) {
return null;
}
return new SpongeProfileProperty(properties.iterator().next());
}).create(Keys.SPECTATOR_TARGET).get(h -> (Entity) h.getCamera()).set((h, v) -> h.setCamera((net.minecraft.world.entity.Entity) v)).delete(h -> h.setCamera(null)).create(Keys.STATISTICS).get(h -> ((StatsCounterBridge) h.getStats()).bridge$getStatsData().entrySet().stream().collect(Collectors.toMap(e -> (Statistic) e.getKey(), e -> e.getValue().longValue()))).set((h, v) -> v.forEach((ik, iv) -> h.getStats().setValue(h, (Stat<?>) ik, iv.intValue()))).create(Keys.CHAT_VISIBILITY).get(h -> {
final ChatVisibility visibility = (ChatVisibility) (Object) h.getChatVisibility();
if (visibility == null) {
return ChatVisibilities.FULL.get();
}
return visibility;
}).asMutable(ServerPlayerAccessor.class).create(Keys.HAS_VIEWED_CREDITS).get(ServerPlayerAccessor::accessor$seenCredits).set(ServerPlayerAccessor::accessor$seenCredits).create(Keys.CHAT_COLORS_ENABLED).get(ServerPlayerAccessor::accessor$canChatColor).asMutable(ServerPlayerBridge.class).create(Keys.LOCALE).get(ServerPlayerBridge::bridge$getLanguage).create(Keys.HEALTH_SCALE).get(ServerPlayerEntityHealthScaleBridge::bridge$getHealthScale).setAnd((h, v) -> {
if (v < 1f || v > Float.MAX_VALUE) {
return false;
}
h.bridge$setHealthScale(v);
return true;
}).delete(b -> b.bridge$setHealthScale(null)).create(Keys.VIEW_DISTANCE).get(ServerPlayerBridge::bridge$getViewDistance).create(Keys.SKIN_PARTS).get(ServerPlayerBridge::bridge$getSkinParts).create(Keys.IS_SLEEPING_IGNORED).get(ServerPlayerBridge::bridge$sleepingIgnored).set(ServerPlayerBridge::bridge$setSleepingIgnored);
registrator.spongeDataStore(Keys.HEALTH_SCALE.key(), ServerPlayerEntityHealthScaleBridge.class, Keys.HEALTH_SCALE);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Player.HEALTH_SCALE, Keys.HEALTH_SCALE.key(), Keys.HEALTH_SCALE);
}
Aggregations