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