diff --git a/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPattern.java b/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPattern.java index 72e78d2e..ae88cec1 100644 --- a/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPattern.java +++ b/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPattern.java @@ -2,6 +2,7 @@ import java.util.Objects; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import appeng.api.crafting.IPatternDetails; @@ -11,17 +12,21 @@ public class DecompressionPattern implements IPatternDetails { private final AEItemKey definition; - private final AEItemKey compressed; - private final AEItemKey decompressed; + private final AEItemKey base; + private final AEItemKey variant; private final int factor; private final boolean toCompress; + public DecompressionPattern(ItemStack stack) { + this(Objects.requireNonNull(AEItemKey.of(stack))); + } + public DecompressionPattern(AEItemKey definition) { this.definition = definition; var tag = Objects.requireNonNull(definition.getTag()); - compressed = DecompressionPatternEncoding.getCompressed(tag); - decompressed = DecompressionPatternEncoding.getDecompressed(tag); + base = DecompressionPatternEncoding.getBase(tag); + variant = DecompressionPatternEncoding.getVariant(tag); factor = DecompressionPatternEncoding.getFactor(tag); toCompress = DecompressionPatternEncoding.getToCompress(tag); } @@ -33,13 +38,12 @@ public AEItemKey getDefinition() { @Override public IInput[] getInputs() { - return new IInput[] {toCompress ? new Input(decompressed, factor) : new Input(compressed, 1)}; + return new IInput[] {toCompress ? new Input(base, factor) : new Input(variant, 1)}; } @Override public GenericStack[] getOutputs() { - return new GenericStack[] {toCompress ? new GenericStack(compressed, 1) : new GenericStack(decompressed, factor) - }; + return new GenericStack[] {toCompress ? new GenericStack(variant, 1) : new GenericStack(base, factor)}; } @Override diff --git a/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPatternEncoding.java b/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPatternEncoding.java index fceb156d..b7719923 100644 --- a/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPatternEncoding.java +++ b/common/src/main/java/gripe/_90/megacells/crafting/DecompressionPatternEncoding.java @@ -6,20 +6,22 @@ import appeng.api.stacks.AEItemKey; +import gripe._90.megacells.util.CompressionVariant; + public class DecompressionPatternEncoding { - private static final String NBT_COMPRESSED = "compressed"; - private static final String NBT_DECOMPRESSED = "decompressed"; + private static final String NBT_BASE = "base"; + private static final String NBT_VARIANT = "variant"; private static final String NBT_FACTOR = "factor"; private static final String NBT_TO_COMPRESS = "toCompress"; - public static AEItemKey getCompressed(CompoundTag nbt) { - Objects.requireNonNull(nbt, "Pattern must have a compressed tag."); - return AEItemKey.fromTag(nbt.getCompound(NBT_COMPRESSED)); + public static AEItemKey getBase(CompoundTag nbt) { + Objects.requireNonNull(nbt, "Pattern must have a base tag."); + return AEItemKey.fromTag(nbt.getCompound(NBT_BASE)); } - public static AEItemKey getDecompressed(CompoundTag nbt) { - Objects.requireNonNull(nbt, "Pattern must have a decompressed tag."); - return AEItemKey.fromTag(nbt.getCompound(NBT_DECOMPRESSED)); + public static AEItemKey getVariant(CompoundTag nbt) { + Objects.requireNonNull(nbt, "Pattern must have a variant tag."); + return AEItemKey.fromTag(nbt.getCompound(NBT_VARIANT)); } public static int getFactor(CompoundTag nbt) { @@ -32,11 +34,10 @@ public static boolean getToCompress(CompoundTag nbt) { return nbt.getBoolean(NBT_TO_COMPRESS); } - public static void encode( - CompoundTag tag, AEItemKey compressed, AEItemKey decompressed, int factor, boolean toCompress) { - tag.put(NBT_COMPRESSED, compressed.toTag()); - tag.put(NBT_DECOMPRESSED, decompressed.toTag()); - tag.putInt(NBT_FACTOR, factor); + public static void encode(CompoundTag tag, AEItemKey base, CompressionVariant variant, boolean toCompress) { + tag.put(NBT_VARIANT, variant.item().toTag()); + tag.put(NBT_BASE, base.toTag()); + tag.putInt(NBT_FACTOR, variant.factor()); tag.putBoolean(NBT_TO_COMPRESS, toCompress); } } diff --git a/common/src/main/java/gripe/_90/megacells/crafting/DecompressionService.java b/common/src/main/java/gripe/_90/megacells/crafting/DecompressionService.java index fdf71559..896b73c3 100644 --- a/common/src/main/java/gripe/_90/megacells/crafting/DecompressionService.java +++ b/common/src/main/java/gripe/_90/megacells/crafting/DecompressionService.java @@ -15,7 +15,6 @@ import appeng.api.networking.IGridService; import appeng.api.networking.IGridServiceProvider; import appeng.api.networking.crafting.ICraftingProvider; -import appeng.api.stacks.AEItemKey; import gripe._90.megacells.definition.MEGAItems; import gripe._90.megacells.item.cell.BulkCellInventory; @@ -89,9 +88,8 @@ private Set generatePatterns(BulkCellInventory cell) { var pattern = new ItemStack(MEGAItems.DECOMPRESSION_PATTERN); var decompressed = decompressionChain.get(decompressionChain.indexOf(variant) + 1); - DecompressionPatternEncoding.encode( - pattern.getOrCreateTag(), variant.item(), decompressed.item(), variant.factor(), false); - patterns.add(new DecompressionPattern(AEItemKey.of(pattern.getItem(), pattern.getTag()))); + DecompressionPatternEncoding.encode(pattern.getOrCreateTag(), decompressed.item(), variant, false); + patterns.add(new DecompressionPattern(pattern)); } var compressionChain = fullChain.subList(decompressionChain.size() - 1, fullChain.size()); @@ -104,9 +102,8 @@ private Set generatePatterns(BulkCellInventory cell) { var pattern = new ItemStack(MEGAItems.DECOMPRESSION_PATTERN); var decompressed = compressionChain.get(compressionChain.indexOf(variant) - 1); - DecompressionPatternEncoding.encode( - pattern.getOrCreateTag(), variant.item(), decompressed.item(), variant.factor(), true); - patterns.add(new DecompressionPattern(AEItemKey.of(pattern.getItem(), pattern.getTag()))); + DecompressionPatternEncoding.encode(pattern.getOrCreateTag(), decompressed.item(), variant, true); + patterns.add(new DecompressionPattern(pattern)); } return patterns;