Skip to content

Commit 949abda

Browse files
authored
Improve VanillaModule design (#324)
* convert vanilla global binding to list * add a way to add properties to the vanilla module * use the parameter * adjust the public method * reduce vanilla global bindings * make vanilla module properties non-static * remove player global binding
1 parent 135351d commit 949abda

26 files changed

+94
-69
lines changed

src/main/java/com/cleanroommc/groovyscript/GroovyScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void onPostInit(FMLPostInitializationEvent event) {
191191
@Mod.EventHandler
192192
public void onServerLoad(FMLServerStartingEvent event) {
193193
event.registerServerCommand(new GSCommand());
194-
VanillaModule.command.onStartServer(event.getServer());
194+
VanillaModule.INSTANCE.command.onStartServer(event.getServer());
195195
}
196196

197197
@SubscribeEvent

src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public GSCommand() {
6161
addSubcommand(new InfoSelfCommand());
6262

6363
addSubcommand(new SimpleCommand("applyDefaultGameRules", (server, sender, args) -> {
64-
VanillaModule.gameRule.applyDefaultGameRules(Objects.requireNonNull(server.getServer()).getWorld(0).getGameRules());
64+
VanillaModule.INSTANCE.gameRule.applyDefaultGameRules(Objects.requireNonNull(server.getServer()).getWorld(0).getGameRules());
6565
sender.sendMessage(new TextComponentString("Applied the default GameRules to the current world."));
6666
}));
6767

src/main/java/com/cleanroommc/groovyscript/compat/content/GroovyBlock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public GroovyBlock(String name, Material blockMaterialIn) {
9898
setHardness(2.0F);
9999
setResistance(10.0F);
100100
setSoundType(SoundType.STONE);
101-
if (VanillaModule.content.getDefaultTab() != null) {
102-
setCreativeTab(VanillaModule.content.getDefaultTab());
101+
if (VanillaModule.INSTANCE.content.getDefaultTab() != null) {
102+
setCreativeTab(VanillaModule.INSTANCE.content.getDefaultTab());
103103
}
104104
}
105105

src/main/java/com/cleanroommc/groovyscript/compat/content/GroovyItem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public static void registerItem(Item item) {
3636
GroovyLog.get().errorMC("Items must registered in preInit. Tried to register {} too late!", item.getRegistryName());
3737
return;
3838
}
39-
if (item.getCreativeTab() == null && VanillaModule.content.getDefaultTab() != null) {
40-
item.setCreativeTab(VanillaModule.content.getDefaultTab());
39+
if (item.getCreativeTab() == null && VanillaModule.INSTANCE.content.getDefaultTab() != null) {
40+
item.setCreativeTab(VanillaModule.INSTANCE.content.getDefaultTab());
4141
}
4242
ResourceLocation key = item.getRegistryName();
4343
if (key == null || ITEMS.containsKey(key.getPath())) {
@@ -77,8 +77,8 @@ public static void initItems(IForgeRegistry<Item> registry) {
7777

7878
public GroovyItem(String loc) {
7979
setRegistryName(GroovyScript.getRunConfig().getPackId(), loc);
80-
if (VanillaModule.content.getDefaultTab() != null) {
81-
setCreativeTab(VanillaModule.content.getDefaultTab());
80+
if (VanillaModule.INSTANCE.content.getDefaultTab() != null) {
81+
setCreativeTab(VanillaModule.INSTANCE.content.getDefaultTab());
8282
}
8383
}
8484

src/main/java/com/cleanroommc/groovyscript/compat/inworldcrafting/Burning.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void validate(GroovyLog.Msg msg) {
110110
public @Nullable Burning.BurningRecipe register() {
111111
if (!validate()) return null;
112112
BurningRecipe burningRecipe = new BurningRecipe(this.input.get(0), this.output.get(0), this.ticks, this.startCondition);
113-
VanillaModule.inWorldCrafting.burning.add(burningRecipe);
113+
VanillaModule.INSTANCE.inWorldCrafting.burning.add(burningRecipe);
114114
return burningRecipe;
115115
}
116116
}

src/main/java/com/cleanroommc/groovyscript/compat/inworldcrafting/Explosion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void validate(GroovyLog.Msg msg) {
133133
public @Nullable Explosion.ExplosionRecipe register() {
134134
if (!validate()) return null;
135135
ExplosionRecipe explosionRecipe = new ExplosionRecipe(this.input.get(0), this.output.get(0), this.chance, this.startCondition);
136-
VanillaModule.inWorldCrafting.explosion.add(explosionRecipe);
136+
VanillaModule.INSTANCE.inWorldCrafting.explosion.add(explosionRecipe);
137137
return explosionRecipe;
138138
}
139139
}

src/main/java/com/cleanroommc/groovyscript/compat/inworldcrafting/FluidToBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void validate(GroovyLog.Msg msg) {
146146
this.startCondition,
147147
this.afterRecipe,
148148
this.outputBlock);
149-
VanillaModule.inWorldCrafting.fluidToBlock.add(recipe);
149+
VanillaModule.INSTANCE.inWorldCrafting.fluidToBlock.add(recipe);
150150
return recipe;
151151
}
152152
}

src/main/java/com/cleanroommc/groovyscript/compat/inworldcrafting/FluidToFluid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void validate(GroovyLog.Msg msg) {
132132
this.startCondition,
133133
this.afterRecipe,
134134
this.fluidOutput.get(0).getFluid());
135-
VanillaModule.inWorldCrafting.fluidToFluid.add(recipe);
135+
VanillaModule.INSTANCE.inWorldCrafting.fluidToFluid.add(recipe);
136136
return recipe;
137137
}
138138
}

src/main/java/com/cleanroommc/groovyscript/compat/inworldcrafting/FluidToItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void validate(GroovyLog.Msg msg) {
157157
this.afterRecipe,
158158
this.output.get(0),
159159
this.fluidConsumptionChance);
160-
VanillaModule.inWorldCrafting.fluidToItem.add(recipe);
160+
VanillaModule.INSTANCE.inWorldCrafting.fluidToItem.add(recipe);
161161
return recipe;
162162
}
163163
}

src/main/java/com/cleanroommc/groovyscript/compat/inworldcrafting/PistonPush.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void validate(GroovyLog.Msg msg) {
131131
public @Nullable PistonPush.PistonPushRecipe register() {
132132
if (!validate()) return null;
133133
PistonPushRecipe pistonPushRecipe = new PistonPushRecipe(this.input.get(0), this.output.get(0), this.maxConversionsPerPush, this.minHarvestLevel, this.startCondition);
134-
VanillaModule.inWorldCrafting.pistonPush.add(pistonPushRecipe);
134+
VanillaModule.INSTANCE.inWorldCrafting.pistonPush.add(pistonPushRecipe);
135135
return null;
136136
}
137137
}

0 commit comments

Comments
 (0)