Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void onPostInit(FMLPostInitializationEvent event) {
@Mod.EventHandler
public void onServerLoad(FMLServerStartingEvent event) {
event.registerServerCommand(new GSCommand());
VanillaModule.command.onStartServer(event.getServer());
VanillaModule.INSTANCE.command.onStartServer(event.getServer());
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public GSCommand() {
addSubcommand(new InfoSelfCommand());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public GroovyBlock(String name, Material blockMaterialIn) {
setHardness(2.0F);
setResistance(10.0F);
setSoundType(SoundType.STONE);
if (VanillaModule.content.getDefaultTab() != null) {
setCreativeTab(VanillaModule.content.getDefaultTab());
if (VanillaModule.INSTANCE.content.getDefaultTab() != null) {
setCreativeTab(VanillaModule.INSTANCE.content.getDefaultTab());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static void registerItem(Item item) {
GroovyLog.get().errorMC("Items must registered in preInit. Tried to register {} too late!", item.getRegistryName());
return;
}
if (item.getCreativeTab() == null && VanillaModule.content.getDefaultTab() != null) {
item.setCreativeTab(VanillaModule.content.getDefaultTab());
if (item.getCreativeTab() == null && VanillaModule.INSTANCE.content.getDefaultTab() != null) {
item.setCreativeTab(VanillaModule.INSTANCE.content.getDefaultTab());
}
ResourceLocation key = item.getRegistryName();
if (key == null || ITEMS.containsKey(key.getPath())) {
Expand Down Expand Up @@ -77,8 +77,8 @@ public static void initItems(IForgeRegistry<Item> registry) {

public GroovyItem(String loc) {
setRegistryName(GroovyScript.getRunConfig().getPackId(), loc);
if (VanillaModule.content.getDefaultTab() != null) {
setCreativeTab(VanillaModule.content.getDefaultTab());
if (VanillaModule.INSTANCE.content.getDefaultTab() != null) {
setCreativeTab(VanillaModule.INSTANCE.content.getDefaultTab());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void validate(GroovyLog.Msg msg) {
public @Nullable Burning.BurningRecipe register() {
if (!validate()) return null;
BurningRecipe burningRecipe = new BurningRecipe(this.input.get(0), this.output.get(0), this.ticks, this.startCondition);
VanillaModule.inWorldCrafting.burning.add(burningRecipe);
VanillaModule.INSTANCE.inWorldCrafting.burning.add(burningRecipe);
return burningRecipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void validate(GroovyLog.Msg msg) {
public @Nullable Explosion.ExplosionRecipe register() {
if (!validate()) return null;
ExplosionRecipe explosionRecipe = new ExplosionRecipe(this.input.get(0), this.output.get(0), this.chance, this.startCondition);
VanillaModule.inWorldCrafting.explosion.add(explosionRecipe);
VanillaModule.INSTANCE.inWorldCrafting.explosion.add(explosionRecipe);
return explosionRecipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void validate(GroovyLog.Msg msg) {
this.startCondition,
this.afterRecipe,
this.outputBlock);
VanillaModule.inWorldCrafting.fluidToBlock.add(recipe);
VanillaModule.INSTANCE.inWorldCrafting.fluidToBlock.add(recipe);
return recipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void validate(GroovyLog.Msg msg) {
this.startCondition,
this.afterRecipe,
this.fluidOutput.get(0).getFluid());
VanillaModule.inWorldCrafting.fluidToFluid.add(recipe);
VanillaModule.INSTANCE.inWorldCrafting.fluidToFluid.add(recipe);
return recipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void validate(GroovyLog.Msg msg) {
this.afterRecipe,
this.output.get(0),
this.fluidConsumptionChance);
VanillaModule.inWorldCrafting.fluidToItem.add(recipe);
VanillaModule.INSTANCE.inWorldCrafting.fluidToItem.add(recipe);
return recipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void validate(GroovyLog.Msg msg) {
public @Nullable PistonPush.PistonPushRecipe register() {
if (!validate()) return null;
PistonPushRecipe pistonPushRecipe = new PistonPushRecipe(this.input.get(0), this.output.get(0), this.maxConversionsPerPush, this.minHarvestLevel, this.startCondition);
VanillaModule.inWorldCrafting.pistonPush.add(pistonPushRecipe);
VanillaModule.INSTANCE.inWorldCrafting.pistonPush.add(pistonPushRecipe);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static void register(IModRegistry registry) {
List<FluidRecipeCategory.RecipeWrapper> recipeWrappers = new ArrayList<>();
FluidRecipe.forEach(fluidRecipe -> recipeWrappers.add(new FluidRecipeCategory.RecipeWrapper(fluidRecipe)));
registry.addRecipes(recipeWrappers, FluidRecipeCategory.UID);
registry.addRecipes(VanillaModule.inWorldCrafting.explosion.getRecipeWrappers(), ExplosionRecipeCategory.UID);
registry.addRecipes(VanillaModule.inWorldCrafting.burning.getRecipeWrappers(), BurningRecipeCategory.UID);
registry.addRecipes(VanillaModule.inWorldCrafting.pistonPush.getRecipeWrappers(), PistonPushRecipeCategory.UID);
registry.addRecipes(VanillaModule.INSTANCE.inWorldCrafting.explosion.getRecipeWrappers(), ExplosionRecipeCategory.UID);
registry.addRecipes(VanillaModule.INSTANCE.inWorldCrafting.burning.getRecipeWrappers(), BurningRecipeCategory.UID);
registry.addRecipes(VanillaModule.INSTANCE.inWorldCrafting.pistonPush.getRecipeWrappers(), PistonPushRecipeCategory.UID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ else if (name == null || name.isEmpty()) {
if (quality < 0) out.add("quality < 0 may make the loot entry unable to be rolled");

if (validateForRegister) {
if (tableName == null || VanillaModule.loot.tables.get(tableName) == null) out.add("No valid LootTable specified").error();
else if (poolName == null || poolName.isEmpty() || VanillaModule.loot.tables.get(tableName).getPool(poolName) == null) out.add("No valid LootPool specified").error();
else if (VanillaModule.loot.tables.get(tableName).getPool(poolName).getEntry(name) != null) out.add("Attempted to add duplicate entry " + name + " to " + tableName + " - " + poolName);
if (tableName == null || VanillaModule.INSTANCE.loot.tables.get(tableName) == null) out.add("No valid LootTable specified").error();
else if (poolName == null || poolName.isEmpty() || VanillaModule.INSTANCE.loot.tables.get(tableName).getPool(poolName) == null) out.add("No valid LootPool specified").error();
else if (VanillaModule.INSTANCE.loot.tables.get(tableName).getPool(poolName).getEntry(name) != null) out.add("Attempted to add duplicate entry " + name + " to " + tableName + " - " + poolName);
}

out.postIfNotEmpty();
Expand All @@ -332,7 +332,7 @@ public LootEntry build() {

public void register() {
if (!validate(true)) return;
VanillaModule.loot.tables.get(tableName)
VanillaModule.INSTANCE.loot.tables.get(tableName)
.getPool(poolName)
.addEntry(new LootEntryItem(item, weight, quality, functions.toArray(new LootFunction[0]), conditions.toArray(new LootCondition[0]), name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public LootPoolBuilder bonusRollsRange(float min, float max) {
private boolean validate(boolean validateForRegister) {
if (name == null || name.isEmpty()) out.add("No name provided").error();
if (validateForRegister) {
if (tableName == null || !VanillaModule.loot.tables.containsKey(tableName)) out.add("No valid LootTable specified").error();
if (tableName == null || !VanillaModule.INSTANCE.loot.tables.containsKey(tableName)) out.add("No valid LootTable specified").error();
else if (name == null || name.isEmpty()) out.add("LootPool must have a name specified with .name()").error();
else if (VanillaModule.loot.tables.get(tableName).getPool(name) != null) out.add("Attempted to add duplicate pool " + name + " to " + tableName).error();
else if (VanillaModule.INSTANCE.loot.tables.get(tableName).getPool(name) != null) out.add("Attempted to add duplicate pool " + name + " to " + tableName).error();
}
out.postIfNotEmpty();
return out.getLevel() != Level.ERROR;
Expand All @@ -135,7 +135,7 @@ public LootPool build() {

public void register() {
if (!validate(true)) return;
VanillaModule.loot.tables.get(tableName)
VanillaModule.INSTANCE.loot.tables.get(tableName)
.addPool(
new LootPool(lootEntries.toArray(new LootEntry[0]), poolConditions.toArray(new LootCondition[0]), rolls, bonusRolls, name)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void removeAndHide(IIngredient ingredient) {
return;
}
hide(ingredient);
VanillaModule.crafting.removeByOutput(ingredient, false);
VanillaModule.INSTANCE.crafting.removeByOutput(ingredient, false);
}

@MethodDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void remove(String name) {

@MethodDescription(example = @Example("item('thaumcraft:mechanism_simple')"))
public void removeByOutput(IIngredient output) {
VanillaModule.crafting.removeByOutput(output, true);
VanillaModule.INSTANCE.crafting.removeByOutput(output, true);
}

@RecipeBuilderDescription(example = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void validate(GroovyLog.Msg msg) {
Recipe recipe = null;
for (ItemStack itemStack : input.get(0).getMatchingStacks()) {
recipe = new Recipe(itemStack, output.get(0), exp);
VanillaModule.furnace.add(recipe);
VanillaModule.INSTANCE.furnace.add(recipe);
}
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
public class ItemStackExpansion {

public static ItemStack setRarity(ItemStack self, TextFormatting color) {
VanillaModule.rarity.set(color, self);
VanillaModule.INSTANCE.rarity.set(color, self);
return self;
}

public static void addOreDict(ItemStack self, OreDictIngredient ingredient) {
VanillaModule.oreDict.add(ingredient.getOreDict(), self);
VanillaModule.INSTANCE.oreDict.add(ingredient.getOreDict(), self);
}

public static void removeOreDict(ItemStack self, OreDictIngredient ingredient) {
VanillaModule.oreDict.remove(ingredient.getOreDict(), self);
VanillaModule.INSTANCE.oreDict.remove(ingredient.getOreDict(), self);
}

public static boolean leftShift(ItemStack self, IIngredient ingredient) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cleanroommc.groovyscript.compat.vanilla;

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.api.INamed;
import com.cleanroommc.groovyscript.compat.content.Content;
import com.cleanroommc.groovyscript.compat.inworldcrafting.InWorldCrafting;
import com.cleanroommc.groovyscript.compat.loot.Loot;
Expand All @@ -10,38 +11,62 @@
import net.minecraft.command.ICommandSender;
import net.minecraft.item.ItemStack;

import java.util.ArrayList;
import java.util.List;

public class VanillaModule extends GroovyPropertyContainer {

public static final VanillaModule INSTANCE = new VanillaModule();

public static final Crafting crafting = new Crafting();
public static final Furnace furnace = new Furnace();
public static final Loot loot = new Loot();
public static final OreDict oreDict = new OreDict();
public static final Player player = new Player();
public static final Content content = new Content();
public static final Rarity rarity = new Rarity();
public static final InWorldCrafting inWorldCrafting = new InWorldCrafting();
public static final Command command = new Command();
public static final GameRule gameRule = new GameRule();
public final Crafting crafting = new Crafting();
public final Furnace furnace = new Furnace();
public final Loot loot = new Loot();
public final OreDict oreDict = new OreDict();
public final Player player = new Player();
public final Content content = new Content();
public final Rarity rarity = new Rarity();
public final InWorldCrafting inWorldCrafting = new InWorldCrafting();
public final Command command = new Command();
public final GameRule gameRule = new GameRule();

private final List<INamed> globalBindings = new ArrayList<>();

private VanillaModule() {
globalBindings.add(crafting);
globalBindings.add(furnace);
globalBindings.add(oreDict);
globalBindings.add(content);
globalBindings.add(inWorldCrafting);
}

private VanillaModule() {}
/**
* Add the given property to the vanilla container.
* Useful for mods which add additional support to a vanilla feature,
* such as enchanting or brewing.
* <p>
* In some specific situations the property is important enough
* that it should be registered as a global binding.
* While this can be done by calling
* {@link com.cleanroommc.groovyscript.sandbox.GroovyScriptSandbox#registerBinding(INamed) GroovyScriptSandbox#registerBinding}
* directly, for vanilla properties a boolean exists as a shorthand.
*
* @param property the property being added to the vanilla container
* @param addGlobalBinding if the property will be registered as a global binding. Typically {@code false}.
* @see com.cleanroommc.groovyscript.sandbox.GroovyScriptSandbox#registerBinding(INamed) GroovyScriptSandbox#registerBinding
*/
public void addProperty(INamed property, boolean addGlobalBinding) {
addProperty(property);
if (addGlobalBinding) globalBindings.add(property);
}

@Override
public void initialize(GroovyContainer<?> owner) {
GroovyScript.getSandbox().registerBinding("Minecraft", this);
GroovyScript.getSandbox().registerBinding("Vanilla", this);
// maybe remove some of these as globals?
GroovyScript.getSandbox().registerBinding(crafting);
GroovyScript.getSandbox().registerBinding(furnace);
GroovyScript.getSandbox().registerBinding(loot);
GroovyScript.getSandbox().registerBinding(oreDict);
GroovyScript.getSandbox().registerBinding(player);
GroovyScript.getSandbox().registerBinding(content);
GroovyScript.getSandbox().registerBinding(rarity);
GroovyScript.getSandbox().registerBinding(inWorldCrafting);
GroovyScript.getSandbox().registerBinding(command);
GroovyScript.getSandbox().registerBinding(gameRule);

for (INamed registry : globalBindings) {
GroovyScript.getSandbox().registerBinding(registry);
}

ExpansionHelper.mixinClass(ItemStack.class, ItemStackExpansion.class);
ExpansionHelper.mixinClass(ICommandSender.class, CommandSenderExpansion.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onUpdate(CallbackInfo ci) {
}

if (((EntityAccessor) thisEntity).getFire() > 0) {
VanillaModule.inWorldCrafting.burning.updateRecipeProgress(thisEntity);
VanillaModule.INSTANCE.inWorldCrafting.burning.updateRecipeProgress(thisEntity);
ci.cancel();
} else if (Burning.removeBurningItem(thisEntity)) {
thisEntity.setEntityInvulnerable(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class ItemMixin {

@Inject(method = "getForgeRarity", at = @At("HEAD"), cancellable = true, remap = false)
private void prioritzeGSRarities(ItemStack stack, CallbackInfoReturnable<IRarity> cir) {
cir.setReturnValue(VanillaModule.rarity.check(stack));
cir.setReturnValue(VanillaModule.INSTANCE.rarity.check(stack));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void moveCollidedEntitiesPost(float p_184322_1_,
Entity entity = list1.get(index);
if (entity.getPushReaction() == EnumPushReaction.IGNORE) return;
if (checkRecipes.get() && index < tryRecipesUntil.get() && entity instanceof EntityItem entityItem) {
VanillaModule.inWorldCrafting.pistonPush.findAndRunRecipe(entityItem1 -> {
VanillaModule.INSTANCE.inWorldCrafting.pistonPush.findAndRunRecipe(entityItem1 -> {
entityItem1.getEntityWorld().spawnEntity(entityItem1);
list1.add(entityItem1);
}, entityItem, pushingAgainst.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class LoadTableEventMixin {

@Inject(method = "reloadLootTables", at = @At("RETURN"))
private void injection(CallbackInfo ci) {
VanillaModule.loot.tables.putAll(this.registeredLootTables.asMap());
VanillaModule.INSTANCE.loot.tables.putAll(this.registeredLootTables.asMap());
MinecraftForge.EVENT_BUS.post(new LootTablesLoadedEvent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void registerTextures(TextureStitchEvent.Post event) {
public static void createSpawnPosition(WorldEvent.CreateSpawnPosition event) {
// only want to execute this for the overworld
var target = DimensionManager.getWorld(0);
if (event.getWorld() == target) VanillaModule.gameRule.applyDefaultGameRules(event.getWorld().getGameRules());
if (event.getWorld() == target) VanillaModule.INSTANCE.gameRule.applyDefaultGameRules(event.getWorld().getGameRules());
}

@SubscribeEvent
Expand Down Expand Up @@ -113,8 +113,8 @@ public static void playerLogin(PlayerEvent.PlayerLoggedInEvent event) {
if (tag.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) {
data = tag.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
}
if (VanillaModule.player.isTestingStartingItems() || !data.getBoolean(Player.GIVEN_ITEMS)) {
VanillaModule.player.addToInventory(event.player.inventory);
if (VanillaModule.INSTANCE.player.isTestingStartingItems() || !data.getBoolean(Player.GIVEN_ITEMS)) {
VanillaModule.INSTANCE.player.addToInventory(event.player.inventory);
data.setBoolean(Player.GIVEN_ITEMS, true);
tag.setTag(EntityPlayer.PERSISTED_NBT_TAG, data);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
public static void onExplosion(ExplosionEvent.Detonate event) {
for (Entity entity : event.getAffectedEntities()) {
if (entity instanceof EntityItem entityItem) {
VanillaModule.inWorldCrafting.explosion.findAndRunRecipe(entityItem);
VanillaModule.INSTANCE.inWorldCrafting.explosion.findAndRunRecipe(entityItem);
}
}
}
Expand Down
Loading