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 Wireless Universal Terminal #88

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up OpenJDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt' # You can choose other OpenJDK distributions.
- name: Build with Gradle
run: ./gradlew build # Ensure your gradlew script is executable
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: NAE2
path: build/libs/*.jar # Make sure this path matches the location of your build artifacts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package co.neeve.nae2.common.api.config;

public enum WirelessTerminalType {
ITEM,
FLUID,
GAS,
CRAFTING,
PATTERN,
INTERFACE,
FLUID_PATTERN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import co.neeve.nae2.common.slots.SlotPatternMultiToolUpgrade;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
import com.glodblock.github.common.item.fake.FakeItemRegister;
import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.InventoryPlayer;
Expand All @@ -40,6 +41,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -327,10 +329,10 @@ public void onSlotChange(Slot s) {
list.set(idx, data);
} else continue;
} else if (fluidReplacement && stack.getItem() instanceof ItemFluidDrop) {
var fluidStack = ItemFluidDrop.getFluidStack(stack);
var fluidStack = FakeItemRegister.getStack(stack);

// This should never be a crafting pattern.
if (fluidStackIn.isFluidEqual(fluidStack)) {
if (fluidStackIn.isFluidEqual(((FluidStack) fluidStack))) {
result = ValidatonResult.OK;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/co/neeve/nae2/common/features/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public boolean isEnabled() {
},
DENSE_CPU_COPROCESSORS("dense.coprocessor"),
DENSE_FLUID_CELLS(),
EXPOSER();
EXPOSER(),
UNIVERSAL_TERMINAL("universalterminal"),;

private String[] mixins;
private EnumSet<? extends ISubFeature> subFeatures = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
package co.neeve.nae2.common.helpers;

import appeng.api.AEApi;
import appeng.util.Platform;
import co.neeve.nae2.common.api.config.WirelessTerminalType;
import com.glodblock.github.loader.FCItems;
import com.mekeng.github.common.ItemAndBlocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;

public class UniversalTerminalHelper {
private final static boolean isMekELoaded = Platform.isModLoaded("mekeng");
public static final List<ItemStack> wirelessTerminals = new ArrayList<>();
public static final List<ItemStack> terminals = new ArrayList<>();
public static final List<WirelessTerminalType> WIRELESS_TERMINAL_TYPE_LIST = Arrays.asList(WirelessTerminalType.values());

private static final boolean isMekEngLoaded = Platform.isModLoaded("mekeng");
private static final boolean isAE2FCLoaded = Platform.isModLoaded("ae2fc");

static {
wirelessTerminals.add(AEApi.instance().definitions().items().wirelessTerminal().maybeStack(1).orElse(null));
wirelessTerminals.add(AEApi.instance().definitions().items().wirelessFluidTerminal().maybeStack(1).orElse(null));
wirelessTerminals.add(AEApi.instance().definitions().items().wirelessCraftingTerminal().maybeStack(1).orElse(null));
wirelessTerminals.add(AEApi.instance().definitions().items().wirelessPatternTerminal().maybeStack(1).orElse(null));

terminals.add(AEApi.instance().definitions().parts().terminal().maybeStack(1).orElse(null));
terminals.add(AEApi.instance().definitions().parts().craftingTerminal().maybeStack(1).orElse(null));
terminals.add(AEApi.instance().definitions().parts().patternTerminal().maybeStack(1).orElse(null));
terminals.add(AEApi.instance().definitions().parts().fluidTerminal().maybeStack(1).orElse(null));

if (isMekEngLoaded) {
wirelessTerminals.add(new ItemStack(ItemAndBlocks.WIRELESS_GAS_TERMINAL));
terminals.add(new ItemStack(ItemAndBlocks.GAS_TERMINAL));
}

if (isAE2FCLoaded) {
wirelessTerminals.add(new ItemStack(FCItems.WIRELESS_FLUID_PATTERN_TERMINAL));
terminals.add(new ItemStack(FCItems.PART_FLUID_PATTERN_TERMINAL));
}
}

public static boolean isWirelessTerminal(ItemStack stack) {
if (stack == ItemStack.EMPTY) return false;

int itemDamage = stack.getItemDamage();
Item item = stack.getItem();

ItemStack wirelessTerminal = AEApi.instance().definitions().items().wirelessTerminal().maybeStack(1).orElse(null);
if (wirelessTerminal != null && wirelessTerminal.getItem() == item && wirelessTerminal.getItemDamage() == itemDamage)
return true;

ItemStack wirelessFluidTerminal = AEApi.instance().definitions().items().wirelessFluidTerminal().maybeStack(1).orElse(null);
if (wirelessFluidTerminal != null && wirelessFluidTerminal.getItem() == item && wirelessFluidTerminal.getItemDamage() == itemDamage)
return true;

if (isMekEngLoaded) {
ItemStack wirelessGasTerminal = new ItemStack(ItemAndBlocks.WIRELESS_GAS_TERMINAL);
if (wirelessGasTerminal.getItem() == item && wirelessGasTerminal.getItemDamage() == itemDamage) return true;
}

if (isAE2FCLoaded) {
ItemStack fluidPatternWirelessTerminal = new ItemStack(FCItems.WIRELESS_FLUID_PATTERN_TERMINAL);
if (fluidPatternWirelessTerminal.getItem() == item && fluidPatternWirelessTerminal.getItemDamage() == itemDamage) return true;
}

ItemStack wirelessCraftingTerminal = AEApi.instance().definitions().items().wirelessCraftingTerminal().maybeStack(1).orElse(null);
if (wirelessCraftingTerminal != null && wirelessCraftingTerminal.getItem() == item && wirelessCraftingTerminal.getItemDamage() == itemDamage)
return true;

ItemStack wirelessPatternTerminal = AEApi.instance().definitions().items().wirelessPatternTerminal().maybeStack(1).orElse(null);
if (wirelessPatternTerminal != null && wirelessPatternTerminal.getItem() == item && wirelessPatternTerminal.getItemDamage() == itemDamage)
return true;

return false;
}

public static boolean isTerminal(ItemStack stack) {
if (stack == ItemStack.EMPTY) return false;

Item item = stack.getItem();
int itemDamage = stack.getItemDamage();

ItemStack terminal = AEApi.instance().definitions().parts().terminal().maybeStack(1).orElse(null);
if (terminal != null && terminal.getItem() == item && terminal.getItemDamage() == itemDamage) return true;

ItemStack fluidTerminal = AEApi.instance().definitions().parts().fluidTerminal().maybeStack(1).orElse(null);
if (fluidTerminal != null && fluidTerminal.getItem() == item && fluidTerminal.getItemDamage() == itemDamage)
return true;

if (isMekEngLoaded) {
ItemStack gasTerminal = new ItemStack(ItemAndBlocks.GAS_TERMINAL);
if (gasTerminal.getItem() == item && gasTerminal.getItemDamage() == itemDamage) return true;
}

if (isAE2FCLoaded) {
ItemStack fluidPatternTerminal = new ItemStack(FCItems.PART_FLUID_PATTERN_TERMINAL);
if (fluidPatternTerminal.getItem() == item && fluidPatternTerminal.getItemDamage() == itemDamage) return true;
}

ItemStack craftingTerminal = AEApi.instance().definitions().parts().craftingTerminal().maybeStack(1).orElse(null);
if (craftingTerminal != null && craftingTerminal.getItem() == item && craftingTerminal.getItemDamage() == itemDamage)
return true;

ItemStack patternTerminal = AEApi.instance().definitions().parts().patternTerminal().maybeStack(1).orElse(null);
if (patternTerminal != null && patternTerminal.getItem() == item && patternTerminal.getItemDamage() == itemDamage)
return true;

ItemStack interfaceTerminal = AEApi.instance().definitions().parts().interfaceTerminal().maybeStack(1).orElse(null);
if (interfaceTerminal != null && interfaceTerminal.getItem() == item && interfaceTerminal.getItemDamage() == itemDamage)
return true;

return false;
}

public static WirelessTerminalType getTerminalType(ItemStack stack) {
if (stack == ItemStack.EMPTY) return null;

Item item = stack.getItem();
int itemDamage = stack.getItemDamage();

ItemStack terminal = AEApi.instance().definitions().parts().terminal().maybeStack(1).orElse(null);
if (terminal != null && terminal.getItem() == item && terminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.ITEM;
}

ItemStack fluidTerminal = AEApi.instance().definitions().parts().fluidTerminal().maybeStack(1).orElse(null);
if (fluidTerminal != null && fluidTerminal.getItem() == item && fluidTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.FLUID;
}

ItemStack craftingTerminal = AEApi.instance().definitions().parts().craftingTerminal().maybeStack(1).orElse(null);
if (craftingTerminal != null && fluidTerminal.getItem() == item && craftingTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.CRAFTING;
}

ItemStack patternTerminal = AEApi.instance().definitions().parts().patternTerminal().maybeStack(1).orElse(null);
if (patternTerminal != null && patternTerminal.getItem() == item && patternTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.PATTERN;
}

ItemStack interfaceTerminal = AEApi.instance().definitions().parts().interfaceTerminal().maybeStack(1).orElse(null);
if (interfaceTerminal != null && interfaceTerminal.getItem() == item && interfaceTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.INTERFACE;
}

//Wireless Terminal

ItemStack wirelessTerminal = AEApi.instance().definitions().items().wirelessTerminal().maybeStack(1).orElse(null);
if (wirelessTerminal != null && wirelessTerminal.getItem() == item && wirelessTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.ITEM;
}

ItemStack wirelessFluidTerminal = AEApi.instance().definitions().items().wirelessFluidTerminal().maybeStack(1).orElse(null);
if (wirelessFluidTerminal != null && wirelessFluidTerminal.getItem() == item && wirelessFluidTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.FLUID;
}

ItemStack wirelessCraftingTerminal = AEApi.instance().definitions().items().wirelessCraftingTerminal().maybeStack(1).orElse(null);
if (wirelessCraftingTerminal != null && wirelessCraftingTerminal.getItem() == item && wirelessCraftingTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.CRAFTING;
}

ItemStack wirelessPatternTerminal = AEApi.instance().definitions().items().wirelessPatternTerminal().maybeStack(1).orElse(null);
if (wirelessPatternTerminal != null && wirelessPatternTerminal.getItem() == item && wirelessPatternTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.PATTERN;
}

ItemStack wirelessInterfaceTerminal = AEApi.instance().definitions().items().wirelessInterfaceTerminal().maybeStack(1).orElse(null);
if (wirelessInterfaceTerminal != null && wirelessInterfaceTerminal.getItem() == item && wirelessInterfaceTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.INTERFACE;
}

//MekEng Integration
if (isMekEngLoaded) {
ItemStack gasTerminal = new ItemStack(ItemAndBlocks.GAS_TERMINAL);
if (gasTerminal.getItem() == item && gasTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.GAS;
}

ItemStack wirelessGasTerminal = new ItemStack(ItemAndBlocks.WIRELESS_GAS_TERMINAL);
if (wirelessGasTerminal.getItem() == item && wirelessGasTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.GAS;
}
}

if (isAE2FCLoaded) {
ItemStack fluidPatternTerminal = new ItemStack(FCItems.PART_FLUID_PATTERN_TERMINAL);
if (fluidPatternTerminal.getItem() == item && fluidPatternTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.FLUID_PATTERN;
}

ItemStack fluidPatternWirelessTerminal = new ItemStack(FCItems.WIRELESS_FLUID_PATTERN_TERMINAL);
if (fluidPatternWirelessTerminal.getItem() == item && fluidPatternWirelessTerminal.getItemDamage() == itemDamage) {
return WirelessTerminalType.FLUID_PATTERN;
}
}

return null;
}

public static boolean isModuleValid(WirelessTerminalType type) {
return switch (type) {
case FLUID_PATTERN -> Platform.isModLoaded("ae2fc");
case GAS -> Platform.isModLoaded("mekeng");
default -> true;
};
}


public static ItemStack changeMode(ItemStack itemStack, EntityPlayer player, NBTTagCompound tag) {
EnumSet<WirelessTerminalType> installedModules = getInstalledModules(itemStack);
int type = tag.getInteger("type");
WirelessTerminalType terminalType;
do {
type = (type + 1) % WIRELESS_TERMINAL_TYPE_LIST.size();
terminalType = WIRELESS_TERMINAL_TYPE_LIST.get(type);

} while (!isModuleValid(terminalType) || !installedModules.contains(terminalType));

tag.setInteger("type", type);

return itemStack;
}

public static EnumSet<WirelessTerminalType> getInstalledModules(ItemStack itemStack) {
if (itemStack == ItemStack.EMPTY || itemStack.getItem() == ItemStack.EMPTY.getItem()) {
return EnumSet.noneOf(WirelessTerminalType.class);
}

NBTTagCompound tag = Platform.openNbtData(itemStack);
int installed = tag.hasKey("modules") ? tag.getInteger("modules") : 0;

EnumSet<WirelessTerminalType> set = EnumSet.noneOf(WirelessTerminalType.class);

for (WirelessTerminalType x : WirelessTerminalType.values()) {
if ((installed >> x.ordinal()) % 2 == 1) {
set.add(x);
}
}

return set;
}

public static boolean isInstalled(ItemStack itemStack, WirelessTerminalType module) {
if (itemStack == ItemStack.EMPTY || itemStack.getItem() == ItemStack.EMPTY.getItem()) {
return false;
}

NBTTagCompound tag = Platform.openNbtData(itemStack);
int installed = tag.hasKey("modules") ? tag.getInteger("modules") : 0;

return 1 == (installed >>> module.ordinal()) % 2;
}

public static void installModule(ItemStack itemStack, WirelessTerminalType module) {
if (isInstalled(itemStack, module) || itemStack == ItemStack.EMPTY) {
return;
}

int install = 1 << module.ordinal();

NBTTagCompound tag = Platform.openNbtData(itemStack);

int installed;
if (tag.hasKey("modules")) {
installed = tag.getInteger("modules") + install;
} else {
installed = install;
}

tag.setInteger("modules", installed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import appeng.api.definitions.IItemDefinition;
import appeng.api.implementations.items.IStorageCell;
import co.neeve.nae2.common.features.Features;
import co.neeve.nae2.common.features.subfeatures.JEIFeatures;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
Expand All @@ -16,6 +17,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -108,5 +110,13 @@ public void register(@NotNull IModRegistry registry) {
for (var blacklistEntry : ingredientBlacklist) {
blacklistEntry.maybeStack(1).ifPresent(blacklist::addIngredientToBlacklist);
}

if (Features.UNIVERSAL_TERMINAL.isEnabled()) {
List<UniversalTerminalRecipeWrapper> recipeWrappers = new ArrayList<>();
recipeWrappers.add(new UniversalTerminalRecipeWrapper(true));
recipeWrappers.add(new UniversalTerminalRecipeWrapper(false));

registry.addRecipes(recipeWrappers,VanillaRecipeCategoryUid.CRAFTING);
}
}
}
Loading