Skip to content

Commit c12b5b2

Browse files
committed
Add a means for Processing Arrays to access getMachineTierForRecipe
- Change method access from protected to public in AbstractRecipeLogic - Add getter in WorkableTieredMetaTileEntity (common superclass) to get this from the workable, so that Processing Arrays can use it in SoG. - Refactor test that no longer needs reflection
1 parent 90c22f3 commit c12b5b2

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public List<Pair<ItemStack, Integer>> getChancedItemOutputs() {
442442
* Used to override the machine's tier for the purposes of determining chanced outputs.
443443
* The default implementation simply returns the overclocking tier of the maximum voltage of the machine.
444444
*/
445-
protected int getMachineTierForRecipe(Recipe recipe) {
445+
public int getMachineTierForRecipe(Recipe recipe) {
446446
return getOverclockingTier(getMaxVoltage());
447447
}
448448

src/main/java/gregtech/api/metatileentity/WorkableTieredMetaTileEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ protected int getOutputTankCapacity(int index) {
136136
return 64000;
137137
}
138138

139+
public int getMachineTierForRecipe(Recipe recipe) {
140+
if(workable == null) return 0;
141+
return workable.getMachineTierForRecipe(recipe);
142+
}
143+
139144
@Override
140145
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
141146
super.addInformation(stack, player, tooltip, advanced);

src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityMacerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected RecipeLogicEnergy createWorkable(RecipeMap<?> recipeMap) {
3232
* after MV. Macerators now only gain slots at HV, but the prior convention is retained.
3333
*/
3434
@Override
35-
protected int getMachineTierForRecipe(Recipe recipe) {
35+
public int getMachineTierForRecipe(Recipe recipe) {
3636
// if the recipe base tier is above MV, use default logic
3737
int baseTier = recipe.getBaseTier();
3838
if(baseTier > GTValues.MV)

src/test/java/gregtech/api/capability/impl/AbstractRecipeLogicTest.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.junit.jupiter.params.*;
1616
import org.junit.jupiter.params.provider.*;
1717

18-
import java.lang.reflect.InvocationTargetException;
1918
import java.util.stream.Stream;
2019

2120
import static org.junit.jupiter.api.Assertions.*;
@@ -317,10 +316,7 @@ static Stream<Arguments> macerChancedArgs() {
317316
*/
318317
@ParameterizedTest
319318
@MethodSource("macerChancedArgs")
320-
public void macerator_chanced_outputs(int outputs, int tier, int chanceExpected) throws
321-
NoSuchMethodException,
322-
InvocationTargetException,
323-
IllegalAccessException {
319+
public void macerator_chanced_outputs(int outputs, int tier, int chanceExpected) {
324320
World world = DummyWorld.INSTANCE;
325321

326322
// Create an empty recipe map to work with
@@ -351,15 +347,11 @@ public void macerator_chanced_outputs(int outputs, int tier, int chanceExpected)
351347
.buildAndRegister();
352348

353349
// get at the Macerator custom workable logic
354-
var workableFn = MetaTileEntityMacerator.class.getDeclaredMethod("createWorkable", RecipeMap.class);
355-
workableFn.setAccessible(true);
356-
RecipeLogicEnergy workable = (RecipeLogicEnergy) workableFn.invoke(macer, map);
357-
358350
AbstractRecipeLogic arl = new AbstractRecipeLogic(macerTE, map) {
359351

360352
@Override
361-
protected int getMachineTierForRecipe(Recipe recipe) {
362-
return workable.getMachineTierForRecipe(recipe);
353+
public int getMachineTierForRecipe(Recipe recipe) {
354+
return macer.getMachineTierForRecipe(recipe);
363355
}
364356

365357
@Override

0 commit comments

Comments
 (0)