crafting handler crap

This commit is contained in:
Boblet 2026-04-10 14:02:17 +02:00
parent 566043d888
commit f762a9c144
9 changed files with 271 additions and 37 deletions

View File

@ -16,11 +16,6 @@ import com.hbm.items.machine.ItemBatteryPack.EnumBatteryPack;
import com.hbm.items.machine.ItemCircuit.EnumCircuitType;
import com.hbm.items.ModItems;
import com.hbm.items.weapon.GunB92Cell;
import com.hbm.items.weapon.grenade.ItemGrenadeExtra.EnumGrenadeExtra;
import com.hbm.items.weapon.grenade.ItemGrenadeFilling.EnumGrenadeFilling;
import com.hbm.items.weapon.grenade.ItemGrenadeFuze.EnumGrenadeFuze;
import com.hbm.items.weapon.grenade.ItemGrenadeShell.EnumGrenadeShell;
import com.hbm.items.weapon.grenade.ItemGrenadeUniversal;
import com.hbm.items.weapon.sedna.factory.GunFactory.EnumAmmo;
import com.hbm.items.weapon.sedna.factory.GunFactory.EnumAmmoSecret;
import com.hbm.items.weapon.sedna.factory.GunFactory.EnumModGeneric;
@ -336,23 +331,5 @@ public class WeaponRecipes {
CraftingManager.addRecipeAuto(new ItemStack(ModBlocks.lamp_demon, 1), new Object[] { " D ", "S S", 'D', ModItems.demon_core_closed, 'S', STEEL.ingot() });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.crucible, 1, 3), new Object[] { "MEM", "YDY", "YCY", 'M', ModItems.ingot_meteorite_forged, 'E', EUPH.ingot(), 'Y', ModItems.billet_yharonite, 'D', ModItems.demon_core_closed, 'C', ModItems.ingot_chainsteel });
// that's a few hundred recipes. is this a good idea? the recipe lookup is slow as molasses because this asshole iterates over every fucking recipe to find a match
// mayhaps we need to invest into a custom solution because right now this might end up badly
for(EnumGrenadeShell shell : EnumGrenadeShell.values()) for(EnumGrenadeFilling filling : EnumGrenadeFilling.values()) {
if(filling.compatibleShells.contains(shell)) for(EnumGrenadeFuze fuze : EnumGrenadeFuze.values()) {
CraftingManager.addShapelessAuto(ItemGrenadeUniversal.make(shell, filling, fuze), new Object[] {
new ItemStack(ModItems.grenade_shell, 1, shell.ordinal()),
new ItemStack(ModItems.grenade_filling, 1, filling.ordinal()),
new ItemStack(ModItems.grenade_fuze, 1, fuze.ordinal()) });
for(EnumGrenadeExtra extra : EnumGrenadeExtra.values()) CraftingManager.addShapelessAuto(ItemGrenadeUniversal.make(shell, filling, fuze, extra), new Object[] {
new ItemStack(ModItems.grenade_shell, 1, shell.ordinal()),
new ItemStack(ModItems.grenade_filling, 1, filling.ordinal()),
new ItemStack(ModItems.grenade_fuze, 1, fuze.ordinal()),
new ItemStack(ModItems.grenade_extra, 1, extra.ordinal())});
}
}
}
}

View File

