/
InspirationsBlockLootTable.java
199 lines (173 loc) · 8.12 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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 knightminer.inspirations.utility.block.CarpetedPressurePlateBlock;
import net.minecraft.block.Block;
import net.minecraft.block.DoorBlock;
import net.minecraft.data.loot.BlockLootTables;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Items;
import net.minecraft.state.properties.DoubleBlockHalf;
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) -> {
String ns = block.getRegistryName().getNamespace();
return ns.equals(Inspirations.modID) || ns.equals("minecraft");
})
.collect(Collectors.toList());
}
@Override
protected void addTables() {
super.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 void addBuilding() {
this.registerLootTable(InspirationsBuilding.shelf_normal, this::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.shelf_rainbow, this::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.shelf_ancient, this::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.shelf_tomes, this::droppingWithNameAndTexture);
this.registerLootTable(InspirationsBuilding.whiteEnlightenedBush, this::enlightenedBush);
this.registerLootTable(InspirationsBuilding.redEnlightenedBush, this::enlightenedBush);
this.registerLootTable(InspirationsBuilding.greenEnlightenedBush, this::enlightenedBush);
this.registerLootTable(InspirationsBuilding.blueEnlightenedBush, this::enlightenedBush);
this.registerDropSelfLootTable(InspirationsBuilding.plainMulch);
this.registerDropSelfLootTable(InspirationsBuilding.blackMulch);
this.registerDropSelfLootTable(InspirationsBuilding.blueMulch);
this.registerDropSelfLootTable(InspirationsBuilding.brownMulch);
this.registerDropSelfLootTable(InspirationsBuilding.redMulch);
this.registerSilkTouch(InspirationsBuilding.glassTrapdoor);
// For glass doors, they need to only drop from one of the blocks so it doesn't dupe.
this.registerLootTable(InspirationsBuilding.glassDoor, LootTable.builder()
.addLootPool(LootPool.builder().addEntry(ItemLootEntry.builder(InspirationsBuilding.glassDoor))
.acceptCondition(BlockStateProperty.builder(InspirationsBuilding.glassDoor)
.with(DoorBlock.HALF, DoubleBlockHalf.LOWER))
.acceptCondition(SILK_TOUCH)
)
);
this.registerDropSelfLootTable(InspirationsBuilding.flower_rose);
this.registerDropSelfLootTable(InspirationsBuilding.flower_cyan);
this.registerDropSelfLootTable(InspirationsBuilding.flower_paeonia);
this.registerDropSelfLootTable(InspirationsBuilding.flower_syringa);
this.registerFlowerPot(InspirationsBuilding.potted_rose);
this.registerFlowerPot(InspirationsBuilding.potted_cyan);
this.registerFlowerPot(InspirationsBuilding.potted_paeonia);
this.registerFlowerPot(InspirationsBuilding.potted_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 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.registerLootTable(InspirationsTweaks.wetHopper, droppingWithName(InspirationsTweaks.dryHopper));
this.registerDropping(InspirationsTweaks.sugarCane, InspirationsTweaks.sugarCaneSeeds);
this.registerDropping(InspirationsTweaks.cactus, InspirationsTweaks.cactusSeeds);
}
private void addRecipes() {
}
private void addUtility() {
for(DyeColor color : DyeColor.values()) {
this.registerDropSelfLootTable(InspirationsUtility.carpetedTrapdoors[color.getId()]);
CarpetedPressurePlateBlock pressurePlate = InspirationsUtility.carpetedPressurePlates[color.getId()];
this.registerLootTable(pressurePlate, LootTable.builder()
.addLootPool(withSurvivesExplosion(pressurePlate, LootPool.builder()
.addEntry(ItemLootEntry.builder(pressurePlate.getCarpet()))
))
.addLootPool(withSurvivesExplosion(pressurePlate, LootPool.builder()
.addEntry(ItemLootEntry.builder(Items.STONE_PRESSURE_PLATE))
))
);
}
this.registerDropSelfLootTable(InspirationsUtility.pipe);
this.registerDropSelfLootTable(InspirationsUtility.collector);
this.registerDropping(InspirationsUtility.torchLeverFloor, InspirationsUtility.torchLeverItem);
this.registerDropping(InspirationsUtility.torchLeverWall, InspirationsUtility.torchLeverItem);
}
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(withExplosionDecay(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 LootTable.Builder enlightenedBush(Block bush) {
return LootTable.builder()
// No explosion check, since that's not going to pass a
// tool check.
.addLootPool(LootPool.builder()
.addEntry(ItemLootEntry.builder(bush)
.acceptFunction(FillTexturedBlockLootFunction::new))
.acceptCondition(SILK_TOUCH_OR_SHEARS)
);
}
private 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()))
));
}
}