Skip to content

Commit

Permalink
Fix Tiny and Small Dust Recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Mar 28, 2024
1 parent 9b39ef1 commit f098dec
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 2 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ curseForgeRelations = requiredDependency:codechicken-lib-1-8;\
optionalDependency:cofh-core;\
optionalDependency:libvulpes;\
optionalDependency:advanced-rocketry;\
optionalDependency:architecturecraft-tridev;
optionalDependency:architecturecraft-tridev;\
optionalDependency:effortless-building;

# This project's release type on CurseForge and/or Modrinth
# Alternatively this can be set with the 'RELEASE_TYPE' environment variable.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/nomiceu/nomilabs/NomiLabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
+ "after:libvulpes;"
+ "after:crafttweaker@[4.1.20,);"
+ "after:appliedenergistics2;"
+ "after:architecturecraft;")
+ "after:architecturecraft;"
+ "after:effortlessbuilding;")
@SuppressWarnings("unused")
public class NomiLabs {
public static final Logger LOGGER = LogManager.getLogger(LabsValues.LABS_MODID);
Expand Down
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; }
}
}
}
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!");
}
}
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);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/mixins.nomilabs.gregtech.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"mixins": [
"AccessibleDecompositionRecipeHandler",
"AccessibleMaterialInfo",
"AccessibleModHandler",
"FluidStorageKeyMixin",
"GTRecipeWrapperMixin",
"MaterialFlagsMixin",
"MaterialMixin",
"MaterialRecipeHandlerMixin",
"MaterialStackMixin",
"MetaItemsMixin",
"MultiblockInfoCategoryMixin",
Expand Down

0 comments on commit f098dec

Please sign in to comment.