-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AE2WTLib integration (Wireless Transmutation Terminal)
- Loading branch information
Showing
26 changed files
with
514 additions
and
19 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
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
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,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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/gripe/_90/appliede/integration/DummyIntegrationItem.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,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)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/gripe/_90/appliede/integration/ae2wtlib/AE2WTIntegration.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,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
16
src/main/java/gripe/_90/appliede/integration/ae2wtlib/WTTItem.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,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
40
src/main/java/gripe/_90/appliede/integration/ae2wtlib/WTTMenu.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,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; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/gripe/_90/appliede/integration/ae2wtlib/WTTMenuHost.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,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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/gripe/_90/appliede/integration/ae2wtlib/WTTScreen.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,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"))); | ||
} | ||
} |
Oops, something went wrong.