@ -0,0 +1,79 @@
package com.hbm.crafting.handlers;
import com.hbm.items.ModItems;
import com.hbm.items.weapon.grenade.ItemGrenadeExtra.EnumGrenadeExtra;
import com.hbm.items.weapon.grenade.ItemGrenadeFilling.EnumGrenadeFilling;
import com.hbm.items.weapon.grenade.ItemGrenadeFuze.EnumGrenadeFuze;
import com.hbm.items.weapon.grenade.ItemGrenadeShell.EnumGrenadeShell;
import com.hbm.items.weapon.grenade.ItemGrenadeUniversal;
import com.hbm.util.EnumUtil;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class GrenadeCraftingHandler implements IRecipe {
@Override
public boolean matches(InventoryCrafting inv, World world) {
if(hasForeignObject(inv)) return false; // can't be non-grenade items and can't be more than 4 items total
EnumGrenadeShell shell = getFirst(inv, ModItems.grenade_shell, EnumGrenadeShell.class); // only one shell, null otherwise
EnumGrenadeFilling filling = getFirst(inv, ModItems.grenade_filling, EnumGrenadeFilling.class); // only one filling, null otherwise
EnumGrenadeFuze fuze = getFirst(inv, ModItems.grenade_fuze, EnumGrenadeFuze.class); // only one fuze, null otherwise
// this leaves the extra unaccounted for, but the restrictions we put in place will allow exactly one without dedicated check
return shell != null && filling != null && fuze != null;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
EnumGrenadeShell shell = getFirst(inv, ModItems.grenade_shell, EnumGrenadeShell.class);
EnumGrenadeFilling filling = getFirst(inv, ModItems.grenade_filling, EnumGrenadeFilling.class);
EnumGrenadeFuze fuze = getFirst(inv, ModItems.grenade_fuze, EnumGrenadeFuze.class);
EnumGrenadeExtra extra = getFirst(inv, ModItems.grenade_extra, EnumGrenadeExtra.class); // if this is null, then we don't care, MAKE works with a null extra too
return ItemGrenadeUniversal.make(shell, filling, fuze, extra);
}
@Override
public int getRecipeSize() {
return 4;
}
// why write the same crap four times when you can just use your massive cock instead
public static <T extends Enum> T getFirst(InventoryCrafting inv, Item itemType, Class<? extends T> type) { // god i love generics
T firstShell = null;
for(int i = 0; i < 9; i++) {
ItemStack stack = inv.getStackInRowAndColumn(i % 3, i / 3);
if(stack == null) continue;
if(stack.getItem() == itemType) {
if(firstShell != null) return null;
firstShell = EnumUtil.grabEnumSafely(type, stack.getItemDamage());
}
}
return firstShell;
}
// this should weed out non-grenade grids quickly as to not waste too much CPU time
public static boolean hasForeignObject(InventoryCrafting inv) {
int itemCount = 0;
for(int i = 0; i < 9; i++) {
ItemStack stack = inv.getStackInRowAndColumn(i % 3, i / 3);
if(stack == null) continue;
if(stack.getItem() != ModItems.grenade_shell &&
stack.getItem() != ModItems.grenade_filling &&
stack.getItem() != ModItems.grenade_fuze &&
stack.getItem() != ModItems.grenade_extra) return true;
itemCount++;
if(itemCount > 4) return true;
}
return false;
}
@Override
public ItemStack getRecipeOutput() {
return new ItemStack(ModItems.grenade_universal);
}
}

View File

@ -0,0 +1,48 @@
package com.hbm.handler;
import com.hbm.lib.RefStrings;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.event.world.ChunkDataEvent;
public class BlockMigrations {
private static final String NBT_KEY_BUILD_NUMBER = "hfr_migrations_version";
private static int buildNumber = -1;
public static int buildNumber() {
if(buildNumber != -1) return buildNumber;
String versionString = RefStrings.VERSION.substring(RefStrings.VERSION.indexOf('(') + 1, RefStrings.VERSION.indexOf(')'));
try {
buildNumber = Integer.parseInt(versionString);
} catch(Exception ex) { }
return buildNumber;
}
@SubscribeEvent
public void onChunkLoad(ChunkDataEvent.Load event) {
// if no build number for migrations has been found, we assume this is a freshly generated chunk, so we skip the migrations.
// side effect is that migrations will not work when the starting version is one from before the current migrations system.
// we are in this for the long game anyway, so i'd wager this isn't that big of an issue.
if(!event.getData().hasKey(NBT_KEY_BUILD_NUMBER)) return;
int prevBuildNo = event.getData().getInteger(NBT_KEY_BUILD_NUMBER);
if(prevBuildNo != buildNumber) try { doMigraion(event.getChunk()); } catch(Exception ex) { }
}
@SubscribeEvent
public void onChunkSave(ChunkDataEvent.Save event) {
event.getData().setInteger(NBT_KEY_BUILD_NUMBER, buildNumber);
}
public static void doMigraion(Chunk chunk) {
for(int x = 0; x < 16; x++) for(int z = 0; z < 16; z++) {
// save ourselves a ton of iterations by optimizing all this air away
for(int y = chunk.getHeightValue(x, z); y >= 0; y++) {
}
}
}
}

