forked from AE2-UEL/NAE2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
59 changed files
with
1,346 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/main/java/co/neeve/nae2/common/crafting/patterntransform/PatternTransformWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...nae2/common/crafting/patterntransform/transformers/GregTechCircuitPatternTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...java/co/neeve/nae2/common/crafting/patterntransform/transformers/IPatternTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
20 changes: 19 additions & 1 deletion
20
src/main/java/co/neeve/nae2/common/features/subfeatures/UpgradeFeatures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/co/neeve/nae2/common/helpers/CraftingDetailsWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.