2020-01-29 00:40:28 +01:00
|
|
|
package de.ellpeck.naturesaura.data;
|
2020-01-23 16:05:52 +01:00
|
|
|
|
2020-02-25 15:14:56 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.BlockFlowerPot;
|
2020-01-24 17:05:41 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.BlockGoldenLeaves;
|
|
|
|
import de.ellpeck.naturesaura.blocks.ModBlocks;
|
2020-01-23 16:05:52 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.Slab;
|
2020-01-24 17:05:41 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2020-01-23 16:05:52 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
|
2023-07-24 17:56:29 +02:00
|
|
|
import net.minecraft.data.loot.BlockLootSubProvider;
|
|
|
|
import net.minecraft.world.flag.FeatureFlags;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.world.item.Items;
|
|
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.minecraft.world.level.block.Blocks;
|
|
|
|
import net.minecraft.world.level.storage.loot.LootPool;
|
|
|
|
import net.minecraft.world.level.storage.loot.LootTable;
|
|
|
|
import net.minecraft.world.level.storage.loot.entries.LootItem;
|
|
|
|
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
|
|
|
|
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
|
|
|
|
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
|
|
|
|
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
|
|
|
|
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
|
2020-01-23 16:05:52 +01:00
|
|
|
|
2023-07-24 17:56:29 +02:00
|
|
|
import java.util.Set;
|
2020-01-23 16:05:52 +01:00
|
|
|
|
2023-07-24 17:56:29 +02:00
|
|
|
public class BlockLootProvider extends BlockLootSubProvider {
|
2021-12-15 16:24:53 +01:00
|
|
|
|
2023-07-24 17:56:29 +02:00
|
|
|
public BlockLootProvider() {
|
|
|
|
super(Set.of(), FeatureFlags.REGISTRY.allFlags());
|
|
|
|
}
|
2020-01-23 16:05:52 +01:00
|
|
|
|
2023-07-24 17:56:29 +02:00
|
|
|
@Override
|
|
|
|
protected void generate() {
|
2021-12-15 16:30:22 +01:00
|
|
|
for (var item : ModRegistry.ALL_ITEMS) {
|
2021-12-15 16:24:53 +01:00
|
|
|
if (!(item instanceof Block block))
|
2020-01-23 16:05:52 +01:00
|
|
|
continue;
|
|
|
|
if (block instanceof Slab) {
|
2023-07-24 17:56:29 +02:00
|
|
|
this.add(block, this::createSlabItemTable);
|
2020-02-25 15:14:56 +01:00
|
|
|
} else if (block instanceof BlockFlowerPot) {
|
2023-07-24 17:56:29 +02:00
|
|
|
this.add(block, this::createPotFlowerItemTable);
|
2020-01-23 16:05:52 +01:00
|
|
|
} else {
|
2023-07-24 17:56:29 +02:00
|
|
|
this.dropSelf(block);
|
2020-01-23 16:05:52 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-24 17:05:41 +01:00
|
|
|
|
2023-07-24 17:56:29 +02:00
|
|
|
this.add(ModBlocks.ANCIENT_LEAVES, BlockLootProvider::createSilkTouchOnlyTable);
|
|
|
|
this.add(ModBlocks.DECAYED_LEAVES, BlockLootProvider::createSilkTouchOnlyTable);
|
|
|
|
this.add(ModBlocks.GOLDEN_LEAVES, b -> LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).add(this.applyExplosionCondition(b, LootItem.lootTableItem(ModItems.GOLD_LEAF)).when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(b).setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(BlockGoldenLeaves.STAGE, BlockGoldenLeaves.HIGHEST_STAGE)))).when(LootItemRandomChanceCondition.randomChance(0.75F))));
|
|
|
|
this.add(ModBlocks.NETHER_WART_MUSHROOM, b -> BlockLootSubProvider.createSilkTouchDispatchTable(b, LootItem.lootTableItem(Items.NETHER_WART).apply(SetItemCountFunction.setCount(UniformGenerator.between(1, 2)))));
|
|
|
|
this.add(ModBlocks.NETHER_GRASS, b -> BlockLootSubProvider.createSilkTouchDispatchTable(b, LootItem.lootTableItem(Blocks.NETHERRACK)));
|
2020-02-07 15:22:30 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 16:05:52 +01:00
|
|
|
@Override
|
2023-07-24 17:56:29 +02:00
|
|
|
protected Iterable<Block> getKnownBlocks() {
|
|
|
|
return ModRegistry.ALL_ITEMS.stream().filter(i -> i instanceof Block).map(i -> (Block) i).toList();
|
2020-01-24 17:05:41 +01:00
|
|
|
}
|
2023-07-24 17:56:29 +02:00
|
|
|
}
|