-
Notifications
You must be signed in to change notification settings - Fork 32
Railcraft compat #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LonelyxiyaOVO
wants to merge
9
commits into
CleanroomMC:master
Choose a base branch
from
LonelyxiyaOVO:Railcraft-compat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Railcraft compat #384
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
77aeaa5
Railcraft compat
LonelyxiyaOVO f7c3701
Fix bug
LonelyxiyaOVO 17e5d27
Update railcraft_example.groovy
LonelyxiyaOVO 09cdcb9
optimize code
LonelyxiyaOVO dd77b78
Functional and logical bug fixes
LonelyxiyaOVO 4ab6ae2
Update FluidFuels.java
LonelyxiyaOVO 99933e7
Update FluidFuels.java
LonelyxiyaOVO 84d43bb
Update buildscript.properties
LonelyxiyaOVO e6ff65d
optimize code
LonelyxiyaOVO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
LonelyxiyaOVO marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // Railcraft GroovyScript Example | ||
| // This file demonstrates how to use the Railcraft compat features | ||
| // pls Railcraft 1.2.1.0 beta8 | ||
|
|
||
| // ============================================ | ||
| // Blast Furnace | ||
| // ============================================ | ||
|
|
||
| // Add a recipe: input, output, time (ticks), slag amount | ||
| mods.railcraft.blastFurnace.add(item('minecraft:iron_ingot'), item('railcraft:ingot:1'), 1280, 1) | ||
|
|
||
| // Add with default time (1280 ticks) and slag (1) | ||
| mods.railcraft.blastFurnace.add(item('minecraft:iron_block'), item('railcraft:ingot:1') * 9) | ||
|
|
||
| // Using recipe builder | ||
| mods.railcraft.blastFurnace.recipeBuilder() | ||
| .input(item('minecraft:gold_ingot')) | ||
| .output(item('railcraft:ingot:2')) | ||
| .time(1000) | ||
| .slag(2) | ||
| .register() | ||
|
|
||
| // Remove by output | ||
| mods.railcraft.blastFurnace.removeByOutput(item('railcraft:ingot:1')) | ||
|
|
||
| // Remove by input | ||
| mods.railcraft.blastFurnace.removeByInput(item('minecraft:iron_ingot')) | ||
|
|
||
| // Remove all | ||
| mods.railcraft.blastFurnace.removeAll() | ||
|
|
||
|
|
||
| // ============================================ | ||
| // Coke Oven | ||
| // ============================================ | ||
|
|
||
| // Add a recipe: input, output, fluid output, time (ticks) | ||
| mods.railcraft.cokeOven.add(item('minecraft:log'), item('railcraft:fuel_coke'), fluid('creosote') * 500, 1800) | ||
|
|
||
| // Add with item output only | ||
| mods.railcraft.cokeOven.add(item('minecraft:log:1'), item('railcraft:fuel_coke'), 1800) | ||
|
|
||
| // Using recipe builder | ||
| mods.railcraft.cokeOven.recipeBuilder() | ||
| .input(item('minecraft:coal')) | ||
| .output(item('railcraft:fuel_coke')) | ||
| .fluid(fluid('creosote') * 1000) | ||
| .time(2000) | ||
| .register() | ||
|
|
||
| // Remove by output | ||
| mods.railcraft.cokeOven.removeByOutput(item('railcraft:fuel_coke')) | ||
|
|
||
| // Remove by input | ||
| mods.railcraft.cokeOven.removeByInput(item('minecraft:log')) | ||
|
|
||
| // Remove all | ||
| mods.railcraft.cokeOven.removeAll() | ||
|
|
||
|
|
||
| // ============================================ | ||
| // Rock Crusher | ||
| // ============================================ | ||
|
|
||
| // Add a recipe with multiple outputs and chances | ||
| mods.railcraft.rockCrusher.recipeBuilder() | ||
| .input(item('minecraft:stone')) | ||
| .output(item('minecraft:cobblestone'), 1.0f) | ||
| .output(item('minecraft:sand'), 0.5f) | ||
| .output(item('minecraft:gravel'), 0.25f) | ||
| .time(200) | ||
| .register() | ||
|
|
||
| // Remove by output | ||
| mods.railcraft.rockCrusher.removeByOutput(item('minecraft:cobblestone')) | ||
|
|
||
| // Remove by input | ||
| mods.railcraft.rockCrusher.removeByInput(item('minecraft:stone')) | ||
|
|
||
| // Remove all | ||
| mods.railcraft.rockCrusher.removeAll() | ||
|
|
||
|
|
||
| // ============================================ | ||
| // Rolling Machine | ||
| // ============================================ | ||
|
|
||
| // Add shaped recipe | ||
| mods.railcraft.rollingMachine.addShaped( | ||
| item('minecraft:iron_bars') * 8, | ||
| [ | ||
| [item('minecraft:iron_ingot'), item('minecraft:iron_ingot'), item('minecraft:iron_ingot')], | ||
| [item('minecraft:iron_ingot'), item('minecraft:iron_ingot'), item('minecraft:iron_ingot')] | ||
| ], | ||
| 200 | ||
| ) | ||
|
|
||
| // Add shapeless recipe | ||
| mods.railcraft.rollingMachine.addShapeless( | ||
| item('minecraft:iron_ingot') * 9, | ||
| [item('minecraft:iron_block')], | ||
| 100 | ||
| ) | ||
|
|
||
| // Using shaped builder | ||
| mods.railcraft.rollingMachine.shapedBuilder() | ||
| .output(item('minecraft:rail') * 16) | ||
| .matrix('I I', 'I I', 'I I') | ||
| .key('I', item('minecraft:iron_ingot')) | ||
| .time(100) | ||
| .register() | ||
|
|
||
| // Using shapeless builder | ||
| mods.railcraft.rollingMachine.shapelessBuilder() | ||
| .output(item('minecraft:iron_nugget') * 9) | ||
| .input(item('minecraft:iron_ingot')) | ||
| .time(50) | ||
| .register() | ||
|
|
||
| // Remove by output | ||
| mods.railcraft.rollingMachine.removeByOutput(item('minecraft:rail')) | ||
|
|
||
| // Remove all | ||
| mods.railcraft.rollingMachine.removeAll() | ||
|
|
||
|
|
||
| // ============================================ | ||
| // Fluid Fuels (for Boilers) | ||
| // ============================================ | ||
|
|
||
| // Add a fluid fuel with heat value | ||
| mods.railcraft.fluidFuels.add(fluid('lava'), 32000) | ||
|
|
||
| // Add with default heat value | ||
| mods.railcraft.fluidFuels.add(fluid('oil')) | ||
|
|
||
| // Remove a fluid fuel | ||
| mods.railcraft.fluidFuels.remove(fluid('creosote')) | ||
|
|
||
| // Remove all | ||
| mods.railcraft.fluidFuels.removeAll() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
src/main/java/com/cleanroommc/groovyscript/compat/mods/railcraft/BlastFurnace.java
|
LonelyxiyaOVO marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| package com.cleanroommc.groovyscript.compat.mods.railcraft; | ||
|
|
||
| import com.cleanroommc.groovyscript.api.GroovyLog; | ||
| import com.cleanroommc.groovyscript.api.IIngredient; | ||
| import com.cleanroommc.groovyscript.api.documentation.annotations.*; | ||
| import com.cleanroommc.groovyscript.compat.mods.ModSupport; | ||
| import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper; | ||
| import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; | ||
| import com.cleanroommc.groovyscript.registry.StandardListRegistry; | ||
| import mods.railcraft.api.crafting.Crafters; | ||
| import mods.railcraft.api.crafting.IBlastFurnaceCrafter; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.item.crafting.Ingredient; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| @RegistryDescription | ||
| public class BlastFurnace extends StandardListRegistry<IBlastFurnaceCrafter.IRecipe> { | ||
|
|
||
| @RecipeBuilderDescription(example = @Example(".input(item('minecraft:iron_ingot')).output(item('railcraft:ingot:1')).time(1280).slag(1)")) | ||
| public static RecipeBuilder recipeBuilder() { | ||
| return new RecipeBuilder(); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<IBlastFurnaceCrafter.IRecipe> getRecipes() { | ||
| return Crafters.blastFurnace().getRecipes(); | ||
| } | ||
|
|
||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public IBlastFurnaceCrafter.IRecipe add(IIngredient input, ItemStack output, int time, int slag) { | ||
| RecipeBuilder builder = recipeBuilder(); | ||
| builder.input(input); | ||
| builder.output(output); | ||
| builder.time = time; | ||
| builder.slag = slag; | ||
|
LonelyxiyaOVO marked this conversation as resolved.
|
||
| return builder.register(); | ||
| } | ||
|
|
||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public IBlastFurnaceCrafter.IRecipe add(IIngredient input, ItemStack output, int time) { | ||
| return add(input, output, time, 1); | ||
| } | ||
|
|
||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public IBlastFurnaceCrafter.IRecipe add(IIngredient input, ItemStack output) { | ||
| return add(input, output, IBlastFurnaceCrafter.SMELT_TIME, 1); | ||
| } | ||
|
|
||
| @MethodDescription(example = @Example("item('railcraft:ingot:1')")) | ||
| public void removeByOutput(ItemStack output) { | ||
|
LonelyxiyaOVO marked this conversation as resolved.
|
||
| if (IngredientHelper.isEmpty(output)) { | ||
| GroovyLog.msg("Error removing Railcraft Blast Furnace recipe") | ||
| .error() | ||
| .add("output must not be empty") | ||
| .post(); | ||
| return; | ||
| } | ||
| if (!getRecipes().removeIf(recipe -> { | ||
| if (ItemStack.areItemStacksEqual(recipe.getOutput(), output)) { | ||
| addBackup(recipe); | ||
| return true; | ||
| } | ||
| return false; | ||
| })) { | ||
| GroovyLog.msg("Error removing Railcraft Blast Furnace recipe") | ||
| .error() | ||
| .add("no recipes found for {}", output) | ||
| .post(); | ||
| } | ||
| } | ||
|
|
||
| @MethodDescription(example = @Example("item('minecraft:iron_ingot')")) | ||
| public void removeByInput(IIngredient input) { | ||
| if (IngredientHelper.isEmpty(input)) { | ||
| GroovyLog.msg("Error removing Railcraft Blast Furnace recipe") | ||
| .error() | ||
| .add("input must not be empty") | ||
| .post(); | ||
| return; | ||
| } | ||
| if (!getRecipes().removeIf(recipe -> { | ||
| if (recipe.getInput().test(input.getMatchingStacks()[0])) { | ||
|
LonelyxiyaOVO marked this conversation as resolved.
|
||
| addBackup(recipe); | ||
| return true; | ||
| } | ||
| return false; | ||
| })) { | ||
| GroovyLog.msg("Error removing Railcraft Blast Furnace recipe") | ||
| .error() | ||
| .add("no recipes found for {}", input) | ||
| .post(); | ||
| } | ||
| } | ||
|
|
||
| @Property(property = "input", comp = @Comp(eq = 1)) | ||
| @Property(property = "output", comp = @Comp(eq = 1)) | ||
| public static class RecipeBuilder extends AbstractRecipeBuilder<IBlastFurnaceCrafter.IRecipe> { | ||
|
|
||
| @Property(comp = @Comp(gte = 0), defaultValue = "IBlastFurnaceCrafter.SMELT_TIME") | ||
| private int time = IBlastFurnaceCrafter.SMELT_TIME; | ||
| @Property(comp = @Comp(gte = 0), defaultValue = "1") | ||
| private int slag = 1; | ||
|
|
||
| @RecipeBuilderMethodDescription | ||
| public RecipeBuilder time(int time) { | ||
| this.time = time; | ||
| return this; | ||
| } | ||
|
|
||
| @RecipeBuilderMethodDescription | ||
| public RecipeBuilder slag(int slag) { | ||
| this.slag = slag; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public String getErrorMsg() { | ||
| return "Error adding Railcraft Blast Furnace recipe"; | ||
| } | ||
|
|
||
| @Override | ||
| public void validate(GroovyLog.Msg msg) { | ||
| validateItems(msg, 1, 1, 1, 1); | ||
| validateFluids(msg); | ||
| msg.add(time <= 0, "time must be greater than 0, got: {}", time); | ||
| msg.add(slag < 0, "slag must be non-negative, got: {}", slag); | ||
| } | ||
|
|
||
| @Override | ||
| @RecipeBuilderRegistrationMethod | ||
| public @Nullable IBlastFurnaceCrafter.IRecipe register() { | ||
| if (!validate()) return null; | ||
| ItemStack outputStack = output.get(0); | ||
| Ingredient inputIngredient = input.get(0).toMcIngredient(); | ||
|
|
||
| IBlastFurnaceCrafter.IRecipe recipe = new IBlastFurnaceCrafter.IRecipe() { | ||
| @Override | ||
| public net.minecraft.util.ResourceLocation getName() { | ||
| return new net.minecraft.util.ResourceLocation("groovyscript", "blastfurnace_" + System.currentTimeMillis()); | ||
|
LonelyxiyaOVO marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public Ingredient getInput() { | ||
| return inputIngredient; | ||
| } | ||
|
|
||
| @Override | ||
| public int getTickTime(ItemStack input) { | ||
| return time; | ||
| } | ||
|
|
||
| @Override | ||
| public ItemStack getOutput() { | ||
| return outputStack.copy(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getSlagOutput() { | ||
| return slag; | ||
| } | ||
| }; | ||
|
|
||
| ModSupport.RAILCRAFT.get().blastFurnace.add(recipe); | ||
| return recipe; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.