44import de .dafuqs .spectrum .helpers .*;
55import de .dafuqs .spectrum .items .conditional .*;
66import de .dafuqs .spectrum .registries .*;
7+ import net .fabricmc .fabric .api .item .v1 .*;
78import net .minecraft .client .item .*;
89import net .minecraft .entity .*;
10+ import net .minecraft .entity .player .*;
911import net .minecraft .item .*;
1012import net .minecraft .nbt .*;
1113import net .minecraft .server .network .*;
1719
1820import java .util .*;
1921
20- public class MidnightAberrationItem extends CloakedItem {
22+ public class MidnightAberrationItem extends CloakedItem implements FabricItem {
2123
2224 private static final Identifier MIDNIGHT_ABERRATION_CRUMBLING_ADVANCEMENT_ID = SpectrumCommon .locate ("midgame/crumble_midnight_aberration" );
2325 private static final String MIDNIGHT_ABERRATION_CRUMBLING_ADVANCEMENT_CRITERION = "have_midnight_aberration_crumble" ;
2426
27+ // Aberrations crumble in the player's inventory (or any inventory that ticks)
28+ // but only after a short grace period, to give them a chance to actually look at it / use it
29+ private static final int CRUMBLING_GRACE_PERIOD_TICKS = 40 ;
30+ private static final String FIRST_INVENTORY_TICK_NBT = "first_inventory_tick" ;
31+
2532 public MidnightAberrationItem (Settings settings , Identifier cloakAdvancementIdentifier , Item cloakItem ) {
2633 super (settings , cloakAdvancementIdentifier , cloakItem );
2734 }
@@ -36,6 +43,16 @@ public void inventoryTick(ItemStack stack, World world, Entity entity, int slot,
3643 return ;
3744 }
3845
46+ NbtCompound nbtCompound = stack .getOrCreateNbt ();
47+ if (!nbtCompound .contains (FIRST_INVENTORY_TICK_NBT )) {
48+ nbtCompound .putLong (FIRST_INVENTORY_TICK_NBT , world .getTime ());
49+ return ;
50+ }
51+ long firstInventoryTick = nbtCompound .getLong (FIRST_INVENTORY_TICK_NBT );
52+ if (world .getTime () < firstInventoryTick + CRUMBLING_GRACE_PERIOD_TICKS ) {
53+ return ;
54+ }
55+
3956 // check if it's a real stack in the player's inventory or just a proxy item (like a Bottomless Bundle)
4057 if (world .random .nextFloat () < 0.2F ) {
4158 stack .decrement (1 );
@@ -57,6 +74,25 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
5774 }
5875 }
5976
77+ @ Override
78+ public boolean allowNbtUpdateAnimation (PlayerEntity player , Hand hand , ItemStack oldStack , ItemStack newStack ) {
79+ // do not play the hand update animation when it starts crumbling
80+ NbtCompound oldNbt = oldStack .getNbt ();
81+ NbtCompound newNbt = newStack .getNbt ();
82+
83+ if (newNbt == null ) {
84+ return super .allowNbtUpdateAnimation (player , hand , oldStack , newStack );
85+ }
86+ if (oldNbt != null && oldNbt .contains (FIRST_INVENTORY_TICK_NBT )) {
87+ return super .allowNbtUpdateAnimation (player , hand , oldStack , newStack );
88+ }
89+ if (!newNbt .contains (FIRST_INVENTORY_TICK_NBT )) {
90+ return super .allowNbtUpdateAnimation (player , hand , oldStack , newStack );
91+ }
92+
93+ return false ;
94+ }
95+
6096 public ItemStack getStableStack () {
6197 ItemStack stack = getDefaultStack ();
6298 NbtCompound compound = stack .getOrCreateNbt ();
0 commit comments