Skip to content
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

Add cell + pattern disassemble recipes like AE2 #257

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/glodblock/github/FluidCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static void postInit(FMLPostInitializationEvent event) {
RecipeLoader.addInfiniteWaterCell();
}
RecipeLoader.runTerminalRecipe();
RecipeLoader.addDisassembleRecipe();

if (ModAndClassUtil.isV2) {
CalculatorV2PluginLoader.installCalculatorV2Plugins();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/glodblock/github/loader/RecipeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import com.glodblock.github.common.Config;
import com.glodblock.github.common.item.FCBaseItemCell;
import com.glodblock.github.common.storage.CellType;
import com.glodblock.github.loader.recipe.DisassembleRecipe;
import com.glodblock.github.loader.recipe.WirelessTerminalEnergyRecipe;
import com.glodblock.github.loader.recipe.WirelessTerminalQuantumBridgeRecipe;
import com.glodblock.github.loader.recipe.WirelessTerminalRecipe;
Expand Down Expand Up @@ -757,4 +758,8 @@ public static void runTerminalRecipe() {
Arrays.stream(term).filter(Objects::nonNull).toArray());

}

public static void addDisassembleRecipe() {
GameRegistry.addRecipe(new DisassembleRecipe());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.glodblock.github.loader.recipe;

import static com.glodblock.github.loader.ItemAndBlockHolder.*;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;

import appeng.api.AEApi;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.util.IterationCounter;
import appeng.util.Platform;

public class DisassembleRecipe implements IRecipe {

private final Map<ItemStack, ItemStack> cellMappings;
private final Map<ItemStack, ItemStack> nonCellMappings;

public DisassembleRecipe() {
this.cellMappings = new HashMap<>(16);
this.nonCellMappings = new HashMap<>(1);

this.cellMappings.put(new ItemStack(CELL1K), new ItemStack(CELL_PART, 1, 0));
this.cellMappings.put(new ItemStack(CELL4K), new ItemStack(CELL_PART, 1, 1));
this.cellMappings.put(new ItemStack(CELL16K), new ItemStack(CELL_PART, 1, 2));
this.cellMappings.put(new ItemStack(CELL64K), new ItemStack(CELL_PART, 1, 3));
this.cellMappings.put(new ItemStack(CELL256K), new ItemStack(CELL_PART, 1, 4));
this.cellMappings.put(new ItemStack(CELL1024K), new ItemStack(CELL_PART, 1, 5));
this.cellMappings.put(new ItemStack(CELL4096K), new ItemStack(CELL_PART, 1, 6));
this.cellMappings.put(new ItemStack(CELL16384K), new ItemStack(CELL_PART, 1, 7));

this.cellMappings.put(new ItemStack(CELL1KM), new ItemStack(CELL_PART, 1, 0));
this.cellMappings.put(new ItemStack(CELL4KM), new ItemStack(CELL_PART, 1, 1));
this.cellMappings.put(new ItemStack(CELL16KM), new ItemStack(CELL_PART, 1, 2));
this.cellMappings.put(new ItemStack(CELL64KM), new ItemStack(CELL_PART, 1, 3));
this.cellMappings.put(new ItemStack(CELL256KM), new ItemStack(CELL_PART, 1, 4));
this.cellMappings.put(new ItemStack(CELL1024KM), new ItemStack(CELL_PART, 1, 5));
this.cellMappings.put(new ItemStack(CELL4096KM), new ItemStack(CELL_PART, 1, 6));
this.cellMappings.put(new ItemStack(CELL16384KM), new ItemStack(CELL_PART, 1, 7));

this.nonCellMappings.put(
new ItemStack(PATTERN),
AEApi.instance().definitions().materials().blankPattern().maybeStack(1).get());
}

@Override
public boolean matches(final InventoryCrafting inv, final World w) {
return this.getOutput(inv) != null;
}

@SuppressWarnings("unchecked")
private ItemStack getOutput(final IInventory inventory) {
int itemCount = 0;
ItemStack output = null;

for (int slotIndex = 0; slotIndex < inventory.getSizeInventory(); slotIndex++) {
final ItemStack stackInSlot = inventory.getStackInSlot(slotIndex);
if (stackInSlot != null) {
// needs a single input in the recipe
itemCount++;
if (itemCount > 1) {
return null;
}

// handle storage cells
final ItemStack storageCellStack = this.getCellOutput(stackInSlot);
if (storageCellStack != null) {
// make sure the storage cell stackInSlot empty...
final IMEInventory<IAEFluidStack> cellInv = AEApi.instance().registries().cell()
.getCellInventory(stackInSlot, null, StorageChannel.FLUIDS);
if (cellInv != null) {
final IItemList<IAEFluidStack> list = cellInv
.getAvailableItems(StorageChannel.FLUIDS.createList(), IterationCounter.fetchNewId());
if (!list.isEmpty()) {
return null;
}
}

output = storageCellStack;
}

// handle crafting storage blocks
final ItemStack craftingStorageStack = this.getNonCellOutput(stackInSlot);
if (craftingStorageStack != null) {
output = craftingStorageStack;
}
}
}

return output;
}

private ItemStack getCellOutput(final ItemStack compared) {
for (final Map.Entry<ItemStack, ItemStack> entry : this.cellMappings.entrySet()) {
if (Platform.isSameItemType(compared, entry.getKey())) {
return entry.getValue().copy();
}
}

return null;
}

private ItemStack getNonCellOutput(final ItemStack compared) {
for (final Map.Entry<ItemStack, ItemStack> entry : this.nonCellMappings.entrySet()) {
if (Platform.isSameItemType(compared, entry.getKey())) {
return entry.getValue().copy();
}
}

return null;
}

@Nullable
@Override
public ItemStack getCraftingResult(final InventoryCrafting inv) {
return this.getOutput(inv);
}

@Override
public int getRecipeSize() {
return 1;
}

@Nullable
@Override
public ItemStack getRecipeOutput() // no default output..
{
return null;
}
}