Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
KasumiNova committed May 31, 2024
2 parents e2a2927 + 2ebd8e2 commit 4c61529
Show file tree
Hide file tree
Showing 59 changed files with 1,346 additions and 96 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build

on: [ push ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up OpenJDK 17
uses: actions/setup-java@v2
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
with:
name: NAE2
path: build/libs/*.jar # Make sure this path matches the location of your build artifacts
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
implementation rfg.deobf("curse.maven:ae2-extended-life-570458:5073329")
implementation rfg.deobf("curse.maven:ae2-extended-life-570458:5378163")
implementation rfg.deobf("curse.maven:ae2-fluid-crafting-rework-623955:4804730")
compileOnlyApi rfg.deobf("curse.maven:baubles-227083:2518667")
compileOnlyApi rfg.deobf("curse.maven:jei-238222:4538010")
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/co/neeve/nae2/NAE2MixinPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public List<String> getMixinConfigs() {

var mixins = new ArrayList<String>();

// Core.
mixins.add("mixins.nae2.json");

for (var feature : Features.values()) {
if (!feature.isEnabled()) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class DenseCraftingCubeModel implements IModel {
private static final ResourceLocation MONITOR_LIGHT_MEDIUM = texture("monitor_light_medium");
private static final ResourceLocation MONITOR_LIGHT_BRIGHT = texture("monitor_light_bright");
private static final ResourceLocation COPROCESSOR_4X_LIGHT = naetexture("coprocessor_4x_light");
private static final ResourceLocation COPROCESSOR_64X_LIGHT = naetexture("coprocessor_16x_light");
private static final ResourceLocation COPROCESSOR_16X_LIGHT = naetexture("coprocessor_64x_light");
private static final ResourceLocation COPROCESSOR_16X_LIGHT = naetexture("coprocessor_16x_light");
private static final ResourceLocation COPROCESSOR_64X_LIGHT = naetexture("coprocessor_64x_light");
private static final ResourceLocation STORAGE_256K_LIGHT = naetexture("crafting_storage_256k_light");
private static final ResourceLocation STORAGE_1024K_LIGHT = naetexture("crafting_storage_1024k_light");
private static final ResourceLocation STORAGE_4096K_LIGHT = naetexture("crafting_storage_4096k_light");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package co.neeve.nae2.common.crafting.patterntransform;

import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import co.neeve.nae2.common.crafting.patterntransform.transformers.IPatternTransformer;
import co.neeve.nae2.common.items.NAEBaseItemUpgrade;
import co.neeve.nae2.common.registration.definitions.Upgrades;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Unique;

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

public class PatternTransform {
protected final static List<IPatternTransformer> transformers = new ArrayList<>();

public static void registerTransformer(IPatternTransformer transformer) {
transformers.add(transformer);
}

public static ICraftingPatternDetails transform(ICraftingMedium medium, ICraftingPatternDetails pattern) {
final var originalInputs = pattern.getInputs();
final var originalOutputs = pattern.getOutputs();
var inputs = originalInputs;
var outputs = originalOutputs;

for (var transformer : transformers) {
if (!transformer.shouldTransform(medium, pattern)) continue;

inputs = transformer.transformInputs(medium, pattern, inputs);
outputs = transformer.transformOutputs(medium, pattern, outputs);
}

if (!Arrays.equals(inputs, originalInputs) || !Arrays.equals(outputs, originalOutputs)) {
return new PatternTransformWrapper(pattern, inputs, outputs);
}
return pattern;
}

@Unique
public static boolean isTransformer(ItemStack is) {
return is.getItem() instanceof NAEBaseItemUpgrade upgrade &&
upgrade.getType(is) == Upgrades.UpgradeType.GREGTECH_CIRCUIT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package co.neeve.nae2.common.crafting.patterntransform;

import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class PatternTransformWrapper implements ICraftingPatternDetails {
private final IAEItemStack[] condensedInputs;
private final IAEItemStack[] condensedOutputs;
private final ICraftingPatternDetails delegate;
private final IAEItemStack[] inputs;
private final IAEItemStack[] outputs;

public PatternTransformWrapper(ICraftingPatternDetails delegate, IAEItemStack[] inputs, IAEItemStack[] outputs) {
this.delegate = delegate;
this.inputs = inputs;
this.outputs = outputs;

this.condensedInputs = new IAEItemStack[inputs.length];
var offset = 0;

IAEItemStack io;
Iterator<IAEItemStack> iterator;
for (iterator = Arrays.stream(inputs).iterator(); iterator.hasNext(); ++offset) {
io = iterator.next();
this.condensedInputs[offset] = io;
}

offset = 0;
this.condensedOutputs = new IAEItemStack[outputs.length];

for (iterator = Arrays.stream(outputs).iterator(); iterator.hasNext(); ++offset) {
io = iterator.next();
this.condensedOutputs[offset] = io;
}
}

@Override
public ItemStack getPattern() {return this.delegate.getPattern();}

@Override
public boolean isValidItemForSlot(int i, ItemStack itemStack, World world) {
return this.delegate.isValidItemForSlot(i,
itemStack,
world);
}

@Override
public boolean isCraftable() {return this.delegate.isCraftable();}

@Override
public boolean canSubstitute() {return this.delegate.canSubstitute();}

@Override
public List<IAEItemStack> getSubstituteInputs(int slot) {return this.delegate.getSubstituteInputs(slot);}

@Override
public ItemStack getOutput(InventoryCrafting inventoryCrafting, World world) {
return this.delegate.getOutput(inventoryCrafting,
world);
}

@Override
public int getPriority() {return this.delegate.getPriority();}

@Override
public void setPriority(int i) {this.delegate.setPriority(i);}

@Override
public IAEItemStack[] getCondensedInputs() {
return this.condensedInputs;
}

@Override
public IAEItemStack[] getInputs() {
return this.inputs;
}

@Override
public IAEItemStack[] getCondensedOutputs() {
return this.condensedOutputs;
}

@Override
public IAEItemStack[] getOutputs() {
return this.outputs;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PatternTransformWrapper that)) return false;
return Arrays.equals(this.condensedInputs, that.condensedInputs) && Arrays.equals(this.condensedOutputs,
that.condensedOutputs) && Objects.equals(this.delegate, that.delegate) && Arrays.equals(this.inputs,
that.inputs) && Arrays.equals(this.outputs, that.outputs);
}

@Override
public int hashCode() {
var result = Objects.hash(this.delegate);
result = 31 * result + Arrays.hashCode(this.condensedInputs);
result = 31 * result + Arrays.hashCode(this.condensedOutputs);
result = 31 * result + Arrays.hashCode(this.inputs);
result = 31 * result + Arrays.hashCode(this.outputs);
return result;
}

public ICraftingPatternDetails getDelegate() {
return this.delegate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package co.neeve.nae2.common.crafting.patterntransform.transformers;

import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import co.neeve.nae2.common.interfaces.IExtendedUpgradeInventory;
import co.neeve.nae2.common.registration.definitions.Upgrades;
import gregtech.api.recipes.ingredients.IntCircuitIngredient;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

public class GregTechCircuitPatternTransformer implements IPatternTransformer {
public static Optional<Integer> getCircuitValueFromDetails(ICraftingPatternDetails details) {
var optCircuit = Arrays.stream(details.getInputs())
.filter(Objects::nonNull)
.filter(ais -> IntCircuitIngredient.isIntegratedCircuit(ais.createItemStack()))
.findFirst();

if (!optCircuit.isPresent()) return Optional.empty();

var circuit = optCircuit.get();
var config = IntCircuitIngredient.getCircuitConfiguration(circuit.createItemStack());
return Optional.of(config);
}

@NotNull
protected static IAEItemStack[] filterCircuitsOut(IAEItemStack[] inputs) {
if (inputs == null) return null;

return Arrays.stream(inputs)
.filter(Objects::nonNull)
.filter(x -> !IntCircuitIngredient.isIntegratedCircuit(x.createItemStack()))
.toArray(IAEItemStack[]::new);
}

@Override
public boolean shouldTransform(ICraftingMedium medium, ICraftingPatternDetails details) {
if (details.isCraftable()) return false;

var optCircuit = getCircuitValueFromDetails(details);
if (!optCircuit.isPresent()) return false;

return medium instanceof IUpgradeableHost upgradeableHost
&& upgradeableHost.getInventoryByName("upgrades") instanceof IExtendedUpgradeInventory naeUpgrades
&& naeUpgrades.getInstalledUpgrades(Upgrades.UpgradeType.GREGTECH_CIRCUIT) > 0;
}

@Override
public IAEItemStack[] transformInputs(ICraftingMedium medium, ICraftingPatternDetails details,
IAEItemStack[] inputs) {
return filterCircuitsOut(inputs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.neeve.nae2.common.crafting.patterntransform.transformers;

import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;

public interface IPatternTransformer {
default IAEItemStack[] transformInputs(ICraftingMedium medium, ICraftingPatternDetails details,
IAEItemStack[] inputs) {
return inputs;
}

default IAEItemStack[] transformOutputs(ICraftingMedium medium, ICraftingPatternDetails details,
IAEItemStack[] outputs) {
return outputs;
}

boolean shouldTransform(ICraftingMedium medium, ICraftingPatternDetails details);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
package co.neeve.nae2.common.features.subfeatures;

import appeng.util.Platform;
import org.jetbrains.annotations.Nullable;

public enum UpgradeFeatures implements ISubFeature {
HYPER_ACCELERATION("Enable Hyper-Acceleration Upgrade cards", "upgrades.hac");
HYPER_ACCELERATION("Enable Hyper-Acceleration Upgrade cards for ME IO Ports", "upgrades.hac"),
AUTO_COMPLETE("Enable Auto-Complete Upgrade cards for ME Interfaces", "upgrades.autocomplete"),
GREGTECH_CIRCUIT("Enable GregTech Circuit Card for ME Interfaces", "upgrades.gregcircuit") {
@Override
public boolean isEnabled() {
if (!super.isEnabled()) return false;

if (Platform.isModLoaded("gregtech")) {
try {
return Class.forName("gregtech.api.capability.IGhostSlotConfigurable").isInterface();
} catch (Throwable e) {
// :P
}
}

return false;
}
};

private final String description;
private final String mixins;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package co.neeve.nae2.common.helpers;

import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public abstract class CraftingDetailsWrapper implements ICraftingPatternDetails {
protected final ICraftingPatternDetails delegate;

public CraftingDetailsWrapper(ICraftingPatternDetails delegate) {
this.delegate = delegate;
}

@Override
public ItemStack getPattern() {
return this.delegate.getPattern();
}

@Override
public boolean isValidItemForSlot(int i, ItemStack itemStack, World world) {
return this.delegate.isValidItemForSlot(i, itemStack, world);
}

@Override
public boolean isCraftable() {
return this.delegate.isCraftable();
}

@Override
public IAEItemStack[] getInputs() {
return this.delegate.getInputs();
}

@Override
public IAEItemStack[] getCondensedInputs() {
return this.delegate.getCondensedInputs();
}

@Override
public IAEItemStack[] getCondensedOutputs() {
return this.delegate.getCondensedOutputs();
}

@Override
public IAEItemStack[] getOutputs() {
return this.delegate.getOutputs();
}

@Override
public boolean canSubstitute() {
return this.delegate.canSubstitute();
}

@Override
public ItemStack getOutput(InventoryCrafting inventoryCrafting, World world) {
return this.delegate.getOutput(inventoryCrafting, world);
}

@Override
public int getPriority() {
return this.delegate.getPriority();
}

@Override
public void setPriority(int i) {
this.delegate.setPriority(i);
}
}
Loading

0 comments on commit 4c61529

Please sign in to comment.