Skip to content

Commit 36c813c

Browse files
committed
Delay command construction to later in the server lifecycle.
1 parent 498fdb5 commit 36c813c

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

src/main/java/net/darkhax/bookshelf/Bookshelf.java

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414

15+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
16+
1517
import net.darkhax.bookshelf.command.ArgumentTypeLootTable;
1618
import net.darkhax.bookshelf.command.ArgumentTypeMod;
1719
import net.darkhax.bookshelf.crafting.block.BlockIngredient;
@@ -32,7 +34,9 @@
3234
import net.darkhax.bookshelf.crafting.recipes.smithing.SmithingRecipeFont;
3335
import net.darkhax.bookshelf.crafting.recipes.smithing.SmithingRecipeRepairCost;
3436
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;
3640
import net.darkhax.bookshelf.loot.condition.CheckBiomeTag;
3741
import net.darkhax.bookshelf.loot.condition.CheckDimensionId;
3842
import net.darkhax.bookshelf.loot.condition.CheckEnchantability;
@@ -53,6 +57,8 @@
5357
import net.darkhax.bookshelf.loot.modifier.ModifierSilkTouch;
5458
import net.darkhax.bookshelf.registry.RegistryHelper;
5559
import net.minecraft.advancements.criterion.ItemPredicate;
60+
import net.minecraft.command.CommandSource;
61+
import net.minecraft.command.Commands;
5662
import net.minecraft.command.arguments.ArgumentSerializer;
5763
import net.minecraft.enchantment.EnchantmentType;
5864
import net.minecraft.item.AxeItem;
@@ -63,29 +69,31 @@
6369
import net.minecraft.item.SwordItem;
6470
import net.minecraft.loot.LootConditionType;
6571
import net.minecraft.util.ResourceLocation;
72+
import net.minecraftforge.common.MinecraftForge;
6673
import net.minecraftforge.common.ToolType;
74+
import net.minecraftforge.event.RegisterCommandsEvent;
6775
import net.minecraftforge.fml.common.Mod;
6876
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
6977