View File

@ -1,11 +1,10 @@
package com.hbm.handler.nei;
import java.util.Map.Entry;
import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.recipes.AnnihilatorRecipes;
import com.hbm.items.ModItems;
import com.hbm.util.InventoryUtil;
import com.hbm.util.Tuple.Pair;
import codechicken.nei.NEIServerUtils;
import net.minecraft.item.ItemStack;
@ -24,7 +23,7 @@ public class AnnihilatorHandler extends NEIUniversalHandler {
@Override
public void loadCraftingRecipes(ItemStack result) {
outer: for(Entry<Object, Object> recipe : recipes.entrySet()) {
outer: for(Pair<Object, Object> recipe : recipes) {
ItemStack[][] ins = InventoryUtil.extractObject(recipe.getKey());
ItemStack[][] outs = InventoryUtil.extractObject(recipe.getValue());

View File

@ -0,0 +1,111 @@
package com.hbm.handler.nei;
import java.util.ArrayList;
import com.hbm.inventory.OreDictManager.DictFrame;
import com.hbm.items.ModItems;
import com.hbm.items.weapon.grenade.ItemGrenadeExtra.EnumGrenadeExtra;
import com.hbm.items.weapon.grenade.ItemGrenadeFilling.EnumGrenadeFilling;
import com.hbm.items.weapon.grenade.ItemGrenadeFuze.EnumGrenadeFuze;
import com.hbm.items.weapon.grenade.ItemGrenadeShell.EnumGrenadeShell;
import com.hbm.util.EnumUtil;
import com.hbm.items.weapon.grenade.ItemGrenadeUniversal;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
public class GrenadeRecipeHandler extends NEIUniversalHandler {
public GrenadeRecipeHandler() {
super("Grenade Crafting", Blocks.crafting_table, new ArrayList());
}
@Override
public String getKey() {
return "ntmGrenade";
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if(outputId.equals(getKey())) {
for(EnumGrenadeShell shell : EnumGrenadeShell.values()) for(EnumGrenadeFilling filling : EnumGrenadeFilling.values()) {
if(filling.compatibleShells.contains(shell)) for(EnumGrenadeFuze fuze : EnumGrenadeFuze.values()) {
addRecipe(shell, filling, fuze, null);
for(EnumGrenadeExtra extra : EnumGrenadeExtra.values()) addRecipe(shell, filling, fuze, extra);
}
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
if(ingredient.getItem() == ModItems.grenade_shell) {
EnumGrenadeShell shell = EnumUtil.grabEnumSafely(EnumGrenadeShell.class, ingredient.getItemDamage());
for(EnumGrenadeFilling filling : EnumGrenadeFilling.values()) {
if(filling.compatibleShells.contains(shell)) for(EnumGrenadeFuze fuze : EnumGrenadeFuze.values()) {
addRecipe(shell, filling, fuze, null);
for(EnumGrenadeExtra extra : EnumGrenadeExtra.values()) addRecipe(shell, filling, fuze, extra);
}
}
}
if(ingredient.getItem() == ModItems.grenade_filling) {
EnumGrenadeFilling filling = EnumUtil.grabEnumSafely(EnumGrenadeFilling.class, ingredient.getItemDamage());
for(EnumGrenadeShell shell : EnumGrenadeShell.values()) {
if(filling.compatibleShells.contains(shell)) for(EnumGrenadeFuze fuze : EnumGrenadeFuze.values()) {
addRecipe(shell, filling, fuze, null);
for(EnumGrenadeExtra extra : EnumGrenadeExtra.values()) addRecipe(shell, filling, fuze, extra);
}
}
}
if(ingredient.getItem() == ModItems.grenade_fuze) {
EnumGrenadeFuze fuze = EnumUtil.grabEnumSafely(EnumGrenadeFuze.class, ingredient.getItemDamage());
for(EnumGrenadeShell shell : EnumGrenadeShell.values()) for(EnumGrenadeFilling filling : EnumGrenadeFilling.values()) {
if(filling.compatibleShells.contains(shell)) {
addRecipe(shell, filling, fuze, null);
for(EnumGrenadeExtra extra : EnumGrenadeExtra.values()) addRecipe(shell, filling, fuze, extra);
}
}
}
if(ingredient.getItem() == ModItems.grenade_extra) {
EnumGrenadeExtra extra = EnumUtil.grabEnumSafely(EnumGrenadeExtra.class, ingredient.getItemDamage());
for(EnumGrenadeShell shell : EnumGrenadeShell.values()) for(EnumGrenadeFilling filling : EnumGrenadeFilling.values()) {
if(filling.compatibleShells.contains(shell)) for(EnumGrenadeFuze fuze : EnumGrenadeFuze.values()) {
addRecipe(shell, filling, fuze, extra);
}
}
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
if(result == null || result.getItem() != ModItems.grenade_universal) return;
EnumGrenadeShell shell = ItemGrenadeUniversal.getShell(result);
EnumGrenadeFilling filling = ItemGrenadeUniversal.getFilling(result);
EnumGrenadeFuze fuze = ItemGrenadeUniversal.getFuze(result);
EnumGrenadeExtra extra = ItemGrenadeUniversal.getExtra(result);
addRecipe(shell, filling, fuze, extra);
}
public void addRecipe(EnumGrenadeShell shell, EnumGrenadeFilling filling, EnumGrenadeFuze fuze, EnumGrenadeExtra extra) {
ItemStack[][] ins = new ItemStack[extra != null ? 4 : 3][1];
ins[0][0] = DictFrame.fromOne(ModItems.grenade_shell, shell);
ins[1][0] = DictFrame.fromOne(ModItems.grenade_filling, filling);
ins[2][0] = DictFrame.fromOne(ModItems.grenade_fuze, fuze);
if(extra != null) ins[3][0] = DictFrame.fromOne(ModItems.grenade_extra, extra);
ItemStack[][] outs = new ItemStack[][] {{ItemGrenadeUniversal.make(shell, filling, fuze, extra)}};
this.arecipes.add(new RecipeSet(ins, outs, null));
}
}

View File

@ -14,6 +14,7 @@ import com.hbm.handler.imc.ICompatNHNEI;
import com.hbm.items.ModItems;
import com.hbm.lib.RefStrings;
import com.hbm.util.InventoryUtil;
import com.hbm.util.Tuple.Pair;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
@ -23,7 +24,6 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@Deprecated // an experiment that i had to staple more and more features to until it ended up a bloated decaying corpse
public abstract class NEIUniversalHandler extends TemplateRecipeHandler implements ICompatNHNEI {
public LinkedList<RecipeTransferRect> transferRectsRec = new LinkedList<RecipeTransferRect>();
@ -34,24 +34,37 @@ public abstract class NEIUniversalHandler extends TemplateRecipeHandler implemen
/// SETUP ///
public final String display;
public final ItemStack[] machine;
public final HashMap<Object, Object> recipes;
public final List<Pair<Object, Object>> recipes = new ArrayList();
public HashMap<Object, Object> machineOverrides;
/// SETUP ///
public NEIUniversalHandler(String display, ItemStack machine[], HashMap recipes) {
@Deprecated public NEIUniversalHandler(String display, ItemStack machine[], HashMap recipes) {
this.display = display;
this.machine = machine;
this.recipes = recipes;
for(Object e : recipes.entrySet()) this.recipes.add(new Pair(((Entry) e).getKey(), ((Entry) e).getValue()));
this.machineOverrides = null;
}
public NEIUniversalHandler(String display, ItemStack machine[], List recipes) {
this.display = display;
this.machine = machine;
this.recipes.addAll(recipes);
this.machineOverrides = null;
}
public NEIUniversalHandler(String display, HashMap recipes, HashMap machines) {
@Deprecated public NEIUniversalHandler(String display, HashMap recipes, HashMap machines) {
this(display, (ItemStack[]) null, recipes);
this.machineOverrides = machines;
}
public NEIUniversalHandler(String display, List recipes, HashMap machines) {
this(display, (ItemStack[]) null, recipes);
this.machineOverrides = machines;
}
public NEIUniversalHandler(String display, ItemStack machine, HashMap recipes) { this(display, new ItemStack[]{machine}, recipes); }
public NEIUniversalHandler(String display, Item machine, HashMap recipes) { this(display, new ItemStack(machine), recipes); }
public NEIUniversalHandler(String display, Block machine, HashMap recipes) { this(display, new ItemStack(machine), recipes); }
@Deprecated public NEIUniversalHandler(String display, ItemStack machine, HashMap recipes) { this(display, new ItemStack[]{machine}, recipes); }
@Deprecated public NEIUniversalHandler(String display, Item machine, HashMap recipes) { this(display, new ItemStack(machine), recipes); }
@Deprecated public NEIUniversalHandler(String display, Block machine, HashMap recipes) { this(display, new ItemStack(machine), recipes); }
public NEIUniversalHandler(String display, ItemStack machine, List recipes) { this(display, new ItemStack[]{machine}, recipes); }
public NEIUniversalHandler(String display, Item machine, List recipes) { this(display, new ItemStack(machine), recipes); }
public NEIUniversalHandler(String display, Block machine, List recipes) { this(display, new ItemStack(machine), recipes); }
public class RecipeSet extends TemplateRecipeHandler.CachedRecipe {
@ -279,7 +292,7 @@ public abstract class NEIUniversalHandler extends TemplateRecipeHandler implemen
if(outputId.equals(getKey())) {
outer: for(Entry<Object, Object> recipe : recipes.entrySet()) {
outer: for(Pair<Object, Object> recipe : recipes) {
ItemStack[][] ins = InventoryUtil.extractObject(recipe.getKey());
ItemStack[][] outs = InventoryUtil.extractObject(recipe.getValue());
@ -297,7 +310,7 @@ public abstract class NEIUniversalHandler extends TemplateRecipeHandler implemen
@Override
public void loadCraftingRecipes(ItemStack result) {
outer: for(Entry<Object, Object> recipe : recipes.entrySet()) {
outer: for(Pair<Object, Object> recipe : recipes) {
ItemStack[][] ins = InventoryUtil.extractObject(recipe.getKey());
ItemStack[][] outs = InventoryUtil.extractObject(recipe.getValue());
@ -328,7 +341,7 @@ public abstract class NEIUniversalHandler extends TemplateRecipeHandler implemen
@Override
public void loadUsageRecipes(ItemStack ingredient) {
outer: for(Entry<Object, Object> recipe : recipes.entrySet()) {
outer: for(Pair<Object, Object> recipe : recipes) {
ItemStack[][] ins = InventoryUtil.extractObject(recipe.getKey());
ItemStack[][] outs = InventoryUtil.extractObject(recipe.getValue());

View File

@ -75,12 +75,14 @@ public class CraftingManager {
GameRegistry.addRecipe(new MKUCraftingHandler());
GameRegistry.addRecipe(new CargoShellCraftingHandler());
GameRegistry.addRecipe(new ScrapsCraftingHandler());
GameRegistry.addRecipe(new GrenadeCraftingHandler());
RecipeSorter.register("hbm:rbmk", RBMKFuelCraftingHandler.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
RecipeSorter.register("hbm:cargo", CargoShellCraftingHandler.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
RecipeSorter.register("hbm:scraps", ScrapsCraftingHandler.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
RecipeSorter.register("hbm:mku", MKUCraftingHandler.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped before:minecraft:shapeless");
RecipeSorter.register("hbm:containerupgrade", ContainerUpgradeCraftingHandler.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped before:minecraft:shapeless");
RecipeSorter.register("hbm:grenades", GrenadeCraftingHandler.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
}
public static void AddCraftingRec() {

View File

@ -643,6 +643,10 @@ public class MainRegistry {
MinecraftForge.EVENT_BUS.register(neutronHandler);
FMLCommonHandler.instance().bus().register(neutronHandler);
BlockMigrations migrations = new BlockMigrations();
MinecraftForge.EVENT_BUS.register(migrations);
FMLCommonHandler.instance().bus().register(migrations);
if(event.getSide() == Side.CLIENT) {
HbmKeybinds.register();
HbmKeybinds keyHandler = new HbmKeybinds();

View File

@ -50,6 +50,7 @@ public class NEIRegistry {
handlers.add(new RBMKRodDisassemblyHandler());
handlers.add(new RBMKWasteDecayHandler());
handlers.add(new SatelliteHandler());
handlers.add(new GrenadeRecipeHandler());
//universal boyes
handlers.add(new ZirnoxRecipeHandler());