use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class BoatData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Boat.class).create(Keys.BOAT_TYPE).get(h -> ((BoatType) (Object) h.getBoatType())).set((h, v) -> h.setType((Boat.Type) (Object) v)).asMutable(BoatAccessor.class).create(Keys.IS_IN_WATER).get(h -> h.accessor$status() == Boat.Status.IN_WATER).asMutable(BoatBridge.class).create(Keys.CAN_MOVE_ON_LAND).get(BoatBridge::bridge$getMoveOnLand).set(BoatBridge::bridge$setMoveOnLand).asMutable(BoatBridge.class).create(Keys.OCCUPIED_DECELERATION).get(BoatBridge::bridge$getOccupiedDecelerationSpeed).set(BoatBridge::bridge$setOccupiedDecelerationSpeed).asMutable(BoatBridge.class).create(Keys.MAX_SPEED).get(BoatBridge::bridge$getMaxSpeed).set(BoatBridge::bridge$setMaxSpeed).asMutable(BoatBridge.class).create(Keys.UNOCCUPIED_DECELERATION).get(BoatBridge::bridge$getUnoccupiedDecelerationSpeed).set(BoatBridge::bridge$setUnoccupiedDecelerationSpeed);
final ResourceKey boatDataStoreKey = ResourceKey.sponge("boat");
registrator.spongeDataStore(boatDataStoreKey, 2, new DataContentUpdater[] { BoatData.BOAT_UPDATER_BYTE_TO_BOOL_FIX }, BoatBridge.class, Keys.MAX_SPEED, Keys.CAN_MOVE_ON_LAND, Keys.OCCUPIED_DECELERATION, Keys.UNOCCUPIED_DECELERATION);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_MAX_SPEED, boatDataStoreKey, Keys.MAX_SPEED);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_MOVE_ON_LAND, boatDataStoreKey, Keys.CAN_MOVE_ON_LAND);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_OCCUPIED_DECELERATION_SPEED, boatDataStoreKey, Keys.OCCUPIED_DECELERATION);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_UNOCCUPIED_DECELERATION_SPEED, boatDataStoreKey, Keys.UNOCCUPIED_DECELERATION);
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class CreatorTrackedData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(CreatorTrackedBridge.class).create(Keys.NOTIFIER).get(m -> m.tracker$getNotifierUUID().orElse(null)).set((b, n) -> b.tracker$setTrackedUUID(PlayerTracker.Type.NOTIFIER, n)).create(Keys.CREATOR).get(m -> m.tracker$getCreatorUUID().orElse(null)).set((b, n) -> b.tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, n));
final ResourceKey dataStoreKey = ResourceKey.sponge("creator_tracked");
registrator.spongeDataStore(dataStoreKey, CreatorTrackedBridge.class, Keys.NOTIFIER, Keys.CREATOR);
SpongeDataManager.INSTANCE.registerLegacySpongeData(PlayerTracker.Type.NOTIFIER.compoundKey, dataStoreKey, Keys.NOTIFIER);
SpongeDataManager.INSTANCE.registerLegacySpongeData(PlayerTracker.Type.CREATOR.compoundKey, dataStoreKey, Keys.CREATOR);
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class ArrowData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Arrow.class).create(Keys.POTION_EFFECTS).get(h -> {
final Set<MobEffectInstance> effects = ((ArrowAccessor) h).accessor$effects();
return effects.stream().map(effect -> (PotionEffect) new MobEffectInstance(effect.getEffect(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.isVisible())).collect(Collectors.toList());
}).set((h, v) -> {
((ArrowAccessor) h).accessor$effects().clear();
for (final PotionEffect effect : v) {
final MobEffectInstance mcEffect = new MobEffectInstance(((MobEffectInstance) effect).getEffect(), (int) effect.duration().ticks(), effect.amplifier(), effect.isAmbient(), effect.showsParticles());
h.addEffect(mcEffect);
}
});
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class WolfData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Wolf.class).create(Keys.DYE_COLOR).get(h -> (DyeColor) (Object) h.getCollarColor()).set((h, v) -> h.setCollarColor((net.minecraft.world.item.DyeColor) (Object) v)).create(Keys.IS_BEGGING_FOR_FOOD).get(Wolf::isInterested).set(Wolf::setIsInterested).create(Keys.IS_WET).get(h -> ((WolfAccessor) h).accessor$isWet() || ((WolfAccessor) h).accessor$isShaking()).set((h, v) -> {
final WolfAccessor accessor = (WolfAccessor) h;
accessor.accessor$isWet(v);
accessor.accessor$isShaking(v);
accessor.accessor$shakeAnim(0f);
accessor.accessor$shakeAnimO(0f);
});
}
use of org.spongepowered.common.data.provider.DataProviderRegistrator in project SpongeCommon by SpongePowered.
the class ItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.APPLICABLE_POTION_EFFECTS).get(h -> {
if (h.isEdible()) {
final List<Pair<MobEffectInstance, Float>> itemEffects = h.getItem().getFoodProperties().getEffects();
final WeightedTable<PotionEffect> effects = new WeightedTable<>();
final ChanceTable<PotionEffect> chance = new ChanceTable<>();
for (final Pair<MobEffectInstance, Float> effect : itemEffects) {
chance.add((PotionEffect) effect.getFirst(), effect.getSecond());
}
effects.add(new NestedTableEntry<>(1, chance));
return effects;
}
return null;
}).create(Keys.BURN_TIME).get(h -> {
final Integer burnTime = AbstractFurnaceBlockEntity.getFuel().get(h.getItem());
if (burnTime != null && burnTime > 0) {
return burnTime;
}
return null;
}).create(Keys.CAN_HARVEST).get(h -> {
final Item item = h.getItem();
if (item instanceof DiggerItemAccessor && !(item instanceof PickaxeItem)) {
final Set<Block> blocks = ((DiggerItemAccessor) item).accessor$blocks();
return ImmutableSet.copyOf((Set<BlockType>) (Object) blocks);
}
final Set<BlockType> blockTypes = Registry.BLOCK.stream().filter(b -> item.isCorrectToolForDrops(b.defaultBlockState())).map(BlockType.class::cast).collect(ImmutableSet.toImmutableSet());
return blockTypes.isEmpty() ? null : blockTypes;
}).create(Keys.CONTAINER_ITEM).get(h -> (ItemType) h.getItem().getCraftingRemainingItem()).create(Keys.DISPLAY_NAME).get(h -> SpongeAdventure.asAdventure(h.getDisplayName())).create(Keys.CUSTOM_MODEL_DATA).get(h -> {
final CompoundTag tag = h.getTag();
if (tag == null || !tag.contains(Constants.Item.CUSTOM_MODEL_DATA, Constants.NBT.TAG_INT)) {
return null;
}
return tag.getInt(Constants.Item.CUSTOM_MODEL_DATA);
}).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTag();
tag.putInt(Constants.Item.CUSTOM_MODEL_DATA, v);
}).delete(h -> {
final CompoundTag tag = h.getTag();
if (tag != null) {
tag.remove(Constants.Item.CUSTOM_MODEL_DATA);
}
}).create(Keys.CUSTOM_NAME).get(h -> {
if (h.hasCustomHoverName()) {
return SpongeAdventure.asAdventure(h.getHoverName());
}
if (h.getItem() == Items.WRITTEN_BOOK) {
// When no custom name is set on a written book fallback to its title
// The custom name has a higher priority than the title so no setter is needed.
final CompoundTag tag = h.getTag();
if (tag != null) {
final String title = tag.getString(Constants.Item.Book.ITEM_BOOK_TITLE);
return LegacyComponentSerializer.legacySection().deserialize(title);
}
}
return null;
}).set((h, v) -> h.setHoverName(SpongeAdventure.asVanilla(v))).delete(ItemStack::resetHoverName).create(Keys.IS_UNBREAKABLE).get(h -> {
final CompoundTag tag = h.getTag();
if (tag == null || !tag.contains(Constants.Item.ITEM_UNBREAKABLE, Constants.NBT.TAG_BYTE)) {
return false;
}
return tag.getBoolean(Constants.Item.ITEM_UNBREAKABLE);
}).set(ItemStackData::setIsUnbrekable).delete(h -> ItemStackData.setIsUnbrekable(h, false)).create(Keys.LORE).get(h -> {
final CompoundTag tag = h.getTag();
if (tag == null || !tag.contains(Constants.Item.ITEM_DISPLAY)) {
return null;
}
final CompoundTag displayCompound = tag.getCompound(Constants.Item.ITEM_DISPLAY);
final ListTag list = displayCompound.getList(Constants.Item.ITEM_LORE, Constants.NBT.TAG_STRING);
return list.isEmpty() ? null : SpongeAdventure.json(list.stream().collect(NBTCollectors.toStringList()));
}).set((h, v) -> {
if (v.isEmpty()) {
ItemStackData.deleteLore(h);
return;
}
final ListTag list = SpongeAdventure.listTagJson(v);
h.getOrCreateTagElement(Constants.Item.ITEM_DISPLAY).put(Constants.Item.ITEM_LORE, list);
}).delete(ItemStackData::deleteLore).create(Keys.MAX_DURABILITY).get(h -> h.getItem().canBeDepleted() ? h.getItem().getMaxDamage() : null).supports(h -> h.getItem().canBeDepleted()).create(Keys.ITEM_DURABILITY).get(stack -> stack.getMaxDamage() - stack.getDamageValue()).set((stack, durability) -> stack.setDamageValue(stack.getMaxDamage() - durability)).supports(h -> h.getItem().canBeDepleted()).create(Keys.ITEM_RARITY).get(stack -> (ItemRarity) (Object) stack.getRarity()).create(Keys.REPLENISHED_FOOD).get(h -> {
if (h.getItem().isEdible()) {
final FoodProperties food = h.getItem().getFoodProperties();
return food == null ? null : food.getNutrition();
}
return null;
}).supports(h -> h.getItem().isEdible()).create(Keys.REPLENISHED_SATURATION).get(h -> {
if (h.getItem().isEdible()) {
final FoodProperties food = h.getItem().getFoodProperties();
if (food != null) {
// Translate's Minecraft's weird internal value to the actual saturation value
return food.getSaturationModifier() * food.getNutrition() * 2.0;
}
}
return null;
}).supports(h -> h.getItem().isEdible());
}
Aggregations