Sponge: Keys.DESPAWN_DELAY does not work (as expected?)

Created on 9 Apr 2018  路  7Comments  路  Source: SpongePowered/Sponge

I am currently running

  • SpongeForge version: 1.12.2-2611-7.1.0-BETA-3005
  • SpongeVanilla version: 1.12.2-7.1.0-BETA-38
  • Java version: 1.8.0_161
  • Operating System: Windows 10

  • Plugins/Mods: Minecraft, Mod Coder Pack, SpongeAPI, SpongeVanilla, Core, CoreLib, GameLib, Jump'n'Clash, LuckPerms, SpongyCord, ViaBackwards, ViaVersion


Issue Description

Setting the Keys.DESPAWN_DELAY for an Item entity either doesn't work at all, or does not do what the name suggests.

So for example I ran the following

item.offer(Keys.DESPAWN_DELAY, 5 * 20);

thinking this would cause the item to despawn after 5 seconds, but it does not. I played with the value (decreased it to 5) and tested a negative value, but nothing observable did change.

The transaction always succeeds:

DataTransactionResult{resultType=SUCCESS, rejectedData=[], replacedData=[ImmutableSpongeBoundedValue{key=SpongeKey{name=Despawn Delay, id=sponge:despawn_delay, valueToken=org.spongepowered.api.data.value.mutable.MutableBoundedValue<java.lang.Integer>, elementToken=java.lang.Integer, query=DespawnDelay}, defaultValue=0, actualValue=40}], successfulData=[ImmutableSpongeBoundedValue{key=SpongeKey{name=Despawn Delay, id=sponge:despawn_delay, valueToken=org.spongepowered.api.data.value.mutable.MutableBoundedValue<java.lang.Integer>, elementToken=java.lang.Integer, query=DespawnDelay}, defaultValue=0, actualValue=100}]}

data 1.12

Most helpful comment

I found the issue and I have a fix. Even if it was working as intended, the documentation was wrong, so I am also going to modify it so the key and DespawnableData work as expected(according to the current documentation and as you guys expected it to work). Will open a PR tomorrow and get it in very soon.

All 7 comments

When I tested this on SpongeVanilla-1.12.2-7.1.0-BETA-38 I noticed that doing entity.offer(Keys.DESPAWN_DELAY, 5); appeared to change the pickup delay as when I dropped the item I would pick it back up before it hit the ground.

entity.offer(Keys.DESPAWN_DELAY, 100000); also prevented the item from being picked up.

@Listener
public void onDropItem(DropItemEvent.Dispense event, @Root Player player) {
    if (event.isCancelled() || event.getEntities().isEmpty()) {
        return;
    }

    for (Entity entity : event.getEntities()) {
        if (entity instanceof Item) {
            entity.offer(Keys.DESPAWN_DELAY, 5);
        }
    }
}

@BrainStone Can you add slightly more context? This is a dumb answer, but are you setting this on the EntityItem or an Item Stack? There's been several times when people have attempted to set data on the wrong type, and expected it to persist across transformation boundaries. e.g. set invalid data on itemStack, expect to see it on EntityItem.

@ryantheleach, I think LXGaming added already all details necessary.

But yes, I鈥檓 definitely offering that key to an EntityItem. I personally didn鈥檛 notice the mix up, because I also set the pick up delay directly after.

Apologies, I misread ' change the pickup delay' as ' change the despawn delay' in LXGaming's post.

Any updates?

I found the issue and I have a fix. Even if it was working as intended, the documentation was wrong, so I am also going to modify it so the key and DespawnableData work as expected(according to the current documentation and as you guys expected it to work). Will open a PR tomorrow and get it in very soon.

Fixed by a624e5c92e6a62cdb15df3d81624bab4863d22ed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TBlueF picture TBlueF  路  5Comments

nikosgram picture nikosgram  路  3Comments

XakepSDK picture XakepSDK  路  3Comments

jeffreykog picture jeffreykog  路  4Comments

DarkArc picture DarkArc  路  3Comments