12
12
import org .apache .logging .log4j .LogManager ;
13
13
import org .apache .logging .log4j .Logger ;
14
14
15
+ import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
16
+
15
17
import net .darkhax .bookshelf .command .ArgumentTypeLootTable ;
16
18
import net .darkhax .bookshelf .command .ArgumentTypeMod ;
17
19
import net .darkhax .bookshelf .crafting .block .BlockIngredient ;
32
34
import net .darkhax .bookshelf .crafting .recipes .smithing .SmithingRecipeFont ;
33
35
import net .darkhax .bookshelf .crafting .recipes .smithing .SmithingRecipeRepairCost ;
34
36
import net .darkhax .bookshelf .internal .command .ArgumentTypeHandOutput ;
35
- import net .darkhax .bookshelf .internal .command .BookshelfCommands ;
37
+ import net .darkhax .bookshelf .internal .command .CommandHand ;
38
+ import net .darkhax .bookshelf .internal .command .CommandLootChest ;
39
+ import net .darkhax .bookshelf .internal .command .CommandTranslate ;
36
40
import net .darkhax .bookshelf .loot .condition .CheckBiomeTag ;
37
41
import net .darkhax .bookshelf .loot .condition .CheckDimensionId ;
38
42
import net .darkhax .bookshelf .loot .condition .CheckEnchantability ;
53
57
import net .darkhax .bookshelf .loot .modifier .ModifierSilkTouch ;
54
58
import net .darkhax .bookshelf .registry .RegistryHelper ;
55
59
import net .minecraft .advancements .criterion .ItemPredicate ;
60
+ import net .minecraft .command .CommandSource ;
61
+ import net .minecraft .command .Commands ;
56
62
import net .minecraft .command .arguments .ArgumentSerializer ;
57
63
import net .minecraft .enchantment .EnchantmentType ;
58
64
import net .minecraft .item .AxeItem ;
63
69
import net .minecraft .item .SwordItem ;
64
70
import net .minecraft .loot .LootConditionType ;
65
71
import net .minecraft .util .ResourceLocation ;
72
+ import net .minecraftforge .common .MinecraftForge ;
66
73
import net .minecraftforge .common .ToolType ;
74
+ import net .minecraftforge .event .RegisterCommandsEvent ;
67
75
import net .minecraftforge .fml .common .Mod ;
68
76
import net .minecraftforge .fml .javafmlmod .FMLJavaModLoadingContext ;
69
77
70
78
@ Mod (Bookshelf .MOD_ID )
71
79
public final class Bookshelf {
72
-
80
+
73
81
public static Bookshelf instance ;
74
-
82
+
75
83
// System Constants
76
84
public static final Random RANDOM = new Random ();
77
-
85
+
78
86
public static final String NEW_LINE = System .getProperty ("line.separator" );
79
-
87
+
80
88
// Mod Constants
81
89
public static final String MOD_ID = "bookshelf" ;
82
-
90
+
83
91
public static final String MOD_NAME = "Bookshelf" ;
84
-
92
+
85
93
public static final Logger LOG = LogManager .getLogger (MOD_NAME );
86
-
94
+
87
95
private final RegistryHelper registry = new RegistryHelper (MOD_ID , LOG );
88
-
96
+
89
97
public final LootConditionType conditionIsMob ;
90
98
public final LootConditionType conditionCheckVillage ;
91
99
public final LootConditionType conditionCheckStructure ;
@@ -99,17 +107,17 @@ public final class Bookshelf {
99
107
public final LootConditionType conditionCheckEnchantability ;
100
108
public final LootConditionType conditionCheckBiomeTag ;
101
109
public final LootConditionType conditionCheckDimension ;
102
-
103
- public Bookshelf () {
104
-
110
+
111
+ public Bookshelf () {
112
+
105
113
// Commands
106
- new BookshelfCommands (this . registry );
107
-
114
+ MinecraftForge . EVENT_BUS . addListener (this :: registerCommands );
115
+
108
116
// Command arguments
109
117
this .registry .commands .registerCommandArgument ("enum" , ArgumentTypeHandOutput .class , new ArgumentTypeHandOutput .Serialzier ());
110
118
this .registry .commands .registerCommandArgument ("mod" , ArgumentTypeMod .class , new ArgumentSerializer <>( () -> ArgumentTypeMod .INSTACE ));
111
119
this .registry .commands .registerCommandArgument ("loot" , ArgumentTypeLootTable .class , new ArgumentSerializer <>( () -> ArgumentTypeLootTable .INSTACE ));
112
-
120
+
113
121
// Loot Modifier
114
122
this .registry .lootModifiers .register (ModifierClear .SERIALIZER , "clear" );
115
123
this .registry .lootModifiers .register (ModifierSilkTouch .SERIALIZER , "silk_touch" );
@@ -122,7 +130,7 @@ public Bookshelf () {
122
130
this .registry .lootModifiers .register (ModifierRecipe .STONECUT , "stonecutting" );
123
131
this .registry .lootModifiers .register (ModifierRecipe .SMITHING , "smithing" );
124
132
this .registry .lootModifiers .register (ModifierAddItem .SERIALIZER , "add_item" );
125
-
133
+
126
134
// Loot Conditions
127
135
this .conditionIsMob = this .registry .lootConditions .register (EntityIsMob .SERIALIZER , "is_mob" );
128
136
this .conditionCheckVillage = this .registry .lootConditions .register (CheckVillage .SERIALIZER , "check_village" );
@@ -137,18 +145,18 @@ public Bookshelf () {
137
145
this .conditionCheckEnchantability = this .registry .lootConditions .register (CheckEnchantability .SERIALIZER , "check_enchantability" );
138
146
this .conditionCheckBiomeTag = this .registry .lootConditions .register (CheckBiomeTag .SERIALIZER , "check_biome_tag" );
139
147
this .conditionCheckDimension = this .registry .lootConditions .register (CheckDimensionId .SERIALIZER , "check_dimension" );
140
-
148
+
141
149
// Item Predicates
142
150
ItemPredicate .register (new ResourceLocation ("bookshelf" , "modid" ), ItemPredicateModid ::fromJson );
143
151
ItemPredicate .register (new ResourceLocation ("bookshelf" , "ingredient" ), ItemPredicateIngredient ::fromJson );
144
-
152
+
145
153
// Recipe Serializers
146
154
this .registry .recipeSerializers .register (ShapedRecipeDamaging .SERIALIZER , "crafting_shaped_with_damage" );
147
155
this .registry .recipeSerializers .register (ShapelessRecipeDamage .SERIALIZER , "crafting_shapeless_with_damage" );
148
156
this .registry .recipeSerializers .register (SmithingRecipeFont .SERIALIZER , "smithing_font" );
149
157
this .registry .recipeSerializers .register (SmithingRecipeRepairCost .SERIALIZER , "smithing_repair_cost" );
150
158
this .registry .recipeSerializers .register (SmithingRecipeEnchantment .SERIALIZER , "smithing_enchant" );
151
-
159
+
152
160
// Ingredients
153
161
this .registry .ingredients .register ("potion" , IngredientPotion .SERIALIZER );
154
162
this .registry .ingredients .register ("modid" , IngredientModid .SERIALIZER );
@@ -158,7 +166,7 @@ public Bookshelf () {
158
166
this .registry .ingredients .register ("any_shovel" , IngredientToolType .create (i -> i instanceof ShovelItem , ToolType .SHOVEL ));
159
167
this .registry .ingredients .register ("any_sword" , IngredientToolType .create (i -> i instanceof SwordItem , null ));
160
168
this .registry .ingredients .register ("any_shear" , IngredientToolType .create (i -> i instanceof ShearsItem , null ));
161
-
169
+
162
170
this .registry .ingredients .register ("enchant_armor" , IngredientEnchantmentType .create (EnchantmentType .ARMOR ));
163
171
this .registry .ingredients .register ("enchant_armor_feet" , IngredientEnchantmentType .create (EnchantmentType .ARMOR_FEET ));
164
172
this .registry .ingredients .register ("enchant_armor_legs" , IngredientEnchantmentType .create (EnchantmentType .ARMOR_LEGS ));
@@ -173,14 +181,24 @@ public Bookshelf () {
173
181
this .registry .ingredients .register ("enchant_wearable" , IngredientEnchantmentType .create (EnchantmentType .WEARABLE ));
174
182
this .registry .ingredients .register ("enchant_crossbow" , IngredientEnchantmentType .create (EnchantmentType .CROSSBOW ));
175
183
this .registry .ingredients .register ("enchant_vanishable" , IngredientEnchantmentType .create (EnchantmentType .VANISHABLE ));
176
-
184
+
177
185
// Block Ingredients
178
186
BlockIngredient .register (BlockIngredientAny .SERIALIZER , BlockIngredientAny .ID );
179
187
BlockIngredient .register (BlockIngredientCheckState .SERIALIZER , BlockIngredientCheckState .ID );
180
188
BlockIngredient .register (BlockIngredientCheckBlock .SERIALIZER , BlockIngredientCheckBlock .ID );
181
189
BlockIngredient .register (BlockIngredientCheckTag .SERIALIZER , BlockIngredientCheckTag .ID );
182
190
BlockIngredient .register (BlockIngredientTestState .SERIALIZER , BlockIngredientTestState .ID );
183
-
191
+
184
192
this .registry .initialize (FMLJavaModLoadingContext .get ().getModEventBus ());
185
193
}
194
+
195
+ private void registerCommands (RegisterCommandsEvent event ) {
196
+
197
+ final LiteralArgumentBuilder <CommandSource > root = Commands .literal ("bookshelf" );
198
+ new CommandHand (root );
199
+ new CommandTranslate (root );
200
+ new CommandLootChest (root );
201
+
202
+ event .getDispatcher ().register (root );
203
+ }
186
204
}
0 commit comments