Skip to content

Commit

Permalink
Mildly refactor pattern and key classes
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Apr 29, 2024
1 parent 7b22e8e commit 6daeb68
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/main/java/gripe/_90/appliede/key/EMCKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@
public final class EMCKey extends AEKey {
private final int tier;

public EMCKey(int tier) {
private EMCKey(int tier) {
if (tier <= 0) {
throw new IllegalArgumentException("Tier must be positive");
}

this.tier = tier;
}

public static EMCKey tier(int tier) {
return new EMCKey(tier);
}

public static EMCKey base() {
return tier(1);
}

public int getTier() {
return tier;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gripe/_90/appliede/key/EMCKeyType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ private EMCKeyType() {

@Override
public AEKey readFromPacket(FriendlyByteBuf input) {
return new EMCKey(input.readVarInt());
return EMCKey.tier(input.readVarInt());
}

@Override
public AEKey loadKeyFromTag(CompoundTag tag) {
return new EMCKey(tag.getInt("tier"));
return EMCKey.tier(tag.getInt("tier"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import appeng.api.stacks.AEItemKey;

import gripe._90.appliede.AppliedE;
import gripe._90.appliede.pattern.TransmutationPattern;

import moze_intel.projecte.api.ItemInfo;
import moze_intel.projecte.api.capabilities.IKnowledgeProvider;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gripe/_90/appliede/module/EMCModulePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@
import appeng.parts.PartModel;

import gripe._90.appliede.AppliedE;
import gripe._90.appliede.pattern.TransmutationPattern;

import moze_intel.projecte.api.event.PlayerKnowledgeChangeEvent;

public final class EMCModulePart extends AEBasePart
implements IStorageProvider, ICraftingProvider, IPriorityHost, IGridTickable {
@PartModels
public static final IPartModel MODEL = new PartModel(AppliedE.id("part/emc_module"));
private static final IPartModel MODEL = new PartModel(AppliedE.id("part/emc_module"));

private final Object2LongMap<AEKey> outputs = new Object2LongOpenHashMap<>();

Expand Down Expand Up @@ -96,7 +95,7 @@ public void mountInventories(IStorageMounts mounts) {
var grid = getMainNode().getGrid();

if (grid != null) {
mounts.mount(grid.getService(KnowledgeService.class).getStorage(this));
mounts.mount(grid.getService(KnowledgeService.class).getStorageToMount(this));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gripe/_90/appliede/module/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public void getAvailableStacks(KeyCounter out) {
var currentTier = 1;

while (emc.divide(AppliedE.TIER_LIMIT).signum() == 1) {
out.add(new EMCKey(currentTier), emc.remainder(AppliedE.TIER_LIMIT).longValue());
out.add(EMCKey.tier(currentTier), emc.remainder(AppliedE.TIER_LIMIT).longValue());
emc = emc.divide(AppliedE.TIER_LIMIT);
currentTier++;
}

out.add(new EMCKey(currentTier), emc.min(AppliedE.TIER_LIMIT).longValue());
out.add(EMCKey.tier(currentTier), emc.min(AppliedE.TIER_LIMIT).longValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public CompositeKnowledgeProvider getKnowledge() {
return knowledge;
}

public MEStorage getStorage(EMCModulePart module) {
public MEStorage getStorage() {
return storage;
}

MEStorage getStorageToMount(EMCModulePart module) {
return !modules.isEmpty() && module.equals(modules.get(0)) ? storage : NullInventory.of();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gripe._90.appliede.pattern;
package gripe._90.appliede.module;

import java.util.Objects;

Expand Down Expand Up @@ -73,7 +73,7 @@ public GenericStack[] getOutputs() {
return new GenericStack[] {
item != null
? new GenericStack(item, 1)
: new GenericStack(new EMCKey(tier - 1), AppliedE.TIER_LIMIT.longValue())
: new GenericStack(EMCKey.tier(tier - 1), AppliedE.TIER_LIMIT.longValue())
};
}

Expand All @@ -90,7 +90,7 @@ public int hashCode() {
private record Input(long amount, int tier) implements IInput {
@Override
public GenericStack[] getPossibleInputs() {
return new GenericStack[] {new GenericStack(new EMCKey(tier), amount)};
return new GenericStack[] {new GenericStack(EMCKey.tier(tier), amount)};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gripe._90.appliede.pattern;
package gripe._90.appliede.module;

import org.jetbrains.annotations.Nullable;

Expand Down

0 comments on commit 6daeb68

Please sign in to comment.