User Tools

Site Tools


tutorial:adding_to_loot_tables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tutorial:adding_to_loot_tables [2019/08/12 23:06]
yanis48 fixed parenthesis
tutorial:adding_to_loot_tables [2019/08/13 06:46] (current)
liach No magic constants man!
Line 12: Line 12:
  
 <code java> <code java>
 +// No magic constants!
 +private static final Identifier COAL_ORE_LOOT_TABLE_ID = new Identifier("​minecraft",​ "​blocks/​coal_ore"​);​
 +
 +// Actual code
 +
 LootTableLoadingCallback.EVENT.register((resourceManager,​ lootManager,​ id, supplier, setter) -> { LootTableLoadingCallback.EVENT.register((resourceManager,​ lootManager,​ id, supplier, setter) -> {
-    if ("​minecraft:​blocks/​coal_ore"​.equals(id.toString())) {+    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {
         // Our code will go here         // Our code will go here
     }     }
Line 27: Line 32:
 <code java> <code java>
 LootTableLoadingCallback.EVENT.register((resourceManager,​ lootManager,​ id, supplier, setter) -> { LootTableLoadingCallback.EVENT.register((resourceManager,​ lootManager,​ id, supplier, setter) -> {
-    if ("​minecraft:​blocks/​coal_ore"​.equals(id.toString())) {+    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {
         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
                 .withRolls(ConstantLootTableRange.create(1));​ // Same as "​rolls":​ 1 in the loot table json                 .withRolls(ConstantLootTableRange.create(1));​ // Same as "​rolls":​ 1 in the loot table json
Line 39: Line 44:
 <code java> <code java>
 LootTableLoadingCallback.EVENT.register((resourceManager,​ lootManager,​ id, supplier, setter) -> { LootTableLoadingCallback.EVENT.register((resourceManager,​ lootManager,​ id, supplier, setter) -> {
-    if ("​minecraft:​blocks/​coal_ore"​.equals(id.toString())) {+    if (COAL_ORE_LOOT_TABLE_ID.equals(id)) {
         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()         FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
                 .withRolls(ConstantLootTableRange.create(1))                 .withRolls(ConstantLootTableRange.create(1))
tutorial/adding_to_loot_tables.txt ยท Last modified: 2019/08/13 06:46 by liach