7078
@Mod(Bookshelf.MOD_ID)
7179
public final class Bookshelf {
72-
80+
7381
public static Bookshelf instance;
74-
82+
7583
// System Constants
7684
public static final Random RANDOM = new Random();
77-
85+
7886
public static final String NEW_LINE = System.getProperty("line.separator");
79-
87+
8088
// Mod Constants
8189
public static final String MOD_ID = "bookshelf";
82-
90+
8391
public static final String MOD_NAME = "Bookshelf";
84-
92+
8593
public static final Logger LOG = LogManager.getLogger(MOD_NAME);
86-
94+
8795
private final RegistryHelper registry = new RegistryHelper(MOD_ID, LOG);
88-
96+
8997
public final LootConditionType conditionIsMob;
9098
public final LootConditionType conditionCheckVillage;
9199
public final LootConditionType conditionCheckStructure;
@@ -99,17 +107,17 @@ public final class Bookshelf {
99107
public final LootConditionType conditionCheckEnchantability;
100108
public final LootConditionType conditionCheckBiomeTag;
101109
public final LootConditionType conditionCheckDimension;
102-
103-
public Bookshelf () {
104-
110+
111+
public Bookshelf() {
112+
105113
// Commands
106-
new BookshelfCommands(this.registry);
107-
114+
MinecraftForge.EVENT_BUS.addListener(this::registerCommands);
115+
108116
// Command arguments
109117
this.registry.commands.registerCommandArgument("enum", ArgumentTypeHandOutput.class, new ArgumentTypeHandOutput.Serialzier());
110118
this.registry.commands.registerCommandArgument("mod", ArgumentTypeMod.class, new ArgumentSerializer<>( () -> ArgumentTypeMod.INSTACE));
111119
this.registry.commands.registerCommandArgument("loot", ArgumentTypeLootTable.class, new ArgumentSerializer<>( () -> ArgumentTypeLootTable.INSTACE));
112-
120+
113121
// Loot Modifier
114122
this.registry.lootModifiers.register(ModifierClear.SERIALIZER, "clear");
115123
this.registry.lootModifiers.register(ModifierSilkTouch.SERIALIZER, "silk_touch");
@@ -122,7 +130,7 @@ public Bookshelf () {
122130
this.registry.lootModifiers.register(ModifierRecipe.STONECUT, "stonecutting");
123131
this.registry.lootModifiers.register(ModifierRecipe.SMITHING, "smithing");
124132
this.registry.lootModifiers.register(ModifierAddItem.SERIALIZER, "add_item");
125-
133+
126134
// Loot Conditions
127135
this.conditionIsMob = this.registry.lootConditions.register(EntityIsMob.SERIALIZER, "is_mob");
128136
this.conditionCheckVillage = this.registry.lootConditions.register(CheckVillage.SERIALIZER, "check_village");
@@ -137,18 +145,18 @@ public Bookshelf () {
137145
this.conditionCheckEnchantability = this.registry.lootConditions.register(CheckEnchantability.SERIALIZER, "check_enchantability");
138146
this.conditionCheckBiomeTag = this.registry.lootConditions.register(CheckBiomeTag.SERIALIZER, "check_biome_tag");
139147
this.conditionCheckDimension = this.registry.lootConditions.register(CheckDimensionId.SERIALIZER, "check_dimension");
140-
148+
141149
// Item Predicates
142150
ItemPredicate.register(new ResourceLocation("bookshelf", "modid"), ItemPredicateModid::fromJson);
143151
ItemPredicate.register(new ResourceLocation("bookshelf", "ingredient"), ItemPredicateIngredient::fromJson);
144-
152+
145153
// Recipe Serializers
146154
this.registry.recipeSerializers.register(ShapedRecipeDamaging.SERIALIZER, "crafting_shaped_with_damage");
147155
this.registry.recipeSerializers.register(ShapelessRecipeDamage.SERIALIZER, "crafting_shapeless_with_damage");
148156
this.registry.recipeSerializers.register(SmithingRecipeFont.SERIALIZER, "smithing_font");
149157
this.registry.recipeSerializers.register(SmithingRecipeRepairCost.SERIALIZER, "smithing_repair_cost");
150158
this.registry.recipeSerializers.register(SmithingRecipeEnchantment.SERIALIZER, "smithing_enchant");
151-
159+
152160
// Ingredients
153161
this.registry.ingredients.register("potion", IngredientPotion.SERIALIZER);
154162
this.registry.ingredients.register("modid", IngredientModid.SERIALIZER);
@@ -158,7 +166,7 @@ public Bookshelf () {
158166
this.registry.ingredients.register("any_shovel", IngredientToolType.create(i -> i instanceof ShovelItem, ToolType.SHOVEL));
159167
this.registry.ingredients.register("any_sword", IngredientToolType.create(i -> i instanceof SwordItem, null));
160168
this.registry.ingredients.register("any_shear", IngredientToolType.create(i -> i instanceof ShearsItem, null));
161-
169+
162170
this.registry.ingredients.register("enchant_armor", IngredientEnchantmentType.create(EnchantmentType.ARMOR));
163171
this.registry.ingredients.register("enchant_armor_feet", IngredientEnchantmentType.create(EnchantmentType.ARMOR_FEET));
164172
this.registry.ingredients.register("enchant_armor_legs", IngredientEnchantmentType.create(EnchantmentType.ARMOR_LEGS));
@@ -173,14 +181,24 @@ public Bookshelf () {
173181
this.registry.ingredients.register("enchant_wearable", IngredientEnchantmentType.create(EnchantmentType.WEARABLE));
174182
this.registry.ingredients.register("enchant_crossbow", IngredientEnchantmentType.create(EnchantmentType.CROSSBOW));
175183
this.registry.ingredients.register("enchant_vanishable", IngredientEnchantmentType.create(EnchantmentType.VANISHABLE));
176-
184+
177185
// Block Ingredients
178186
BlockIngredient.register(BlockIngredientAny.SERIALIZER, BlockIngredientAny.ID);
179187
BlockIngredient.register(BlockIngredientCheckState.SERIALIZER, BlockIngredientCheckState.ID);
180188
BlockIngredient.register(BlockIngredientCheckBlock.SERIALIZER, BlockIngredientCheckBlock.ID);
181189
BlockIngredient.register(BlockIngredientCheckTag.SERIALIZER, BlockIngredientCheckTag.ID);
182190
BlockIngredient.register(BlockIngredientTestState.SERIALIZER, BlockIngredientTestState.ID);
183-
191+
184192
this.registry.initialize(FMLJavaModLoadingContext.get().getModEventBus());
185193
}
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+
}
186204
}

src/main/java/net/darkhax/bookshelf/internal/command/BookshelfCommands.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)