-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b39ef1
commit f098dec
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
64 changes: 64 additions & 0 deletions
64
src/main/java/com/nomiceu/nomilabs/gregtech/mixinhelper/GTDisassemblingOreRecipe.java
This file contains 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,64 @@ | ||
package com.nomiceu.nomilabs.gregtech.mixinhelper; | ||
|
||
import gregtech.common.crafting.GTShapedOreRecipe; | ||
import net.minecraft.inventory.InventoryCrafting; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A disassembling recipe that assumes that there is only one input. | ||
*/ | ||
public class GTDisassemblingOreRecipe extends GTShapedOreRecipe { | ||
private final int inputLocation; | ||
|
||
public GTDisassemblingOreRecipe(boolean isClearing, ResourceLocation group, @NotNull ItemStack result, Object... recipe) { | ||
super(isClearing, group, result, recipe); | ||
for (int i = 0; i < input.size(); i++) { | ||
var ing = input.get(i); | ||
if (ing.apply(ItemStack.EMPTY)) continue; // Empty Ingredients Return True when ItemStack.EMPTY applied | ||
inputLocation = i; | ||
return; | ||
} | ||
inputLocation = -1; | ||
} | ||
|
||
/** | ||
* A matches where the input must perfectly match the ingredient list. | ||
*/ | ||
@Override | ||
public boolean matches(@NotNull InventoryCrafting inv, @NotNull World world) { | ||
if (inv.getWidth() < 2 || inv.getWidth() > 3 || inv.getHeight() < 2 || inv.getHeight() > 3 || inv.getWidth() != inv.getHeight()) return false; | ||
if (inputLocation == -1) return false; | ||
var location = getLocationForDim(inv.getWidth()); | ||
if (location == -1) return false; | ||
|
||
int locationX = location % inv.getWidth(); | ||
int locationY = location / inv.getWidth(); | ||
|
||
// Not using inv.stackList, as the stackList may not be correct for a given invCrafting. | ||
for (int x = 0; x < inv.getWidth(); x++) { | ||
for (int y = 0; y < inv.getHeight(); y++) { | ||
if (x == locationX && y == locationY) { | ||
if (!input.get(inputLocation).apply(inv.getStackInRowAndColumn(x, y))) return false; | ||
continue; | ||
} | ||
if (!inv.getStackInRowAndColumn(x, y).isEmpty()) return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private int getLocationForDim(int dim) { | ||
switch (dim) { | ||
case 2 -> { | ||
if (inputLocation > 4 || inputLocation == 2) return -1; // Not in 2x2 square | ||
if (inputLocation > 2) return inputLocation - 1; | ||
return inputLocation; | ||
} | ||
case 3 -> { return inputLocation; } | ||
default -> { return -1; } | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/nomiceu/nomilabs/mixin/gregtech/AccessibleModHandler.java
This file contains 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,17 @@ | ||
package com.nomiceu.nomilabs.mixin.gregtech; | ||
|
||
import gregtech.api.recipes.ModHandler; | ||
import net.minecraft.item.ItemStack; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(value = ModHandler.class, remap = false) | ||
public interface AccessibleModHandler { | ||
@Invoker(value = "validateRecipeWithOutput") | ||
static boolean validateRecipeWithOutput(@NotNull String regName, @NotNull ItemStack result, | ||
@NotNull Object... recipe) { | ||
throw new NotImplementedException("AccessibleModHandler Failed to Apply!"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/nomiceu/nomilabs/mixin/gregtech/MaterialRecipeHandlerMixin.java
This file contains 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,41 @@ | ||
package com.nomiceu.nomilabs.mixin.gregtech; | ||
|
||
import com.nomiceu.nomilabs.gregtech.mixinhelper.GTDisassemblingOreRecipe; | ||
import gregtech.api.recipes.ModHandler; | ||
import gregtech.loaders.recipe.handlers.MaterialRecipeHandler; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraftforge.fml.common.registry.ForgeRegistries; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import static gregtech.api.recipes.ModHandler.finalizeShapedRecipeInput; | ||
|
||
@Mixin(value = MaterialRecipeHandler.class, remap = false) | ||
public class MaterialRecipeHandlerMixin { | ||
@Redirect(method = "processSmallDust", at = @At(value = "INVOKE", target = "Lgregtech/api/recipes/ModHandler;addShapedRecipe(Ljava/lang/String;Lnet/minecraft/item/ItemStack;[Ljava/lang/Object;)V")) | ||
private static void addDisassemblingRecipeSmall(String regName, ItemStack result, Object[] recipe) { | ||
addDisassemblingRecipe(regName, result, recipe); | ||
} | ||
|
||
@Redirect(method = "processTinyDust", at = @At(value = "INVOKE", target = "Lgregtech/api/recipes/ModHandler;addShapedRecipe(Ljava/lang/String;Lnet/minecraft/item/ItemStack;[Ljava/lang/Object;)V")) | ||
private static void addDisassemblingRecipeTiny(String regName, ItemStack result, Object[] recipe) { | ||
addDisassemblingRecipe(regName, result, recipe); | ||
} | ||
|
||
@Unique | ||
private static void addDisassemblingRecipe(String regName, ItemStack result, Object[] recipe) { | ||
if (!regName.contains("_dust_disassembling_")) { | ||
ModHandler.addShapedRecipe(regName, result, recipe); | ||
return; | ||
} | ||
if (!AccessibleModHandler.validateRecipeWithOutput(regName, result, recipe)) return; | ||
IRecipe shapedOreRecipe = new GTDisassemblingOreRecipe(false, null, result.copy(), | ||
finalizeShapedRecipeInput(recipe)) | ||
.setMirrored(false) | ||
.setRegistryName(regName); | ||
ForgeRegistries.RECIPES.register(shapedOreRecipe); | ||
} | ||
} |
This file contains 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