Skip to content

Commit

Permalink
Add AE2WTLib integration (Wireless Transmutation Terminal)
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed May 6, 2024
1 parent d1dc3bf commit 54a598c
Show file tree
Hide file tree
Showing 26 changed files with 514 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ jobs:
dependencies: |
ae2(required){curseforge:223794}{modrinth:XxWD5pD3}
projecte(required){curseforge:226410}
ae2wtlib(optional){curseforge:459929}{modrinth:pNabrMMw}
teamprojecte(optional){curseforge:689273}
aecapfix(optional){curseforge:914685}{modrinth:LkfFGNnA}
24 changes: 23 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ repositories {
includeGroup("curse.maven")
}
}

maven {
name = "Shedaniel"
url = uri("https://maven.shedaniel.me/")
content {
includeGroup("me.shedaniel.cloth")
includeGroup("dev.architectury")
}
}

maven {
name = "TheIllusiveC4"
url = uri("https://maven.theillusivec4.top/")
content {
includeGroup("top.theillusivec4.curios")
}
}
}

minecraft {
Expand Down Expand Up @@ -70,8 +87,13 @@ dependencies {
implementation(fg.deobf(libs.ae2.get()))
implementation(fg.deobf(libs.projecte.get()))

implementation(fg.deobf(libs.aecapfix.get()))
implementation(fg.deobf(libs.teampe.get()))
implementation(fg.deobf(libs.ae2wtlib.get()))
implementation(fg.deobf(libs.aecapfix.get()))

runtimeOnly(fg.deobf(libs.curios.get()))
runtimeOnly(fg.deobf(libs.architectury.get()))
runtimeOnly(fg.deobf(libs.cloth.get()))

runtimeOnly(fg.deobf(libs.projectex.get()))
runtimeOnly(fg.deobf(libs.jei.get()))
Expand Down
11 changes: 9 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ dependencyResolutionManagement {
plugin("mixin", "org.spongepowered.mixin").version("0.7.+")
plugin("spotless", "com.diffplug.spotless").version("6.23.3")

library("forge", "net.neoforged", "forge").version("1.20.1-47.1.54")
val minecraftVersion = "1.20.1"

library("forge", "net.neoforged", "forge").version("$minecraftVersion-47.1.54")
library("mixin", "org.spongepowered", "mixin").version("0.8.5")

library("ae2", "appeng", "appliedenergistics2-forge").version("15.1.0")
library("projecte", "curse.maven", "projecte-226410").version("4901949-api-4901951")

library("aecapfix", "curse.maven", "aecapfix-914685").version("5017517")
library("teampe", "curse.maven", "team-projecte-689273").version("5313878")
library("ae2wtlib", "curse.maven", "applied-energistics-2-wireless-terminals-459929").version("5217955")
library("aecapfix", "curse.maven", "aecapfix-914685").version("5017517")

library("curios", "top.theillusivec4.curios", "curios-forge").version("5.9.0+$minecraftVersion")
library("cloth", "me.shedaniel.cloth", "cloth-config-forge").version("11.1.106")
library("architectury", "dev.architectury", "architectury-forge").version("9.1.12")

library("projectex", "curse.maven", "project-expansion-579177").version("5232445")
library("jade", "curse.maven", "jade-324717").version("5072729")
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/gripe/_90/appliede/AppliedE.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
import gripe._90.appliede.client.screen.EMCInterfaceScreen;
import gripe._90.appliede.client.screen.EMCSetStockAmountScreen;
import gripe._90.appliede.client.screen.TransmutationTerminalScreen;
import gripe._90.appliede.integration.Addons;
import gripe._90.appliede.integration.DummyIntegrationItem;
import gripe._90.appliede.integration.ae2wtlib.AE2WTIntegration;
import gripe._90.appliede.me.key.EMCKey;
import gripe._90.appliede.me.key.EMCKeyType;
import gripe._90.appliede.me.misc.LearnAllItemsPacket;
Expand Down Expand Up @@ -121,6 +124,10 @@ public final class AppliedE {
public static final RegistryObject<Item> TRANSMUTATION_TERMINAL = ITEMS.register("transmutation_terminal", () -> part(TransmutationTerminalPart.class, TransmutationTerminalPart::new));
public static final RegistryObject<Item> LEARNING_CARD = ITEMS.register("learning_card", () -> Upgrades.createUpgradeCardItem(new Item.Properties()));

public static final RegistryObject<Item> WIRELESS_TRANSMUTATION_TERMINAL = ITEMS.register("wireless_transmutation_terminal", () -> Addons.AE2WTLIB.isLoaded()
? AE2WTIntegration.createWirelessTerminalItem()
: new DummyIntegrationItem(new Item.Properties().stacksTo(1), Addons.AE2WTLIB));

static {
ITEMS.register("dummy_emc_item", () -> new Item(new Item.Properties()));

Expand All @@ -130,6 +137,10 @@ public final class AppliedE {
MENU_TYPES.register("emc_import_bus", () -> EMCImportBusPart.MENU);
MENU_TYPES.register("transmutation_terminal", () -> TransmutationTerminalMenu.TYPE);

if (Addons.AE2WTLIB.isLoaded()) {
MENU_TYPES.register("wireless_transmutation_terminal", AE2WTIntegration::getWirelessTerminalMenu);
}

TABS.register(MODID, () -> CreativeModeTab.builder()
.title(Component.translatable("mod." + MODID))
.icon(() -> EMC_MODULE.get().getDefaultInstance())
Expand All @@ -141,6 +152,11 @@ public final class AppliedE {
output.accept(EMC_IMPORT_BUS.get());
output.accept(TRANSMUTATION_TERMINAL.get());
output.accept(LEARNING_CARD.get());
output.accept(WIRELESS_TRANSMUTATION_TERMINAL.get());

if (Addons.AE2WTLIB.isLoaded()) {
output.accept(AE2WTIntegration.getChargedTerminal());
}
})
.build());
}
Expand Down Expand Up @@ -188,6 +204,10 @@ public AppliedE() {
registerEMC(AEParts.CABLE_ANCHOR, 32);
});

if (Addons.AE2WTLIB.isLoaded()) {
bus.addListener(AE2WTIntegration::addTerminalToAE2WTLibTab);
}

if (FMLEnvironment.dist.isClient()) {
Client.setup(bus);
}
Expand Down Expand Up @@ -227,6 +247,10 @@ private static void setup(IEventBus bus) {
TransmutationTerminalMenu.TYPE,
TransmutationTerminalScreen<TransmutationTerminalMenu>::new,
"/screens/appliede/transmutation_terminal.json");

if (Addons.AE2WTLIB.isLoaded()) {
AE2WTIntegration.Client.initScreen();
}
});
});

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/gripe/_90/appliede/integration/Addons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gripe._90.appliede.integration;

