77import net .minecraft .item .ItemStack ;
88import net .minecraft .item .Items ;
99import net .minecraft .item .SpawnEggItem ;
10+ import net .minecraft .nbt .NbtCompound ;
1011import net .minecraft .nbt .NbtList ;
1112import net .minecraft .potion .PotionUtil ;
12- import net .minecraft .registry .Registries ;
13- import net .minecraft .util .Identifier ;
13+ import org .jetbrains .annotations .Nullable ;
1414import org .samo_lego .golfiv .casts .ItemStackChecker ;
1515import org .spongepowered .asm .mixin .Mixin ;
1616import org .spongepowered .asm .mixin .Shadow ;
@@ -45,6 +45,8 @@ public abstract class ItemStackMixinCast_ItemStackChecker implements ItemStackCh
4545 @ Shadow
4646 public abstract Item getItem ();
4747
48+ @ Shadow
49+ private @ Nullable NbtCompound nbt ;
4850 private final ItemStack itemStack = (ItemStack ) (Object ) this ;
4951
5052 /**
@@ -58,55 +60,49 @@ public void makeLegal(boolean survival) {
5860 Map <Enchantment , Integer > enchantments = EnchantmentHelper .fromNbt (this .getEnchantments ());
5961
6062 // Checks item enchantments
61- if ((survival && golfConfig .items .survival .checkEnchants ) || (!survival && golfConfig .items .creative .checkEnchants ))
62- for (Map .Entry <Enchantment , Integer > ench : enchantments .entrySet ()) {
63+ if ((survival && golfConfig .items .survival .checkEnchants ) || (!survival && golfConfig .items .creative .checkEnchants ))
64+ for (Map .Entry <Enchantment , Integer > ench : enchantments .entrySet ()) {
6365 Enchantment enchantment = ench .getKey ();
6466 int level = ench .getValue ();
6567
6668 Set <Enchantment > otherEnchants = EnchantmentHelper .get (this .itemStack ).keySet ();
6769 otherEnchants .remove (enchantment );
6870
69- if (!enchantment .isAcceptableItem (this .itemStack ) || !EnchantmentHelper .isCompatible (otherEnchants , enchantment ) || level > enchantment .getMaxLevel ()) {
71+ if (!enchantment .isAcceptableItem (this .itemStack ) ||
72+ !EnchantmentHelper .isCompatible (otherEnchants , enchantment ) ||
73+ level > enchantment .getMaxLevel ()) {
7074 this .removeSubNbt ("Enchantments" );
7175 break ;
7276 }
7377 }
7478
7579 // Checks potion
76- if (
77- (
78- (survival && golfConfig .items .survival .checkPotionLevels ) ||
79- (!survival && golfConfig .items .creative .checkPotionLevels )
80- ) &&
81- (
82- this .itemStack .getItem () == Items .POTION ||
83- this .itemStack .getItem () == Items .SPLASH_POTION ||
84- this .itemStack .getItem () == Items .LINGERING_POTION
85- )
86- ) {
80+ if (((survival && golfConfig .items .survival .checkPotionLevels ) || (!survival && golfConfig .items .creative .checkPotionLevels )) &&
81+ (this .itemStack .getItem () == Items .POTION ||
82+ this .itemStack .getItem () == Items .SPLASH_POTION ||
83+ this .itemStack .getItem () == Items .LINGERING_POTION )) {
8784 List <StatusEffectInstance > effects = PotionUtil .getCustomPotionEffects (this .itemStack );
88- for (StatusEffectInstance effect : effects ) {
89- if (effect .getAmplifier () > 1 ) {
85+
86+ for (StatusEffectInstance effect : effects ) {
87+ if (effect .getAmplifier () > 1 ) {
9088 this .removeSubNbt ("CustomPotionEffects" );
9189 this .removeSubNbt ("Potion" );
9290 break ;
9391 }
9492 }
9593 }
9694
97- Identifier id = Registries .ITEM .getId (this .itemStack .getItem ());
98- if (survival && (golfConfig .items .survival .bannedItems .contains (id .toString ()) || (golfConfig .items .survival .bannedItems .contains ("minecraft:spawn_egg" ) && this .itemStack .getItem () instanceof SpawnEggItem ))) {
95+ String nbt = golfConfig .items .survival .bannedItems .get (this .itemStack .getItem ());
96+ NbtCompound tag = this .itemStack .getNbt ();
97+
98+ if (survival && nbt != null && (nbt .isEmpty () || tag != null && tag .toString ().equals (nbt )) ||
99+ (golfConfig .items .survival .banSpawnEggs && this .itemStack .getItem () instanceof SpawnEggItem )) {
99100 this .setCount (0 );
100- }
101+ } else if (((survival && golfConfig .items .survival .checkItemCount ) ||
102+ (!survival && golfConfig .items .creative .checkItemCount )) &&
103+ this .count > this .getMaxCount ()) {
101104
102- if (
103- (
104- (survival && golfConfig .items .survival .checkItemCount ) ||
105- (!survival && golfConfig .items .creative .checkItemCount )
106- ) &&
107- this .count > this .getMaxCount ()
108- ) {
109- this .count = 1 ;
105+ this .count = this .getMaxCount ();
110106 }
111107 }
112108}
0 commit comments