Search in sources :

Example 1 with ItemEntityBridge

use of org.spongepowered.common.bridge.world.entity.item.ItemEntityBridge in project SpongeCommon by SpongePowered.

the class ItemData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemEntity.class).create(Keys.ITEM_STACK_SNAPSHOT).get(h -> ItemStackUtil.snapshotOf(h.getItem())).set((h, v) -> h.setItem(ItemStackUtil.fromSnapshotToNative(v))).asMutable(ItemEntityBridge.class).create(Keys.DESPAWN_DELAY).get(h -> new SpongeTicks(h.bridge$getDespawnDelay())).setAnd((h, v) -> {
        final int ticks = (int) v.ticks();
        if (ticks < 0) {
            return false;
        }
        h.bridge$setDespawnDelay(ticks, false);
        return true;
    }).create(Keys.INFINITE_DESPAWN_DELAY).get(ItemEntityBridge::bridge$infiniteDespawnDelay).set((h, v) -> h.bridge$setDespawnDelay(h.bridge$getDespawnDelay(), v)).create(Keys.INFINITE_PICKUP_DELAY).get(ItemEntityBridge::bridge$infinitePickupDelay).set((h, v) -> h.bridge$setPickupDelay(h.bridge$getPickupDelay(), v)).create(Keys.PICKUP_DELAY).get(h -> new SpongeTicks(h.bridge$getPickupDelay())).set((h, v) -> h.bridge$setPickupDelay((int) v.ticks(), false)).create(ItemData.PREVIOUS_PICKUP_DELAY).get(v -> -1).set(ItemEntityBridge::bridge$setPrevPickupDelay).create(ItemData.PREVIOUS_DESPAWN_DELAY).get(v -> -1).set(ItemEntityBridge::bridge$setPrevDespawnDelay);
    final ResourceKey item = ResourceKey.sponge("item");
    registrator.spongeDataStore(item, 2, new DataContentUpdater[] { ItemData.INFINITE_DELAYS_UPDATER_BYTE_TO_BOOL_FIX }, ItemEntityBridge.class, Keys.INFINITE_PICKUP_DELAY, ItemData.PREVIOUS_PICKUP_DELAY, Keys.INFINITE_DESPAWN_DELAY, ItemData.PREVIOUS_DESPAWN_DELAY);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Item.INFINITE_PICKUP_DELAY, item, Keys.INFINITE_PICKUP_DELAY);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Item.PREVIOUS_PICKUP_DELAY, item, ItemData.PREVIOUS_PICKUP_DELAY);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Item.INFINITE_DESPAWN_DELAY, item, Keys.INFINITE_DESPAWN_DELAY);
    SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Sponge.Entity.Item.PREVIOUS_DESPAWN_DELAY, item, ItemData.PREVIOUS_DESPAWN_DELAY);
}
Also used : DataContentUpdater(org.spongepowered.api.data.persistence.DataContentUpdater) Constants(org.spongepowered.common.util.Constants) ItemEntityBridge(org.spongepowered.common.bridge.world.entity.item.ItemEntityBridge) Key(org.spongepowered.api.data.Key) Value(org.spongepowered.api.data.value.Value) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) Keys(org.spongepowered.api.data.Keys) ItemStackUtil(org.spongepowered.common.item.util.ItemStackUtil) ItemEntity(net.minecraft.world.entity.item.ItemEntity) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) ResourceKey(org.spongepowered.api.ResourceKey) ByteToBooleanContentUpdater(org.spongepowered.common.data.ByteToBooleanContentUpdater) SpongeTicks(org.spongepowered.common.util.SpongeTicks) ItemEntityBridge(org.spongepowered.common.bridge.world.entity.item.ItemEntityBridge) SpongeTicks(org.spongepowered.common.util.SpongeTicks) ResourceKey(org.spongepowered.api.ResourceKey)

Aggregations

ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 ResourceKey (org.spongepowered.api.ResourceKey)1 Key (org.spongepowered.api.data.Key)1 Keys (org.spongepowered.api.data.Keys)1 DataContentUpdater (org.spongepowered.api.data.persistence.DataContentUpdater)1 Value (org.spongepowered.api.data.value.Value)1 ItemEntityBridge (org.spongepowered.common.bridge.world.entity.item.ItemEntityBridge)1 ByteToBooleanContentUpdater (org.spongepowered.common.data.ByteToBooleanContentUpdater)1 SpongeDataManager (org.spongepowered.common.data.SpongeDataManager)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 ItemStackUtil (org.spongepowered.common.item.util.ItemStackUtil)1 Constants (org.spongepowered.common.util.Constants)1 SpongeTicks (org.spongepowered.common.util.SpongeTicks)1