-
Notifications
You must be signed in to change notification settings - Fork 754
/
BlockLootTableProvider.java
409 lines (364 loc) · 19.8 KB
/
BlockLootTableProvider.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
package slimeknights.tconstruct.common.data.loot;
import net.minecraft.advancements.critereon.EnchantmentPredicate;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.core.Registry;
import net.minecraft.data.loot.BlockLoot;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.MangrovePropaguleBlock;
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.entries.LootPoolEntryContainer;
import net.minecraft.world.level.storage.loot.functions.ApplyBonusCount;
import net.minecraft.world.level.storage.loot.functions.CopyNameFunction;
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.predicates.BonusLevelTableCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
import net.minecraftforge.common.ToolActions;
import net.minecraftforge.common.loot.CanToolPerformAction;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.loot.function.RetexturedLootFunction;
import slimeknights.mantle.registration.object.BuildingBlockObject;
import slimeknights.mantle.registration.object.FenceBuildingBlockObject;
import slimeknights.mantle.registration.object.WallBuildingBlockObject;
import slimeknights.mantle.registration.object.WoodBlockObject;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.registration.GeodeItemObject;
import slimeknights.tconstruct.common.registration.GeodeItemObject.BudSize;
import slimeknights.tconstruct.gadgets.TinkerGadgets;
import slimeknights.tconstruct.library.utils.NBTTags;
import slimeknights.tconstruct.shared.TinkerCommons;
import slimeknights.tconstruct.shared.TinkerMaterials;
import slimeknights.tconstruct.shared.block.ClearStainedGlassBlock;
import slimeknights.tconstruct.shared.block.SlimeType;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;
import slimeknights.tconstruct.tables.TinkerTables;
import slimeknights.tconstruct.tables.block.entity.chest.TinkersChestBlockEntity;
import slimeknights.tconstruct.tools.TinkerModifiers;
import slimeknights.tconstruct.world.TinkerWorld;
import slimeknights.tconstruct.world.block.DirtType;
import slimeknights.tconstruct.world.block.FoliageType;
import javax.annotation.Nonnull;
import java.util.function.Function;
import java.util.stream.Collectors;
public class BlockLootTableProvider extends BlockLoot {
@Nonnull
@Override
protected Iterable<Block> getKnownBlocks() {
return ForgeRegistries.BLOCKS.getValues().stream()
.filter((block) -> TConstruct.MOD_ID.equals(Registry.BLOCK.getKey(block).getNamespace()))
.collect(Collectors.toList());
}
@Override
protected void addTables() {
this.addCommon();
this.addDecorative();
this.addGadgets();
this.addWorld();
this.addTools();
this.addSmeltery();
this.addFoundry();
}
private void addCommon() {
this.registerFenceBuildingLootTables(TinkerMaterials.blazewood);
this.registerFenceBuildingLootTables(TinkerMaterials.nahuatl);
this.dropSelf(TinkerCommons.cheeseBlock.get());
this.dropSelf(TinkerModifiers.silkyJewelBlock.get());
this.dropSelf(TinkerCommons.goldBars.get());
this.dropSelf(TinkerCommons.goldPlatform.get());
this.dropSelf(TinkerCommons.ironPlatform.get());
this.dropSelf(TinkerCommons.cobaltPlatform.get());
TinkerCommons.copperPlatform.forEach(this::dropSelf);
TinkerCommons.waxedCopperPlatform.forEach(this::dropSelf);
// ores
this.dropSelf(TinkerMaterials.cobalt.get());
// tier 3
this.dropSelf(TinkerMaterials.slimesteel.get());
this.dropSelf(TinkerMaterials.amethystBronze.get());
this.dropSelf(TinkerMaterials.roseGold.get());
this.dropSelf(TinkerMaterials.pigIron.get());
// tier 4
this.dropSelf(TinkerMaterials.manyullyn.get());
this.dropSelf(TinkerMaterials.hepatizon.get());
this.dropSelf(TinkerMaterials.queensSlime.get());
this.dropSelf(TinkerMaterials.soulsteel.get());
// tier 5
this.dropSelf(TinkerMaterials.knightslime.get());
}
private void addDecorative() {
this.dropSelf(TinkerCommons.obsidianPane.get());
this.dropSelf(TinkerCommons.clearGlass.get());
this.dropSelf(TinkerCommons.clearTintedGlass.get());
this.dropSelf(TinkerCommons.clearGlassPane.get());
for (ClearStainedGlassBlock.GlassColor color : ClearStainedGlassBlock.GlassColor.values()) {
this.dropSelf(TinkerCommons.clearStainedGlass.get(color));
this.dropSelf(TinkerCommons.clearStainedGlassPane.get(color));
}
this.dropSelf(TinkerCommons.soulGlass.get());
this.dropSelf(TinkerCommons.soulGlassPane.get());
}
private void addTools() {
// chests
// tinker chest - name and color
this.add(TinkerTables.tinkersChest.get(), block -> droppingWithFunctions(block, builder ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy(TinkersChestBlockEntity.TAG_CHEST_COLOR, "display.color"))));
// part chest - just name
this.add(TinkerTables.partChest.get(), block ->
droppingWithFunctions(block, builder ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))));
// cast chest - name and inventory
this.add(TinkerTables.castChest.get(), block -> droppingWithFunctions(block, builder ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Items", "TinkerData.Items"))));
// tables with legs
this.dropTable(TinkerTables.craftingStation.get());
this.dropTable(TinkerTables.partBuilder.get());
this.dropTable(TinkerTables.tinkerStation.get());
this.dropTable(TinkerTables.tinkersAnvil.get());
this.dropTable(TinkerTables.modifierWorktable.get());
this.dropTable(TinkerTables.scorchedAnvil.get());
}
private void addWorld() {
this.add(TinkerWorld.cobaltOre.get(), block -> createOreDrop(block, TinkerWorld.rawCobalt.asItem()));
this.dropSelf(TinkerWorld.rawCobaltBlock.get());
TinkerWorld.heads.forEach(this::dropSelf);
// slime blocks
TinkerWorld.slime.forEach((type, block) -> {
if (type != SlimeType.EARTH) {
this.dropSelf(block);
}
});
TinkerWorld.congealedSlime.forEach((slime, block) -> this.add(block, createSingleItemTableWithSilkTouch(block, TinkerCommons.slimeball.get(slime), ConstantValue.exactly(4))));
// slime dirt and grass
TinkerWorld.slimeDirt.forEach(this::dropSelf);
TinkerWorld.vanillaSlimeGrass.forEach(block -> this.add(block, createSingleItemTableWithSilkTouch(block, Blocks.DIRT)));
TinkerWorld.earthSlimeGrass.forEach(block -> this.add(block, createSingleItemTableWithSilkTouch(block, TinkerWorld.slimeDirt.get(DirtType.EARTH))));
TinkerWorld.skySlimeGrass.forEach(block -> this.add(block, createSingleItemTableWithSilkTouch(block, TinkerWorld.slimeDirt.get(DirtType.SKY))));
TinkerWorld.enderSlimeGrass.forEach(block -> this.add(block, createSingleItemTableWithSilkTouch(block, TinkerWorld.slimeDirt.get(DirtType.ENDER))));
TinkerWorld.ichorSlimeGrass.forEach(block -> this.add(block, createSingleItemTableWithSilkTouch(block, TinkerWorld.slimeDirt.get(DirtType.ICHOR))));
// saplings
TinkerWorld.slimeSapling.forEach((type, block) -> {
if (type != FoliageType.ENDER) {
this.dropSelf(block);
}
});
this.add(TinkerWorld.slimeSapling.get(FoliageType.ENDER), sapling -> applyExplosionDecay(
sapling, LootTable.lootTable().withPool(LootPool.lootPool()
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(sapling).setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(MangrovePropaguleBlock.AGE, 4)))
.add(LootItem.lootTableItem(sapling)))));
TinkerWorld.pottedSlimeSapling.forEach(this::dropPottedContents);
TinkerWorld.pottedSlimeFern.forEach(this::dropPottedContents);
// foliage
TinkerWorld.slimeTallGrass.forEach(block -> this.add(block, BlockLootTableProvider::onlyShears));
for (FoliageType type : FoliageType.OVERWORLD) {
// overworld leaves, drops with leaves and slimeballs
this.add(TinkerWorld.slimeLeaves.get(type), block -> randomDropSlimeBallOrSapling(type, block, TinkerWorld.slimeSapling.get(type), NORMAL_LEAVES_SAPLING_CHANCES));
this.add(TinkerWorld.slimeFern.get(type), BlockLootTableProvider::onlyShears);
}
for (FoliageType type : FoliageType.NETHER) {
// nether leaves drop self
this.dropSelf(TinkerWorld.slimeLeaves.get(type));
this.dropSelf(TinkerWorld.slimeFern.get(type));
}
// mangrove leaves do not drop saplings, they just drop sticks. We do slimeballs instead
this.add(TinkerWorld.slimeLeaves.get(FoliageType.ENDER), leaves -> createSelfDropDispatchTable(leaves, SILK_TOUCH_OR_SHEARS,
applyExplosionDecay(leaves, LootItem.lootTableItem(TinkerCommons.slimeball.get(SlimeType.ENDER)).apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F))))
.when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES))));
this.add(TinkerWorld.slimeFern.get(FoliageType.ENDER), BlockLootTableProvider::onlyShears);
// vines
this.add(TinkerWorld.skySlimeVine.get(), BlockLootTableProvider::onlyShears);
this.add(TinkerWorld.enderSlimeVine.get(), BlockLootTableProvider::onlyShears);
// wood
this.registerWoodLootTables(TinkerWorld.greenheart);
this.registerWoodLootTables(TinkerWorld.skyroot);
this.registerWoodLootTables(TinkerWorld.bloodshroom);
this.registerWoodLootTables(TinkerWorld.enderbark);
this.dropSelf(TinkerWorld.enderbarkRoots.get());
TinkerWorld.slimyEnderbarkRoots.forEach(this::dropSelf);
// geode
this.registerGeode(TinkerWorld.earthGeode);
this.registerGeode(TinkerWorld.skyGeode);
this.registerGeode(TinkerWorld.ichorGeode);
this.registerGeode(TinkerWorld.enderGeode);
}
private void addGadgets() {
this.dropSelf(TinkerGadgets.punji.get());
TinkerGadgets.cake.forEach(block -> this.add(block, noDrop()));
this.add(TinkerGadgets.magmaCake.get(), noDrop());
}
private void addSmeltery() {
this.dropSelf(TinkerSmeltery.grout.get());
// controller
this.dropSelf(TinkerSmeltery.searedMelter.get());
this.dropSelf(TinkerSmeltery.searedHeater.get());
this.dropTable(TinkerSmeltery.smelteryController.get());
// smeltery component
this.registerBuildingLootTables(TinkerSmeltery.searedStone);
this.registerWallBuildingLootTables(TinkerSmeltery.searedCobble);
this.registerBuildingLootTables(TinkerSmeltery.searedPaver);
this.registerWallBuildingLootTables(TinkerSmeltery.searedBricks);
this.dropSelf(TinkerSmeltery.searedCrackedBricks.get());
this.dropSelf(TinkerSmeltery.searedFancyBricks.get());
this.dropSelf(TinkerSmeltery.searedTriangleBricks.get());
this.dropSelf(TinkerSmeltery.searedLadder.get());
this.dropSelf(TinkerSmeltery.searedGlass.get());
this.dropSelf(TinkerSmeltery.searedSoulGlass.get());
this.dropSelf(TinkerSmeltery.searedTintedGlass.get());
this.dropSelf(TinkerSmeltery.searedGlassPane.get());
this.dropSelf(TinkerSmeltery.searedSoulGlassPane.get());
this.dropTable(TinkerSmeltery.searedDrain.get());
this.dropTable(TinkerSmeltery.searedChute.get());
this.dropTable(TinkerSmeltery.searedDuct.get());
Function<Block, LootTable.Builder> dropTank = block -> droppingWithFunctions(block, builder ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy(NBTTags.TANK, NBTTags.TANK)));
TinkerSmeltery.searedTank.forEach(block -> this.add(block, dropTank));
this.add(TinkerSmeltery.searedLantern.get(), dropTank);
// fluid
this.dropSelf(TinkerSmeltery.searedFaucet.get());
this.dropSelf(TinkerSmeltery.searedChannel.get());
// casting
this.dropSelf(TinkerSmeltery.searedBasin.get());
this.dropSelf(TinkerSmeltery.searedTable.get());
}
private void addFoundry() {
this.dropSelf(TinkerSmeltery.netherGrout.get());
// controller
this.dropSelf(TinkerSmeltery.scorchedAlloyer.get());
this.dropTable(TinkerSmeltery.foundryController.get());
// smeltery component
this.dropSelf(TinkerSmeltery.scorchedStone.get());
this.dropSelf(TinkerSmeltery.polishedScorchedStone.get());
this.registerFenceBuildingLootTables(TinkerSmeltery.scorchedBricks);
this.dropSelf(TinkerSmeltery.chiseledScorchedBricks.get());
this.registerBuildingLootTables(TinkerSmeltery.scorchedRoad);
this.dropSelf(TinkerSmeltery.scorchedLadder.get());
this.dropSelf(TinkerSmeltery.scorchedGlass.get());
this.dropSelf(TinkerSmeltery.scorchedSoulGlass.get());
this.dropSelf(TinkerSmeltery.scorchedTintedGlass.get());
this.dropSelf(TinkerSmeltery.scorchedGlassPane.get());
this.dropSelf(TinkerSmeltery.scorchedSoulGlassPane.get());
this.dropTable(TinkerSmeltery.scorchedDrain.get());
this.dropTable(TinkerSmeltery.scorchedChute.get());
this.dropTable(TinkerSmeltery.scorchedDuct.get());
Function<Block, LootTable.Builder> dropTank = block -> droppingWithFunctions(block, builder ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy(NBTTags.TANK, NBTTags.TANK)));
TinkerSmeltery.scorchedTank.forEach(block -> this.add(block, dropTank));
this.add(TinkerSmeltery.scorchedLantern.get(), dropTank);
// fluid
this.dropSelf(TinkerSmeltery.scorchedFaucet.get());
this.dropSelf(TinkerSmeltery.scorchedChannel.get());
// casting
this.dropSelf(TinkerSmeltery.scorchedBasin.get());
this.dropSelf(TinkerSmeltery.scorchedTable.get());
}
/*
* Utils
*/
private static final LootItemCondition.Builder SILK_TOUCH = MatchTool.toolMatches(ItemPredicate.Builder.item().hasEnchantment(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.atLeast(1))));
private static final LootItemCondition.Builder SHEARS = CanToolPerformAction.canToolPerformAction(ToolActions.SHEARS_DIG);
private static final LootItemCondition.Builder SILK_TOUCH_OR_SHEARS = SHEARS.or(SILK_TOUCH);
protected static LootTable.Builder onlyShears(ItemLike item) {
return LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(SHEARS).add(LootItem.lootTableItem(item)));
}
private static LootTable.Builder droppingSilkOrShears(Block block, LootPoolEntryContainer.Builder<?> alternativeLootEntry) {
return createSelfDropDispatchTable(block, SILK_TOUCH_OR_SHEARS, alternativeLootEntry);
}
private static LootTable.Builder dropSapling(Block blockIn, Block saplingIn, float... fortuneIn) {
return droppingSilkOrShears(blockIn, applyExplosionCondition(blockIn, LootItem.lootTableItem(saplingIn)).when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, fortuneIn)));
}
private static LootTable.Builder randomDropSlimeBallOrSapling(FoliageType foliageType, Block blockIn, Block sapling, float... fortuneIn) {
LootTable.Builder builder = dropSapling(blockIn, sapling, fortuneIn);
SlimeType slime = foliageType.asSlime();
if (slime != null) {
return builder.withPool(
LootPool.lootPool().setRolls(ConstantValue.exactly(1))
.when(HAS_NO_SHEARS_OR_SILK_TOUCH)
.add(applyExplosionCondition(blockIn, LootItem.lootTableItem(TinkerCommons.slimeball.get(slime)))
.when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, 1 / 50f, 1 / 45f, 1 / 40f, 1 / 30f, 1 / 20f))));
}
return builder;
}
private static LootTable.Builder droppingWithFunctions(Block block, Function<LootItem.Builder<?>,LootItem.Builder<?>> mapping) {
return LootTable.lootTable().withPool(applyExplosionCondition(block, LootPool.lootPool().setRolls(ConstantValue.exactly(1)).add(mapping.apply(LootItem.lootTableItem(block)))));
}
/**
* Registers all loot tables for a building block object
* @param object Object instance
*/
private void registerBuildingLootTables(BuildingBlockObject object) {
this.dropSelf(object.get());
this.add(object.getSlab(), BlockLoot::createSlabItemTable);
this.dropSelf(object.getStairs());
}
/**
* Registers all loot tables for a wall building block object
* @param object Object instance
*/
private void registerWallBuildingLootTables(WallBuildingBlockObject object) {
registerBuildingLootTables(object);
this.dropSelf(object.getWall());
}
/**
* Registers all loot tables for a fence building block object
* @param object Object instance
*/
private void registerFenceBuildingLootTables(FenceBuildingBlockObject object) {
registerBuildingLootTables(object);
this.dropSelf(object.getFence());
}
/** Adds all loot tables relevant to the given wood object */
private void registerWoodLootTables(WoodBlockObject object) {
registerFenceBuildingLootTables(object);
// basic
this.dropSelf(object.getLog());
this.dropSelf(object.getStrippedLog());
this.dropSelf(object.getWood());
this.dropSelf(object.getStrippedWood());
// door
this.dropSelf(object.getFenceGate());
this.add(object.getDoor(), BlockLoot::createDoorTable);
this.dropSelf(object.getTrapdoor());
// redstone
this.dropSelf(object.getPressurePlate());
this.dropSelf(object.getButton());
// sign
this.dropSelf(object.getSign());
}
private static Function<Block, LootTable.Builder> ADD_TABLE = block -> droppingWithFunctions(block, (builder) ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)).apply(RetexturedLootFunction::new));
/** Registers a block that drops with its own texture stored in NBT */
private void dropTable(Block table) {
this.add(table, ADD_TABLE);
}
/** Adds all loot tables relevant to the given geode block set */
private void registerGeode(GeodeItemObject geode) {
this.dropSelf(geode.getBlock());
// cluster
this.add(geode.getBud(BudSize.CLUSTER), block -> createSilkTouchDispatchTable(
block, LootItem.lootTableItem(geode.get())
.apply(SetItemCountFunction.setCount(ConstantValue.exactly(4.0F)))
.apply(ApplyBonusCount.addOreBonusCount(Enchantments.BLOCK_FORTUNE))
.when(MatchTool.toolMatches(ItemPredicate.Builder.item().of(ItemTags.CLUSTER_MAX_HARVESTABLES)))
.otherwise(applyExplosionDecay(block, LootItem.lootTableItem(geode.get()).apply(SetItemCountFunction.setCount(ConstantValue.exactly(2.0F)))))));
// buds
for (BudSize size : BudSize.SIZES) {
this.dropWhenSilkTouch(geode.getBud(size));
}
this.add(geode.getBudding(), noDrop());
}
}