import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.LoadingModList;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;

public enum Addons {
TEAMPE("teamprojecte"),
AE2WTLIB("ae2wtlib"),
AECAPFIX("aecapfix");

private final String modId;

Addons(String modId) {
this.modId = modId;
}

public String getModId() {
return modId;
}

public boolean isLoaded() {
return ModList.get() != null
? ModList.get().isLoaded(modId)
: LoadingModList.get().getMods().stream().map(ModInfo::getModId).anyMatch(modId::equals);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gripe._90.appliede.integration;

import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;

import org.jetbrains.annotations.Nullable;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;

import gripe._90.appliede.AppliedE;

public class DummyIntegrationItem extends Item {
private final Addons addon;

public DummyIntegrationItem(Properties props, Addons addon) {
super(props);
this.addon = addon;
}

@ParametersAreNonnullByDefault
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> lines, TooltipFlag flag) {
lines.add(Component.translatable("tooltip." + AppliedE.MODID + ".not_installed." + addon.getModId())
.withStyle(ChatFormatting.GRAY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gripe._90.appliede.integration.ae2wtlib;

import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;

import appeng.api.config.Actionable;
import appeng.api.features.GridLinkables;
import appeng.init.client.InitScreens;
import appeng.items.tools.powered.WirelessTerminalItem;

import gripe._90.appliede.AppliedE;
import gripe._90.appliede.integration.Addons;

public class AE2WTIntegration {
public static Item createWirelessTerminalItem() {
var terminal = new WTTItem();
GridLinkables.register(terminal, WirelessTerminalItem.LINKABLE_HANDLER);
return terminal;
}

public static MenuType<?> getWirelessTerminalMenu() {
return WTTMenu.TYPE;
}

public static ItemStack getChargedTerminal() {
var stack = AppliedE.WIRELESS_TRANSMUTATION_TERMINAL.get().getDefaultInstance();

if (stack.getItem() instanceof WirelessTerminalItem terminal) {
terminal.injectAEPower(stack, terminal.getAEMaxPower(stack), Actionable.MODULATE);
return stack;
}

return stack;
}

public static void addTerminalToAE2WTLibTab(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey().location().getNamespace().equals(Addons.AE2WTLIB.getModId())) {
event.accept(AppliedE.WIRELESS_TRANSMUTATION_TERMINAL::get);
event.accept(AE2WTIntegration.getChargedTerminal());
}
}

public static class Client {
public static void initScreen() {
InitScreens.register(
WTTMenu.TYPE, WTTScreen::new, "/screens/appliede/wireless_transmutation_terminal.json");
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/gripe/_90/appliede/integration/ae2wtlib/WTTItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gripe._90.appliede.integration.ae2wtlib;

import org.jetbrains.annotations.NotNull;

import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack;

import de.mari_023.ae2wtlib.terminal.ItemWT;

public class WTTItem extends ItemWT {
@NotNull
@Override
public MenuType<?> getMenuType(@NotNull ItemStack itemStack) {
return WTTMenu.TYPE;
}
}
40 changes: 40 additions & 0 deletions src/main/java/gripe/_90/appliede/integration/ae2wtlib/WTTMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package gripe._90.appliede.integration.ae2wtlib;

import org.jetbrains.annotations.Nullable;

import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.MenuType;

import appeng.api.networking.IGridNode;
import appeng.menu.implementations.MenuTypeBuilder;
import appeng.menu.slot.RestrictedInputSlot;

import de.mari_023.ae2wtlib.AE2wtlibSlotSemantics;
import de.mari_023.ae2wtlib.wut.ItemWUT;

import gripe._90.appliede.menu.TransmutationTerminalMenu;

public class WTTMenu extends TransmutationTerminalMenu {
public static final MenuType<WTTMenu> TYPE =
MenuTypeBuilder.create(WTTMenu::new, WTTMenuHost.class).build("wireless_transmutation_terminal");

public WTTMenu(int id, Inventory ip, WTTMenuHost host) {
super(TYPE, id, ip, host, true);

var singularitySlot = new RestrictedInputSlot(
RestrictedInputSlot.PlacableItemType.QE_SINGULARITY,
host.getSubInventory(WTTMenuHost.INV_SINGULARITY),
0);
addSlot(singularitySlot, AE2wtlibSlotSemantics.SINGULARITY);
}

@Nullable
@Override
public IGridNode getNetworkNode() {
return getHost().getActionableNode();
}

boolean isWUT() {
return ((WTTMenuHost) getHost()).getItemStack().getItem() instanceof ItemWUT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package gripe._90.appliede.integration.ae2wtlib;

import java.util.function.BiConsumer;

import org.jetbrains.annotations.Nullable;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

import appeng.api.implementations.blockentities.IViewCellStorage;
import appeng.api.networking.IGrid;
import appeng.items.tools.powered.WirelessTerminalItem;
import appeng.menu.ISubMenu;

import de.mari_023.ae2wtlib.terminal.WTMenuHost;

import gripe._90.appliede.AppliedE;
import gripe._90.appliede.me.misc.ITransmutationTerminalHost;

public class WTTMenuHost extends WTMenuHost implements IViewCellStorage, ITransmutationTerminalHost {
private final IGrid targetGrid;
private boolean shiftToTransmute;

public WTTMenuHost(
Player player,
@Nullable Integer inventorySlot,
ItemStack is,
BiConsumer<Player, ISubMenu> returnToMainMenu) {
super(player, inventorySlot, is, returnToMainMenu);
this.targetGrid = ((WirelessTerminalItem) is.getItem()).getLinkedGrid(is, player.level(), null);
readFromNbt();
}

@Override
public ItemStack getMainMenuIcon() {
return AppliedE.WIRELESS_TRANSMUTATION_TERMINAL.get().getDefaultInstance();
}

@Override
protected void readFromNbt() {
super.readFromNbt();
shiftToTransmute = getItemStack().getOrCreateTag().getBoolean("shiftToTransmute");
}

@Override
public void saveChanges() {
super.saveChanges();
getItemStack().getOrCreateTag().putBoolean("shiftToTransmute", shiftToTransmute);
}

@Override
public boolean getShiftToTransmute() {
return shiftToTransmute;
}

@Override
public void setShiftToTransmute(boolean toggle) {
shiftToTransmute = toggle;
}

@Nullable
@Override
public IGrid getGrid() {
return targetGrid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gripe._90.appliede.integration.ae2wtlib;

import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;

import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.BackgroundPanel;

import de.mari_023.ae2wtlib.wut.CycleTerminalButton;
import de.mari_023.ae2wtlib.wut.IUniversalTerminalCapable;

import gripe._90.appliede.client.screen.TransmutationTerminalScreen;

public class WTTScreen extends TransmutationTerminalScreen<WTTMenu> implements IUniversalTerminalCapable {
public WTTScreen(WTTMenu menu, Inventory playerInventory, Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);

if (menu.isWUT()) {
addToLeftToolbar(new CycleTerminalButton(btn -> cycleTerminal()));
}

widgets.add("singularityBackground", new BackgroundPanel(style.getImage("singularityBackground")));
}
}
Loading

0 comments on commit 54a598c

Please sign in to comment.