-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c196a59
add cable p2p tunnel
zyxkad 94fa325
remove debug logs
zyxkad 49dc39e
add Overrides
zyxkad 002c447
checkstyle
zyxkad f16ee9c
updated -> updating
zyxkad 91ef22a
Create p2p item model
SirEndii a97a7b9
fix peripheral will not connect when changing tunnel type
zyxkad 04c6f27
fix peripheral will detach and reattach when ME grid changes
zyxkad 2b2f9d1
remove ae2.Integration and rename ae2.Registries to ae2.AE2Registries
zyxkad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/de/srendi/advancedperipherals/common/addons/ae2/Integration.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,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()); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/de/srendi/advancedperipherals/common/addons/ae2/Registries.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,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)); | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
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,169 @@ | ||
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 = outElement; | ||
} | ||
|
||
@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); | ||
} | ||
} | ||
this.sendBlockUpdate(); | ||
} | ||
|
||
@Override | ||
protected void onMainNodeStateChanged(IGridNodeListener.State reason) { | ||
super.onMainNodeStateChanged(reason); | ||
if (this.isActive()) { | ||
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 | ||
zyxkad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) {} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 thatThere was a problem hiding this comment.
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
There was a problem hiding this comment.
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
AdvancedPeripherals/src/main/java/de/srendi/advancedperipherals/common/setup/APRegistration.java
Line 48 in 016c6c2