Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CC Networking Cable p2p tunnel #702

Merged
merged 9 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// 1.19.2 2024-05-28T14:53:16.653667 Tags for minecraft:item
// 1.19.2 2025-01-20T07:59:27.474151 Tags for minecraft:item
de4b4f45ec18b2b1f0db1c36882981042e20ee23 data/advancedperipherals/tags/items/p2p_attunements/cable_p2p_tunnel.json
72eba3b11f69e16c87488f7c4ba7cfdad42c378e data/advancedperipherals/tags/items/smart_glasses.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2025-01-16T15:59:34.693839 Languages: en_us
d0fe3ab5a88d6b925369860038c76f23d9910143 assets/advancedperipherals/lang/en_us.json
// 1.19.2 2025-01-20T07:50:09.44057 Languages: en_us
ebf2194b8fece940adb61f1ae317f68799bd498f assets/advancedperipherals/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"block.advancedperipherals.rs_bridge": "RS Bridge",
"curios.identifier.glasses": "Glasses",
"entity.minecraft.villager.advancedperipherals.computer_scientist": "Computer Scientist",
"item.advancedperipherals.cable_p2p_tunnel": "Cable P2P Tunnel",
"item.advancedperipherals.chunk_controller": "Chunk Controller",
"item.advancedperipherals.computer_tool": "Computer Tool",
"item.advancedperipherals.end_automata_core": "End Automata Core",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"computercraft:cable",
"computercraft:wired_modem",
"computercraft:wired_modem_full"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
Expand All @@ -35,6 +36,7 @@ public AdvancedPeripherals() {
APConfig.register(ModLoadingContext.get());

modBus.addListener(this::commonSetup);
modBus.addListener(this::onLoadComplete);
APRegistration.register();
MinecraftForge.EVENT_BUS.register(this);
new APAddons();
Expand Down Expand Up @@ -67,4 +69,11 @@ public void commonSetup(FMLCommonSetupEvent event) {
});
}

