@@ -771,38 +771,41 @@ private void showLoot(FeatureWidget widget) {
771771 MemorySegment lootTableInternal = Piece .lootTable (piece );
772772 String lootTable = lootTableInternal .getString (0 );
773773 MemorySegment lootTableContext = LootTableContext .allocate (tempArena );
774- if (Cubiomes .init_loot_table_name (lootTableContext , lootTableInternal , this .version ) == 0 ) {
775- continue ;
776- }
777- MemorySegment chestPoses = Piece .chestPoses (piece );
778- MemorySegment lootSeeds = Piece .lootSeeds (piece );
779- for (int chestIdx = 0 ; chestIdx < chestCount ; chestIdx ++) {
780- MemorySegment chestPosInternal = Pos .asSlice (chestPoses , chestIdx );
781- BlockPos chestPos = new BlockPos (Pos .x (chestPosInternal ), 0 , Pos .z (chestPosInternal ));
782- long lootSeed = lootSeeds .getAtIndex (Cubiomes .C_LONG_LONG , chestIdx );
783- Cubiomes .set_loot_seed (lootTableContext , lootSeed );
784- Cubiomes .generate_loot (lootTableContext );
785- int lootCount = LootTableContext .generated_item_count (lootTableContext );
786- SimpleContainer container = new SimpleContainer (3 * 9 );
787- for (int lootIdx = 0 ; lootIdx < lootCount ; lootIdx ++) {
788- MemorySegment itemStackInternal = ItemStack .asSlice (LootTableContext .generated_items (lootTableContext ), lootIdx );
789- int itemId = Cubiomes .get_global_item_id (lootTableContext , ItemStack .item (itemStackInternal ));
790- Item item = ItemAndEnchantmentsPredicateArgument .ITEM_ID_TO_MC .get (itemId );
791- net .minecraft .world .item .ItemStack itemStack = new net .minecraft .world .item .ItemStack (item , ItemStack .count (itemStackInternal ));
792- MemorySegment enchantments = ItemStack .enchantments (itemStackInternal );
793- int enchantmentCount = ItemStack .enchantment_count (itemStackInternal );
794- for (int enchantmentIdx = 0 ; enchantmentIdx < enchantmentCount ; enchantmentIdx ++) {
795- MemorySegment enchantInstance = EnchantInstance .asSlice (enchantments , enchantmentIdx );
796- int itemEnchantment = EnchantInstance .enchantment (enchantInstance );
797- ResourceKey <Enchantment > enchantmentResourceKey = ItemAndEnchantmentsPredicateArgument .ENCHANTMENT_ID_TO_MC .get (itemEnchantment );
798- Holder .Reference <Enchantment > enchantmentReference = this .enchantmentsRegistry .getOrThrow (enchantmentResourceKey );
799- itemStack .enchant (enchantmentReference , EnchantInstance .level (enchantInstance ));
774+ try {
775+ if (Cubiomes .init_loot_table_name (lootTableContext , lootTableInternal , this .version ) == 0 ) {
776+ continue ;
777+ }
778+ MemorySegment chestPoses = Piece .chestPoses (piece );
779+ MemorySegment lootSeeds = Piece .lootSeeds (piece );
780+ for (int chestIdx = 0 ; chestIdx < chestCount ; chestIdx ++) {
781+ MemorySegment chestPosInternal = Pos .asSlice (chestPoses , chestIdx );
782+ BlockPos chestPos = new BlockPos (Pos .x (chestPosInternal ), 0 , Pos .z (chestPosInternal ));
783+ long lootSeed = lootSeeds .getAtIndex (Cubiomes .C_LONG_LONG , chestIdx );
784+ Cubiomes .set_loot_seed (lootTableContext , lootSeed );
785+ Cubiomes .generate_loot (lootTableContext );
786+ int lootCount = LootTableContext .generated_item_count (lootTableContext );
787+ SimpleContainer container = new SimpleContainer (3 * 9 );
788+ for (int lootIdx = 0 ; lootIdx < lootCount ; lootIdx ++) {
789+ MemorySegment itemStackInternal = ItemStack .asSlice (LootTableContext .generated_items (lootTableContext ), lootIdx );
790+ int itemId = Cubiomes .get_global_item_id (lootTableContext , ItemStack .item (itemStackInternal ));
791+ Item item = ItemAndEnchantmentsPredicateArgument .ITEM_ID_TO_MC .get (itemId );
792+ net .minecraft .world .item .ItemStack itemStack = new net .minecraft .world .item .ItemStack (item , ItemStack .count (itemStackInternal ));
793+ MemorySegment enchantments = ItemStack .enchantments (itemStackInternal );
794+ int enchantmentCount = ItemStack .enchantment_count (itemStackInternal );
795+ for (int enchantmentIdx = 0 ; enchantmentIdx < enchantmentCount ; enchantmentIdx ++) {
796+ MemorySegment enchantInstance = EnchantInstance .asSlice (enchantments , enchantmentIdx );
797+ int itemEnchantment = EnchantInstance .enchantment (enchantInstance );
798+ ResourceKey <Enchantment > enchantmentResourceKey = ItemAndEnchantmentsPredicateArgument .ENCHANTMENT_ID_TO_MC .get (itemEnchantment );
799+ Holder .Reference <Enchantment > enchantmentReference = this .enchantmentsRegistry .getOrThrow (enchantmentResourceKey );
800+ itemStack .enchant (enchantmentReference , EnchantInstance .level (enchantInstance ));
801+ }
802+ container .addItem (itemStack );
800803 }
801- container . addItem ( itemStack );
804+ chestLootDataList . add ( new ChestLootData ( structure , pieceName , chestPos , lootSeed , lootTable , container ) );
802805 }
803- chestLootDataList .add (new ChestLootData (structure , pieceName , chestPos , lootSeed , lootTable , container ));
806+ } finally {
807+ Cubiomes .free_loot_table_pools (lootTableContext );
804808 }
805- Cubiomes .free_loot_table_pools (lootTableContext );
806809 }
807810 if (!chestLootDataList .isEmpty ()) {
808811 this .chestLootWidget = new ChestLootWidget (widget .x + widget .width () / 2 , widget .y + widget .height () / 2 , chestLootDataList );
0 commit comments