-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #702 from zyxkad/p2p-feature
add CC Networking Cable p2p tunnel
- Loading branch information
Showing
22 changed files
with
310 additions
and
33 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
src/generated/resources/.cache/03e4de26f1265135874f8cdcaebc09d9c08eb42b
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 |
---|---|---|
@@ -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 |
4 changes: 2 additions & 2 deletions
4
src/generated/resources/.cache/c622617f6fabf890a00b9275cd5f643584a8a2c8
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 |
---|---|---|
@@ -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 |
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
7 changes: 7 additions & 0 deletions
7
...rated/resources/data/advancedperipherals/tags/items/p2p_attunements/cable_p2p_tunnel.json
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,7 @@ | ||
{ | ||
"values": [ | ||
"computercraft:cable", | ||
"computercraft:wired_modem", | ||
"computercraft:wired_modem_full" | ||
] | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/de/srendi/advancedperipherals/common/addons/ae2/AE2Registries.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,42 @@ | ||
package de.srendi.advancedperipherals.common.addons.ae2; | ||
|
||
import appeng.api.features.P2PTunnelAttunement; | ||
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 dan200.computercraft.shared.Registry.ModItems; | ||
import de.srendi.advancedperipherals.common.setup.APRegistration; | ||
import net.minecraft.data.tags.TagsProvider; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
import java.util.function.Function; | ||
|
||
public final class AE2Registries { | ||
private AE2Registries() {} | ||
|
||
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)); | ||
} | ||
|
||
public static void finishRegister() { | ||
P2PTunnelAttunement.registerAttunementTag(CABLE_P2P_TUNNEL.get()); | ||
} | ||
|
||
public static TagKey<Item> getCableP2PTag() { | ||
return P2PTunnelAttunement.getAttunementTag(CABLE_P2P_TUNNEL.get()); | ||
} | ||
|
||
public static void registerTags(Function<TagKey<Item>, TagsProvider.TagAppender<Item>> tagger) { | ||
tagger.apply(getCableP2PTag()) | ||
.add(ModItems.CABLE.get()) | ||
.add(ModItems.WIRED_MODEM.get()) | ||
.add(ModItems.WIRED_MODEM_FULL.get()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../addons/appliedenergistics/AppEngApi.java → ...ipherals/common/addons/ae2/AppEngApi.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
2 changes: 1 addition & 1 deletion
2
...n/addons/appliedenergistics/CraftJob.java → ...ripherals/common/addons/ae2/CraftJob.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
2 changes: 1 addition & 1 deletion
2
...edenergistics/MeBridgeEntityListener.java → ...on/addons/ae2/MeBridgeEntityListener.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
2 changes: 1 addition & 1 deletion
2
...ns/appliedenergistics/MeFluidHandler.java → ...als/common/addons/ae2/MeFluidHandler.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
2 changes: 1 addition & 1 deletion
2
...ons/appliedenergistics/MeItemHandler.java → ...rals/common/addons/ae2/MeItemHandler.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
174 changes: 174 additions & 0 deletions
174
src/main/java/de/srendi/advancedperipherals/common/addons/ae2/WiredCableP2PTunnelPart.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,174 @@ | ||
package de.srendi.advancedperipherals.common.addons.ae2; | ||
|
||
import appeng.api.networking.IGridNodeListener; | ||
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.ComputerCraftAPI; | ||
import dan200.computercraft.api.network.wired.IWiredElement; | ||
import dan200.computercraft.api.network.wired.IWiredNetworkChange; | ||
import dan200.computercraft.api.network.wired.IWiredNode; | ||
import dan200.computercraft.shared.Capabilities; | ||
import de.srendi.advancedperipherals.AdvancedPeripherals; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
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 IWiredElement element = new P2PWiredElement(); | ||
private final IWiredElement outElement = new P2PWiredElement(); | ||
private final IWiredNode node = this.element.getNode(); | ||
private Set<WiredCableP2PTunnelPart> connected = new HashSet<>(); | ||
private boolean activated = false; | ||
|
||
public WiredCableP2PTunnelPart(IPartItem<?> partItem) { | ||
super(partItem, Capabilities.CAPABILITY_WIRED_ELEMENT); | ||
this.inputHandler = outElement; | ||
this.outputHandler = outElement; | ||
this.emptyHandler = null; // should never used | ||
} | ||
|
||
@PartModels | ||
public static List<IPartModel> getModels() { | ||
return MODELS.getModels(); | ||
} | ||
|
||
@Override | ||
public IPartModel getStaticModels() { | ||
return MODELS.getModel(this.isPowered(), this.isActive()); | ||
} | ||
|
||
@Override | ||
public void onTunnelConfigChange() { | ||
super.onTunnelConfigChange(); | ||
this.connectionsChanged(); | ||
} | ||
|
||
@Override | ||
public void onTunnelNetworkChange() { | ||
super.onTunnelNetworkChange(); | ||
this.connectionsChanged(); | ||
} | ||
|
||
protected void connectionsChanged() { | ||
if (this.isClientSide()) { | ||
return; | ||
} | ||
if (!this.isActive()) { | ||
return; | ||
} | ||
if (!this.activated) { | ||
this.activated = true; | ||
this.node.connectTo(this.outElement.getNode()); | ||
} | ||
|
||
Stream<WiredCableP2PTunnelPart> nodeStream = this.getOutputStream().filter(out -> out != this); | ||
WiredCableP2PTunnelPart in = this.getInput(); | ||
if (in != null && in != this) { | ||
nodeStream = Stream.concat(nodeStream, Stream.of(in)); | ||
} | ||
Set<WiredCableP2PTunnelPart> nodes = nodeStream.collect(Collectors.toCollection(HashSet::new)); | ||
|
||
for (WiredCableP2PTunnelPart part : this.connected.stream().filter(n -> !nodes.contains(n)).collect(Collectors.toList())) { | ||
if (part.connected.contains(this)) { | ||
this.node.disconnectFrom(part.node); | ||
part.connected.remove(this); | ||
} | ||
this.connected.remove(part); | ||
} | ||
|
||
for (WiredCableP2PTunnelPart part : nodes) { | ||
if (!this.connected.contains(part)) { | ||
this.node.connectTo(part.node); | ||
this.connected.add(part); | ||
part.connected.add(this); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onMainNodeStateChanged(IGridNodeListener.State reason) { | ||
super.onMainNodeStateChanged(reason); | ||
if (reason == IGridNodeListener.State.GRID_BOOT) { | ||
return; | ||
} | ||
if (this.isActive()) { | ||
if (!this.getMainNode().hasGridBooted()) { | ||
return; | ||
} | ||
this.connectionsChanged(); | ||
this.refreshConnection(); | ||
} else if (this.activated) { | ||
this.activated = false; | ||
this.node.remove(); | ||
this.connected.clear(); | ||
} | ||
} | ||
|
||
protected BlockPos getFacingPos() { | ||
return this.getHost().getLocation().getPos().relative(this.getSide()); | ||
} | ||
|
||
protected void refreshConnection() { | ||
BlockEntity cable = this.getLevel().getBlockEntity(this.getFacingPos()); | ||
IWiredElement elem = cable == null ? null : cable.getCapability(Capabilities.CAPABILITY_WIRED_ELEMENT, this.getSide().getOpposite()).orElse(null); | ||
if (elem == null) { | ||
return; | ||
} | ||
elem.getNode().connectTo(this.outElement.getNode()); | ||
} | ||
|
||
@Override | ||
public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) { | ||
if (!this.getFacingPos().equals(neighbor)) { | ||
return; | ||
} | ||
if (this.activated) { | ||
this.refreshConnection(); | ||
} | ||
} | ||
|
||
private class P2PWiredElement implements IWiredElement { | ||
private final IWiredNode node = ComputerCraftAPI.createWiredNodeForElement(this); | ||
|
||
@Nonnull | ||
@Override | ||
public IWiredNode getNode() { | ||
return node; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getSenderID() { | ||
return "p2p"; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Level getLevel() { | ||
return WiredCableP2PTunnelPart.this.getLevel(); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Vec3 getPosition() { | ||
return Vec3.atCenterOf(WiredCableP2PTunnelPart.this.getBlockEntity().getBlockPos()); | ||
} | ||
|
||
@Override | ||
public void networkChanged(IWiredNetworkChange change) {} | ||
} | ||
} |
Oops, something went wrong.