public void onLoadComplete(FMLLoadCompleteEvent event) {
event.enqueueWork(() -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we maybe want to put this into the APAddons class or into the Integration class direclty

Do we even need a Integration class if the run method is not used? Maybe we want to re-organize that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to do that in Integration.run(), but Integration runs before items get registered...
I'll move them to Registries

Copy link
Member

@SirEndii SirEndii Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is weird
Should happen after item registration

if (APAddons.appliedEnergisticsLoaded) {
de.srendi.advancedperipherals.common.addons.ae2.Integration.onComplete();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,51 @@
@Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class APAddons {

public static final String CURIOS_MODID = "curios";
public static final String REFINEDSTORAGE_MODID = "refinedstorage";
public static final String AE_ADDITIONS_MODID = "ae2additions";
public static final String AE_THINGS_MODID = "ae2things";
public static final String APPLIEDENERGISTICS_MODID = "ae2";
public static final String MEKANISM_MODID = "mekanism";
public static final String AE_ADDITIONS_MODID = "ae2additions";
public static final String APP_MEKANISTICS_MODID = "appmek";
public static final String BOTANIA_MODID = "botania";
public static final String CREATE_MODID = "create";
public static final String CURIOS_MODID = "curios";
public static final String DIMSTORAGE_MODID = "dimstorage";
public static final String MEKANISM_MODID = "mekanism";
public static final String POWAH_MODID = "powah";
public static final String REFINEDSTORAGE_MODID = "refinedstorage";
public static final String VALKYRIEN_SKIES_MODID = "valkyrienskies";

public static boolean curiosLoaded;
public static boolean refinedStorageLoaded;
public static boolean aeAdditionsLoaded;
public static boolean aeThingsLoaded;
public static boolean appMekLoaded;
public static boolean appliedEnergisticsLoaded;
public static boolean botaniaLoaded;
public static boolean createLoaded;
public static boolean curiosLoaded;
public static boolean dimstorageLoaded;
public static boolean mekanismLoaded;
public static boolean aeAdditionsLoaded;
public static boolean appMekLoaded;
public static boolean powahLoaded;
public static boolean refinedStorageLoaded;
public static boolean vs2Loaded;

// Use static so these checks run as early as possible, so we can use them for our registries
static {
ModList modList = ModList.get();
curiosLoaded = modList.isLoaded(CURIOS_MODID);
refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID);
appliedEnergisticsLoaded = modList.isLoaded(APPLIEDENERGISTICS_MODID);
mekanismLoaded = modList.isLoaded(MEKANISM_MODID);
aeThingsLoaded = modList.isLoaded(AE_THINGS_MODID);
aeAdditionsLoaded = modList.isLoaded(AE_ADDITIONS_MODID);
aeThingsLoaded = modList.isLoaded(AE_THINGS_MODID);
appMekLoaded = modList.isLoaded(APP_MEKANISTICS_MODID);
appliedEnergisticsLoaded = modList.isLoaded(APPLIEDENERGISTICS_MODID);
botaniaLoaded = modList.isLoaded(BOTANIA_MODID);
createLoaded = modList.isLoaded(CREATE_MODID);
curiosLoaded = modList.isLoaded(CURIOS_MODID);
dimstorageLoaded = modList.isLoaded(DIMSTORAGE_MODID);
mekanismLoaded = modList.isLoaded(MEKANISM_MODID);
powahLoaded = modList.isLoaded(POWAH_MODID);
refinedStorageLoaded = modList.isLoaded(REFINEDSTORAGE_MODID);
vs2Loaded = modList.isLoaded(VALKYRIEN_SKIES_MODID);

if (refinedStorageLoaded)
if (refinedStorageLoaded) {
RefinedStorage.instance = new RefinedStorage();
}
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.crafting.IPatternDetails;
import appeng.api.inventories.InternalInventory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.features.P2PTunnelAttunement;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;

public class Integration implements Runnable {

@Override
public void run() {
}

public static void onComplete() {
P2PTunnelAttunement.registerAttunementTag(Registries.CABLE_P2P_TUNNEL.get());
}

public static TagKey<Item> getCableP2PTag() {
return P2PTunnelAttunement.getAttunementTag(Registries.CABLE_P2P_TUNNEL.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridNodeListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.srendi.advancedperipherals.common.addons.appliedenergistics;
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.parts.IPart;
import appeng.api.parts.IPartItem;
import appeng.api.parts.PartModels;
import appeng.items.parts.PartItem;
import appeng.items.parts.PartModelsHelper;
import de.srendi.advancedperipherals.common.setup.APRegistration;
import net.minecraft.world.item.Item;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Function;

public final class Registries {
private Registries() {}

public static final RegistryObject<PartItem<WiredCableP2PTunnelPart>> CABLE_P2P_TUNNEL = registerPart("cable_p2p_tunnel", WiredCableP2PTunnelPart.class, WiredCableP2PTunnelPart::new);

private static <T extends IPart> RegistryObject<PartItem<T>> registerPart(String id, Class<T> clazz, Function<IPartItem<T>, T> factory) {
PartModels.registerModels(PartModelsHelper.createModels(clazz));
return APRegistration.ITEMS.register(id, () -> new PartItem<>(new Item.Properties(), clazz, factory));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package de.srendi.advancedperipherals.common.addons.ae2;

import appeng.api.parts.IPartItem;
import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels;
import appeng.parts.p2p.CapabilityP2PTunnelPart;
import appeng.parts.p2p.P2PModels;
import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.network.wired.IWiredNode;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.Capabilities;
import dan200.computercraft.shared.peripheral.modem.wired.WiredModemElement;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;

public class WiredCableP2PTunnelPart extends CapabilityP2PTunnelPart<WiredCableP2PTunnelPart, IWiredElement> {
private static final P2PModels MODELS = new P2PModels(AdvancedPeripherals.getRL("part/p2p/p2p_tunnel_cable"));

private final P2PWiredElement element = new P2PWiredElement();
private final IWiredNode node = this.element.getNode();
private final Set<IWiredNode> connected = new HashSet<>();
private short lastFreq = 0;

public WiredCableP2PTunnelPart(IPartItem<?> partItem) {
super(partItem, Capabilities.CAPABILITY_WIRED_ELEMENT);
this.inputHandler = element;
this.outputHandler = element;
this.emptyHandler = element;
}

@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}

@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}

@Override
public void onTunnelConfigChange() {
this.connectionsChanged();
}

@Override
public void onTunnelNetworkChange() {
this.connectionsChanged();
}

protected void connectionsChanged() {
if (this.lastFreq == this.getFrequency()) {
return;
}
this.lastFreq = this.getFrequency();

for (IWiredNode node : this.connected) {
this.node.disconnectFrom(node);
}
this.connected.clear();

WiredCableP2PTunnelPart in = this.getInput();
if (in != null && in != this) {
this.node.connectTo(in.node);
this.connected.add(in.node);
}
for (WiredCableP2PTunnelPart out : WiredCableP2PTunnelPart.this.getOutputs()) {
if (out != this) {
this.node.connectTo(out.node);
this.connected.add(out.node);
}
}
}

private class P2PWiredElement extends WiredModemElement {
private boolean updating = false;

@Nonnull
@Override
public Level getLevel() {
return WiredCableP2PTunnelPart.this.getLevel();
}

@Nonnull
@Override
public Vec3 getPosition() {
return Vec3.atCenterOf(WiredCableP2PTunnelPart.this.getBlockEntity().getBlockPos());
}

@Nonnull
@Override
public String getSenderID() {
return "p2p";
}

@Override
zyxkad marked this conversation as resolved.
Show resolved Hide resolved
protected void attachPeripheral(String name, IPeripheral peripheral) {
if (this.updating) {
return;
}
this.updating = true;
try {
WiredCableP2PTunnelPart.this.connectionsChanged();
WiredCableP2PTunnelPart in = WiredCableP2PTunnelPart.this.getInput();
if (in != null) {
in.element.attachPeripheral(name, peripheral);
}
for (WiredCableP2PTunnelPart out : WiredCableP2PTunnelPart.this.getOutputs()) {
out.element.attachPeripheral(name, peripheral);
}
} finally {
this.updating = false;
}
}

@Override
protected void detachPeripheral(String name) {
if (this.updating) {
return;
}
this.updating = true;
try {
WiredCableP2PTunnelPart.this.connectionsChanged();
WiredCableP2PTunnelPart in = WiredCableP2PTunnelPart.this.getInput();
if (in != null) {
in.element.detachPeripheral(name);
}
for (WiredCableP2PTunnelPart out : WiredCableP2PTunnelPart.this.getOutputs()) {
out.element.detachPeripheral(name);
}
} finally {
this.updating = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import de.srendi.advancedperipherals.common.addons.APAddons;
import de.srendi.advancedperipherals.common.util.Platform;
import de.srendi.advancedperipherals.lib.integrations.IPeripheralIntegration;
import de.srendi.advancedperipherals.lib.peripherals.BlockEntityIntegrationPeripheral;
Expand All @@ -23,7 +24,15 @@

public class IntegrationPeripheralProvider implements IPeripheralProvider {

private static final String[] SUPPORTED_MODS = new String[]{"botania", "create", "mekanism", "powah", "dimstorage", "valkyrienskies"};
private static final String[] SUPPORTED_MODS = new String[]{
APAddons.APPLIEDENERGISTICS_MODID,
APAddons.BOTANIA_MODID,
APAddons.CREATE_MODID,
APAddons.MEKANISM_MODID,
APAddons.POWAH_MODID,
APAddons.DIMSTORAGE_MODID,
APAddons.VALKYRIEN_SKIES_MODID,
};

private static final PriorityQueue<IPeripheralIntegration> integrations = new PriorityQueue<>(Comparator.comparingInt(IPeripheralIntegration::getPriority));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.core.apis.TableHelper;
import dan200.computercraft.core.computer.ComputerSide;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeFluidHandler;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeItemHandler;
import de.srendi.advancedperipherals.common.addons.ae2.AppEngApi;
import de.srendi.advancedperipherals.common.addons.ae2.CraftJob;
import de.srendi.advancedperipherals.common.addons.ae2.MeFluidHandler;
import de.srendi.advancedperipherals.common.addons.ae2.MeItemHandler;
import de.srendi.advancedperipherals.common.addons.computercraft.owner.BlockEntityPeripheralOwner;
import de.srendi.advancedperipherals.common.blocks.blockentities.MeBridgeEntity;
import de.srendi.advancedperipherals.common.configuration.APConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import appeng.api.stacks.AEItemKey;
import appeng.api.storage.StorageHelper;
import appeng.api.util.AECableType;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.AppEngApi;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.CraftJob;
import de.srendi.advancedperipherals.common.addons.appliedenergistics.MeBridgeEntityListener;
import de.srendi.advancedperipherals.common.addons.ae2.AppEngApi;
import de.srendi.advancedperipherals.common.addons.ae2.CraftJob;
import de.srendi.advancedperipherals.common.addons.ae2.MeBridgeEntityListener;
import de.srendi.advancedperipherals.common.addons.computercraft.peripheral.MeBridgePeripheral;
import de.srendi.advancedperipherals.common.blocks.base.IInventoryBlock;
import de.srendi.advancedperipherals.common.blocks.base.PeripheralBlockEntity;
Expand Down
Loading