-
Notifications
You must be signed in to change notification settings - Fork 18
/
InspirationsBlockLootTable.java
166 lines (143 loc) · 6.63 KB
/
InspirationsBlockLootTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package knightminer.inspirations.common.datagen;
import knightminer.inspirations.Inspirations;
import knightminer.inspirations.building.InspirationsBuilding;
import knightminer.inspirations.building.block.RopeBlock;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.data.FillTexturedBlockLootFunction;
import knightminer.inspirations.recipes.InspirationsRecipes;
import knightminer.inspirations.tools.InspirationsTools;
import knightminer.inspirations.tweaks.InspirationsTweaks;
import knightminer.inspirations.utility.InspirationsUtility;
import net.minecraft.block.Block;
import net.minecraft.data.loot.BlockLootTables;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.world.storage.loot.ConstantRange;
import net.minecraft.world.storage.loot.ItemLootEntry;
import net.minecraft.world.storage.loot.LootPool;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.TableLootEntry;
import net.minecraft.world.storage.loot.conditions.BlockStateProperty;
import net.minecraft.world.storage.loot.functions.CopyName;
import net.minecraft.world.storage.loot.functions.SetCount;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nonnull;
import java.util.stream.Collectors;
public class InspirationsBlockLootTable extends BlockLootTables {
// We only care about our blocks.
@Nonnull
@Override
protected Iterable<Block> getKnownBlocks() {
return ForgeRegistries.BLOCKS.getValues().stream()
.filter((block) -> block.getRegistryName().getNamespace().equals(Inspirations.modID))
.collect(Collectors.toList());
}
@Override
protected void addTables() {
addIf(InspirationsBuilding.pulseID, this::addBuilding);
addIf(InspirationsTools.pulseID, this::addTools);
addIf(InspirationsTweaks.pulseID, this::addTweaks);
addIf(InspirationsRecipes.pulseID, this::addRecipes);
addIf(InspirationsUtility.pulseID, this::addUtility);
}
private void addIf(String pulseID, Runnable registrar) {
if (Inspirations.pulseManager.isPulseLoaded(pulseID)) {
registrar.run();
}
}
private static LootTable.Builder droppingWithNameAndTexture(Block block) {
return LootTable.builder()
.addLootPool(withSurvivesExplosion(block, LootPool.builder()
.addEntry(ItemLootEntry.builder(block)
.acceptFunction(CopyName.builder(CopyName.Source.BLOCK_ENTITY))
.acceptFunction(FillTexturedBlockLootFunction::new)
)));
}
private void registerRedirect(Block block, Block originalBlock) {
this.registerLootTable(block, LootTable.builder()
.addLootPool(LootPool.builder()
.addEntry(TableLootEntry.builder(originalBlock.getLootTable()))
));
}
private void addBuilding() {
this.registerLootTable(InspirationsBuilding.shelf_normal, InspirationsBlockLootTable::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.shelf_rainbow, InspirationsBlockLootTable::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.shelf_ancient, InspirationsBlockLootTable::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.shelf_tomes, InspirationsBlockLootTable::droppingWithNameAndTexture);
this.registerDropSelfLootTable(InspirationsBuilding.plainMulch);
this.registerDropSelfLootTable(InspirationsBuilding.blackMulch);
this.registerDropSelfLootTable(InspirationsBuilding.blueMulch);
this.registerDropSelfLootTable(InspirationsBuilding.brownMulch);
this.registerDropSelfLootTable(InspirationsBuilding.redMulch);
this.registerSilkTouch(InspirationsBuilding.glassDoor);
this.registerSilkTouch(InspirationsBuilding.glassTrapdoor);
this.registerDropSelfLootTable(InspirationsBuilding.flower_rose);
this.registerDropSelfLootTable(InspirationsBuilding.flower_cyan);
this.registerDropSelfLootTable(InspirationsBuilding.flower_paeonia);
this.registerDropSelfLootTable(InspirationsBuilding.flower_syringa);
this.registerDropSelfLootTable(InspirationsBuilding.path_brick);
this.registerDropSelfLootTable(InspirationsBuilding.path_rock);
this.registerDropSelfLootTable(InspirationsBuilding.path_round);
this.registerDropSelfLootTable(InspirationsBuilding.path_tile);
this.registerLootTable(InspirationsBuilding.rope, this::rope);
this.registerLootTable(InspirationsBuilding.chain, this::rope);
this.registerLootTable(InspirationsBuilding.vine, this::rope);
}
private LootTable.Builder rope(Block block) {
RopeBlock rope = (RopeBlock) block;
return LootTable.builder()
// The rope block itself
.addLootPool(withSurvivesExplosion(block, LootPool.builder()
.addEntry(ItemLootEntry.builder(block))
))
// And, if rungs are present the items for those.
.addLootPool(withSurvivesExplosion(block, LootPool.builder()
.addEntry(ItemLootEntry.builder(rope.getRungsItem())
.acceptFunction(SetCount.builder(ConstantRange.of(RopeBlock.RUNG_ITEM_COUNT)))
)
.acceptCondition(BlockStateProperty.builder(rope)
.with(RopeBlock.RUNGS, RopeBlock.Rungs.NONE)
.inverted()
)
));
}
private void addTools() {
// func_218482 = droppingNothing()
this.registerLootTable(InspirationsTools.redstoneCharge, func_218482_a());
}
private void addTweaks() {
if (Config.enableFittedCarpets.get()) {
for(DyeColor color : DyeColor.values()) {
this.registerRedirect(
InspirationsTweaks.fitCarpets[color.getId()],
InspirationsTweaks.flatCarpets[color.getId()]
);
}
}
// this.registerDropping(InspirationsTweaks.sugarCaneCrop, InspirationsTweaks.sugarCaneSeeds);
// this.registerDropping(InspirationsTweaks.cactusCrop, InspirationsTweaks.cactusSeeds);
}
private void addRecipes() {
}
private void addUtility() {
for(DyeColor color : DyeColor.values()) {
this.registerDropSelfLootTable(InspirationsUtility.carpetedTrapdoors[color.getId()]);
Block trapdoor = InspirationsUtility.carpetedPressurePlates[color.getId()];
// We don't use these values.
Item carpet = trapdoor.getPickBlock(null, null, null, null, null).getItem();
this.registerLootTable(trapdoor, LootTable.builder()
.addLootPool(withExplosionDecay(trapdoor, LootPool.builder()
.addEntry(ItemLootEntry.builder(Items.STONE_PRESSURE_PLATE))
))
.addLootPool(withExplosionDecay(carpet, LootPool.builder()
.addEntry(ItemLootEntry.builder(carpet))
))
);
}
this.registerDropSelfLootTable(InspirationsUtility.pipe);
this.registerDropSelfLootTable(InspirationsUtility.collector);
this.registerDropping(InspirationsUtility.torchLeverFloor, InspirationsUtility.torchLeverItem);
this.registerDropping(InspirationsUtility.torchLeverWall, InspirationsUtility.torchLeverItem);
}
}