Skip to content

Commit

Permalink
Hide "Store EMC" tooltip on non-transmutation terminals
Browse files Browse the repository at this point in the history
also some other slight rearrangement
  • Loading branch information
62832 committed May 9, 2024
1 parent ae6a4fa commit 417d836
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gripe/_90/appliede/AppliedE.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public final class AppliedE {
// external storage strategy not provided so as not to clash with service's mounted EMC storage
StackImportStrategy.register(EMCKeyType.TYPE, EMCImportStrategy::new);
StackExportStrategy.register(EMCKeyType.TYPE, EMCExportStrategy::new);
ContainerItemStrategy.register(EMCKeyType.TYPE, EMCKey.class, new EMCContainerItemStrategy());
ContainerItemStrategy.register(EMCKeyType.TYPE, EMCKey.class, EMCContainerItemStrategy.INSTANCE);

return part(EMCModulePart.class, EMCModulePart::new);
});
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/gripe/_90/appliede/integration/Addons.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.LoadingModList;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import net.minecraftforge.forgespi.language.IModInfo;

public enum Addons {
TEAMPE("teamprojecte"),
Expand All @@ -22,6 +22,8 @@ public String getModId() {
public boolean isLoaded() {
return ModList.get() != null
? ModList.get().isLoaded(modId)
: LoadingModList.get().getMods().stream().map(ModInfo::getModId).anyMatch(modId::equals);
: LoadingModList.get().getMods().stream()
.map(IModInfo::getModId)
.anyMatch(modId::equals);
}
}
11 changes: 5 additions & 6 deletions src/main/java/gripe/_90/appliede/me/service/EMCStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ public long extract(AEKey what, long amount, Actionable mode, IActionSource sour
return extracted.divide(multiplier).longValue();
}

public long insertItem(AEItemKey what, long amount, Actionable mode, IActionSource source, boolean mayLearn) {
return insertItem(what, amount, mode, source, mayLearn, () -> {});
}

public long insertItem(
AEItemKey what, long amount, Actionable mode, IActionSource source, boolean mayLearn, Runnable onLearn) {
if (service.getProviders().isEmpty()) {
Expand Down Expand Up @@ -215,8 +211,7 @@ public long insertItem(
source.machine().ifPresent(host -> {
if (machineOwnerProvider != null) {
var node = Objects.requireNonNull(host.getActionableNode());
var id = node.getOwningPlayerId();
var player = IPlayerRegistry.getConnected(node.getLevel().getServer(), id);
var player = IPlayerRegistry.getConnected(node.getLevel().getServer(), node.getOwningPlayerId());
addKnowledge(what, machineOwnerProvider.get(), player);
}
});
Expand All @@ -226,6 +221,10 @@ public long insertItem(
return totalInserted;
}

public long insertItem(AEItemKey what, long amount, Actionable mode, IActionSource source, boolean mayLearn) {
return insertItem(what, amount, mode, source, mayLearn, () -> {});
}

public long extractItem(AEItemKey what, long amount, Actionable mode, IActionSource source, boolean skipStored) {
if (source.player().isPresent()
&& !(source.player().get().containerMenu instanceof TransmutationTerminalMenu)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

@SuppressWarnings("UnstableApiUsage")
public class EMCContainerItemStrategy implements ContainerItemStrategy<EMCKey, ItemStack> {
public static final EMCContainerItemStrategy INSTANCE = new EMCContainerItemStrategy();

private EMCContainerItemStrategy() {}

@Nullable
@Override
public GenericStack getContainedStack(ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public EMCItemImportStrategy(ServerLevel level, BlockPos fromPos, Direction from

@Override
public boolean transfer(StackTransferContext context) {
if (!(context instanceof EMCItemTransferContext emc)) {
if (!(context instanceof EMCItemTransferContext ctx)) {
return false;
}

Expand All @@ -36,7 +36,7 @@ public boolean transfer(StackTransferContext context) {
}

var adjacentStorage = ExternalStorageFacade.of(itemHandler);
var remaining = emc.getOperationsRemaining();
var remaining = ctx.getOperationsRemaining();

for (var i = 0; i < adjacentStorage.getSlots() && remaining > 0; i++) {
var resource = adjacentStorage.getStackInSlot(i);
Expand All @@ -52,8 +52,8 @@ public boolean transfer(StackTransferContext context) {
var amount = adjacentStorage.extract(item, remaining, Actionable.SIMULATE, context.getActionSource());

if (amount > 0) {
var inserted = emc.getEmcStorage()
.insertItem(item, amount, Actionable.MODULATE, context.getActionSource(), emc.canLearn());
var inserted = ctx.getEmcStorage()
.insertItem(item, amount, Actionable.MODULATE, context.getActionSource(), ctx.canLearn());
adjacentStorage.extract(item, inserted, Actionable.MODULATE, context.getActionSource());
context.reduceOperationsRemaining(inserted);
remaining -= (int) inserted;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gripe._90.appliede.mixin.main;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import appeng.api.stacks.AEKey;
import appeng.client.gui.me.common.MEStorageScreen;
import appeng.menu.me.common.MEStorageMenu;

import gripe._90.appliede.me.key.EMCKey;
import gripe._90.appliede.menu.TransmutationTerminalMenu;

@Mixin(MEStorageScreen.class)
public abstract class MEStorageScreenMixin {
// spotless:off
@Redirect(
method = "renderTooltip",
at = @At(
value = "INVOKE",
target = "Lappeng/menu/me/common/MEStorageMenu;isKeyVisible(Lappeng/api/stacks/AEKey;)Z",
remap = false))
// spotless:on
private boolean hideEmcKey(MEStorageMenu menu, AEKey what) {
return menu.isKeyVisible(what) && (!(what instanceof EMCKey) || menu instanceof TransmutationTerminalMenu);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/appliede.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
"tooltip.MEInventoryUpdatePacketMixin",
"tooltip.MEStorageMenuMixin"
],
"client": ["tooltip.MEStorageScreenMixin", "tooltip.RepoMixin"]
"client": [
"main.MEStorageScreenMixin",
"tooltip.MEStorageScreenMixin",
"tooltip.RepoMixin"
]
}

0 comments on commit 417d836

Please sign in to comment.