experiments with loot table changes
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				build / build (21) (push) Waiting to run
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	build / build (21) (push) Waiting to run
				
			This commit is contained in:
		| @@ -13,9 +13,18 @@ import de.jottyfan.quickiemod.item.ModItems; | ||||
| import de.jottyfan.quickiemod.itemgroup.ModItemGroup; | ||||
| import net.fabricmc.api.ModInitializer; | ||||
| import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; | ||||
| import net.fabricmc.fabric.api.loot.v3.LootTableEvents; | ||||
| import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; | ||||
| import net.minecraft.block.Block; | ||||
| import net.minecraft.block.Blocks; | ||||
| import net.minecraft.item.Item; | ||||
| import net.minecraft.loot.LootPool; | ||||
| import net.minecraft.loot.LootTable; | ||||
| import net.minecraft.loot.condition.SurvivesExplosionLootCondition; | ||||
| import net.minecraft.loot.entry.ItemEntry; | ||||
| import net.minecraft.loot.entry.LeafEntry.Builder; | ||||
| import net.minecraft.registry.Registry; | ||||
| import net.minecraft.registry.RegistryKey; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -26,12 +35,29 @@ public class Quickiemod implements ModInitializer { | ||||
| 	public static final String MOD_ID = "quickiemod"; | ||||
| 	public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||||
|  | ||||
|   private void registerComposterItems() { | ||||
|   	CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_COTTONSEED, 0.5f); | ||||
| 	private void registerComposterItems() { | ||||
| 		CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_COTTONSEED, 0.5f); | ||||
| 		CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_COTTON, 0.75f); | ||||
| 		CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_CANOLASEED, 0.5f); | ||||
| 		CompostingChanceRegistry.INSTANCE.add(ModItems.ITEM_CANOLA, 0.75f); | ||||
|   } | ||||
| 	} | ||||
|  | ||||
| 	private void registerLootTableChanges() { | ||||
| 		// does not work yet | ||||
| 		LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> { | ||||
| 			if (Blocks.SHORT_GRASS.equals(key)) { | ||||
| 				Builder<?> entry = ItemEntry.builder(ModItems.ITEM_COTTON); | ||||
| 				LootPool.Builder poolBuilder = LootPool.builder().with(entry) | ||||
| 						.conditionally(SurvivesExplosionLootCondition.builder()); | ||||
| 				tableBuilder.pool(poolBuilder); | ||||
| 			} else if (Blocks.TALL_GRASS.getLootTableKey().equals(key)) { | ||||
| 				Builder<?> entry = ItemEntry.builder(ModItems.ITEM_CANOLA); | ||||
| 				LootPool.Builder poolBuilder = LootPool.builder().with(entry) | ||||
| 						.conditionally(SurvivesExplosionLootCondition.builder()); | ||||
| 				tableBuilder.pool(poolBuilder); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void onInitialize() { | ||||
| @@ -40,8 +66,8 @@ public class Quickiemod implements ModInitializer { | ||||
| 		List<Block> blocks = ModBlocks.registerModBlocks(); | ||||
| 		ModFeatures.registerFeatures(); | ||||
| 		registerComposterItems(); | ||||
| 		registerLootTableChanges(); | ||||
| 		ModItemGroup.registerItemGroup(items, blocks); | ||||
|  | ||||
| 		PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> { | ||||
| 			Block oldBlock = state.getBlock(); | ||||
| 			new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user