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 network signal insulators #3963

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -57,6 +57,7 @@ public abstract class Network {
private final Queue<Location> nodeQueue = new ArrayDeque<>();
protected final Set<Location> regulatorNodes = new HashSet<>();
protected final Set<Location> connectorNodes = new HashSet<>();
protected final Set<Location> insulatorNodes = new HashSet<>();
protected final Set<Location> terminusNodes = new HashSet<>();

/**
Expand Down Expand Up @@ -121,7 +122,7 @@ protected Network(@Nonnull NetworkManager manager, @Nonnull Location regulator)
* @return The size of this {@link Network}
*/
public int getSize() {
return regulatorNodes.size() + connectorNodes.size() + terminusNodes.size();
return regulatorNodes.size() + connectorNodes.size() + terminusNodes.size() + insulatorNodes.size();
}

/**
Expand Down Expand Up @@ -181,6 +182,8 @@ public boolean connectsTo(@Nonnull Location l) {
return NetworkComponent.CONNECTOR;
} else if (terminusNodes.contains(l)) {
return NetworkComponent.TERMINUS;
} else if (insulatorNodes.contains(l)) {
return NetworkComponent.INSULATOR;
iTwins marked this conversation as resolved.
Show resolved Hide resolved
}

return null;
Expand All @@ -196,12 +199,15 @@ private void discoverStep() {
NetworkComponent classification = classifyLocation(l);

if (classification != currentAssignment) {
if (currentAssignment == NetworkComponent.REGULATOR || currentAssignment == NetworkComponent.CONNECTOR) {
if (currentAssignment == NetworkComponent.REGULATOR || currentAssignment == NetworkComponent.CONNECTOR || classification == NetworkComponent.INSULATOR) {
// Requires a complete rebuild of the network, so we just throw the current one away.
manager.unregisterNetwork(this);
return;
} else if (currentAssignment == NetworkComponent.TERMINUS) {
terminusNodes.remove(l);
} else if (currentAssignment == NetworkComponent.INSULATOR) {
insulatorNodes.remove(l);
updateNeighbors(l);
}

if (classification == NetworkComponent.REGULATOR) {
Expand All @@ -226,8 +232,13 @@ private void discoverStep() {
}

private void discoverNeighbors(@Nonnull Location l, double xDiff, double yDiff, double zDiff) {
for (int i = getRange() + 1; i > 0; i--) {
for (int i = 1; i <= getRange(); i++) {
Location newLocation = l.clone().add(i * xDiff, i * yDiff, i * zDiff);
if (classifyLocation(newLocation) == NetworkComponent.INSULATOR) {
positions.add(BlockPosition.getAsLong(newLocation));
insulatorNodes.add(newLocation);
return;
}
addLocationToNetwork(newLocation);
}
}
Expand All @@ -241,6 +252,32 @@ private void discoverNeighbors(@Nonnull Location l) {
discoverNeighbors(l, 0.0, 0.0, -1.0);
}

private void updateNeighbors(@Nonnull Location l, double xDiff, double yDiff, double zDiff) {
for (int i = 1; i <= getRange(); i++) {
Location newLocation = l.clone().add(i * xDiff, i * yDiff, i * zDiff);
Comment on lines +256 to +257
Copy link
Member

Choose a reason for hiding this comment

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

Slightly confused by this. What is this method supposed to do?

As it is written I don't see it ever being useful to pass anything but one unitary value (with sign) and two zeros, like you do below, therefore the method only updatesNeighbors in one direction.
But then the question arises on whether this format even makes sense, it would be a lot more readable (though not as compact) if it accepted a BlockFace at that point.

Was the idea just to avoid having to "decode" what versor each BlockFace refers to?

Copy link
Contributor Author

@iTwins iTwins Dec 8, 2023

Choose a reason for hiding this comment

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

This method checks if any Locations need to be added to the network when an insulator is broken.

It indeed is intended to only check the 6 directions in which a network can connect. The reason I went with this signature is because the method is similar to discoverNeighbors and that used the same way of passing the arguments. If you'd rather have the method take a BlockFace I would be happy to change it. Then perhaps discoverNeighbors should also be changed to take a BlockFace for consistency sake.

Copy link
Member

Choose a reason for hiding this comment

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

Oh my god I had not even noticed the other one. If you could make both accept a blockface that would be awesome

NetworkComponent classification = classifyLocation(newLocation);
if (connectsTo(newLocation) && classification == NetworkComponent.CONNECTOR || classification == NetworkComponent.REGULATOR) {
discoverNeighbors(newLocation);
}
}
}

/**
* Make all the nodes that are connected to this network and
* in range of this location rediscover their neighbors.
*
* @param l
* The location to search around
*/
private void updateNeighbors(@Nonnull Location l) {
updateNeighbors(l, 1.0, 0.0, 0.0);
updateNeighbors(l, -1.0, 0.0, 0.0);
updateNeighbors(l, 0.0, 1.0, 0.0);
updateNeighbors(l, 0.0, -1.0, 0.0);
updateNeighbors(l, 0.0, 0.0, 1.0);
updateNeighbors(l, 0.0, 0.0, -1.0);
}

/**
* This method runs the network visualizer which displays a {@link Particle} on
* every {@link Location} that this {@link Network} is connected to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public enum NetworkComponent {
*/
CONNECTOR,

/**
* This represents a node that stops {@link NetworkComponent}s from connecting
*/
INSULATOR,

/**
* This represents the main component of the {@link Network}.
* This node is responsible for managing the {@link Network}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public NetworkComponent classifyLocation(@Nonnull Location l) {
case "CARGO_NODE_INPUT",
"CARGO_NODE_OUTPUT",
"CARGO_NODE_OUTPUT_ADVANCED" -> NetworkComponent.TERMINUS;
case "CARGO_INSULATOR" -> NetworkComponent.INSULATOR;
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public NetworkComponent classifyLocation(@Nonnull Location l) {
CAPACITOR -> NetworkComponent.CONNECTOR;
case CONSUMER,
GENERATOR -> NetworkComponent.TERMINUS;
case INSULATOR -> NetworkComponent.INSULATOR;
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public enum EnergyNetComponentType {
*/
CONNECTOR,

/**
* An Insulator can be placed between {@link EnergyNetComponent}s
* to stop them from connecting
*/
INSULATOR,

/**
* A fallback value to use when a {@link Block} cannot be classified as any of the
* other options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ private SlimefunItems() {}

public static final SlimefunItemStack ENERGY_REGULATOR = new SlimefunItemStack("ENERGY_REGULATOR", HeadTexture.ENERGY_REGULATOR, "&6Energy Regulator", "", "&fCore Component of an Energy Network");
public static final SlimefunItemStack ENERGY_CONNECTOR = new SlimefunItemStack("ENERGY_CONNECTOR", HeadTexture.ENERGY_CONNECTOR, "&eEnergy Connector", LoreBuilder.range(6), "", "&fPlace this between machines", "&fand generators to connect them", "&fto your regulator.");
public static final SlimefunItemStack ENERGY_INSULATOR = new SlimefunItemStack("ENERGY_INSULATOR", HeadTexture.ENERGY_INSULATOR, "&7Energy Insulator", "", "&fPlace this between machines, generators", "&fand connectors to stop", "&fthem from connecting.");
public static final SlimefunItemStack DEBUG_FISH = new SlimefunItemStack("DEBUG_FISH", Material.SALMON, "&3How much is the Fish?", "", "&eRight Click &fany Block to view it's BlockData", "&eLeft Click &fto break a Block", "&eShift + Left Click &fany Block to erase it's BlockData", "&eShift + Right Click &fto place a Placeholder Block");

public static final SlimefunItemStack NETHER_ICE = new SlimefunItemStack("NETHER_ICE", HeadTexture.NETHER_ICE, "&eNether Ice", "", LoreBuilder.radioactive(Radioactivity.MODERATE), LoreBuilder.HAZMAT_SUIT_REQUIRED);
Expand All @@ -776,6 +777,7 @@ private SlimefunItems() {}
// Cargo
public static final SlimefunItemStack CARGO_MANAGER = new SlimefunItemStack("CARGO_MANAGER", HeadTexture.CARGO_MANAGER, "&6Cargo Manager", "", "&fCore Component of an Item Transport Network");
public static final SlimefunItemStack CARGO_CONNECTOR_NODE = new SlimefunItemStack("CARGO_NODE", HeadTexture.CARGO_CONNECTOR_NODE, "&7Cargo Node &c(Connector)", "", "&fCargo Connector Pipe");
public static final SlimefunItemStack CARGO_INSULATOR = new SlimefunItemStack("CARGO_INSULATOR", HeadTexture.CARGO_INSULATOR, "&7Cargo Insulator", "", "&fCargo Signal Insulator");
public static final SlimefunItemStack CARGO_INPUT_NODE = new SlimefunItemStack("CARGO_NODE_INPUT", HeadTexture.CARGO_INPUT_NODE, "&7Cargo Node &c(Input)", "", "&fCargo Input Pipe");
public static final SlimefunItemStack CARGO_OUTPUT_NODE = new SlimefunItemStack("CARGO_NODE_OUTPUT", HeadTexture.CARGO_OUTPUT_NODE, "&7Cargo Node &c(Output)", "", "&fCargo Output Pipe");
public static final SlimefunItemStack CARGO_OUTPUT_NODE_2 = new SlimefunItemStack("CARGO_NODE_OUTPUT_ADVANCED", HeadTexture.CARGO_OUTPUT_NODE, "&6Advanced Cargo Node &c(Output)", "", "&fCargo Output Pipe");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;

/**
* The {@link CargoInsulator} stops {@link CargoNode}s and {@link CargoConnectorNode}s
* from connecting when placed in between them.
*
* @author iTwins
*/
public class CargoInsulator extends SlimefunItem {

@ParametersAreNonnullByDefault
public CargoInsulator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.electric;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;

/**
* This {@link EnergyNetComponent} is node that stops {@link EnergyNetComponent}s from connecting
* when placed in between them.
*
* @author iTwins
*
* @see EnergyNet
* @see EnergyNetComponent
*/
public class EnergyInsulator extends SlimefunItem implements EnergyNetComponent {

@ParametersAreNonnullByDefault
public EnergyInsulator(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
}

@Override
public @Nonnull EnergyNetComponentType getEnergyComponentType() {
return EnergyNetComponentType.INSULATOR;
}

@Override
public int getCapacity() {
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.AdvancedCargoOutputNode;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoConnectorNode;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoInputNode;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoInsulator;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoManager;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoOutputNode;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.ReactorAccessPort;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.TrashCan;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.Capacitor;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.EnergyConnector;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.EnergyInsulator;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.EnergyRegulator;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.JetBoots;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;
Expand Down Expand Up @@ -1560,6 +1562,10 @@ public static void setup(@Nonnull Slimefun plugin) {
new SlimefunItemStack(SlimefunItems.ENERGY_CONNECTOR, 8))
.register(plugin);

new EnergyInsulator(itemGroups.electricity, SlimefunItems.ENERGY_INSULATOR, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.PLASTIC_SHEET, new ItemStack(Material.TERRACOTTA), SlimefunItems.PLASTIC_SHEET, new ItemStack(Material.TERRACOTTA), SlimefunItems.ENERGY_CONNECTOR, new ItemStack(Material.TERRACOTTA), SlimefunItems.PLASTIC_SHEET, new ItemStack(Material.TERRACOTTA), SlimefunItems.PLASTIC_SHEET})
.register(plugin);

new SlimefunItem(itemGroups.misc, SlimefunItems.DUCT_TAPE, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.ALUMINUM_DUST, SlimefunItems.ALUMINUM_DUST, SlimefunItems.ALUMINUM_DUST, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.WHITE_WOOL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.PAPER), new ItemStack(Material.PAPER), new ItemStack(Material.PAPER)},
new SlimefunItemStack(SlimefunItems.DUCT_TAPE, 2))
Expand Down Expand Up @@ -2557,6 +2563,10 @@ public int getCapacity() {
new SlimefunItemStack(SlimefunItems.CARGO_CONNECTOR_NODE, 4))
.register(plugin);

new CargoInsulator(itemGroups.cargo, SlimefunItems.CARGO_INSULATOR, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.LEAD_INGOT, SlimefunItems.TIN_INGOT, SlimefunItems.LEAD_INGOT, SlimefunItems.TIN_INGOT, SlimefunItems.CARGO_CONNECTOR_NODE, SlimefunItems.TIN_INGOT, SlimefunItems.LEAD_INGOT, SlimefunItems.TIN_INGOT, SlimefunItems.LEAD_INGOT})
.register(plugin);

new CargoInputNode(itemGroups.cargo, SlimefunItems.CARGO_INPUT_NODE, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, new ItemStack(Material.HOPPER), null, SlimefunItems.BILLON_INGOT, SlimefunItems.CARGO_CONNECTOR_NODE, SlimefunItems.BILLON_INGOT, null, new ItemStack(Material.HOPPER), null},
new SlimefunItemStack(SlimefunItems.CARGO_INPUT_NODE, 2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ public enum HeadTexture {
ELECTRIC_PRESS("8d5cf92bc79ec19f4106441affff1406a1367010dcafb197dd94cfca1a6de0fc"),
ENERGY_REGULATOR("d78f2b7e5e75639ea7fb796c35d364c4df28b4243e66b76277aadcd6261337"),
ENERGY_CONNECTOR("1085e098756b995b00241644089c55a8f9acde35b9a37785d5e057a923613b"),
ENERGY_INSULATOR("7f44bee34a0ead8af93260181747e573456abb54385bf234102ef14c4f2216d6"),
NETHER_ICE("3ce2dad9baf7eaba7e80d4d0f9fac0aab01a76b12fb71c3d2af2a16fdd4c7383"),
ENRICHED_NETHER_ICE("7c818aa13aabc7294838d21caac057e97bd8c89641a0c0f8a55442ff4e27"),
NETHER_ICE_COOLANT_CELL("8d3cd412555f897016213e5d6c7431b448b9e5644e1b19ec51b5316f35840e0"),
CARGO_MANAGER("e510bc85362a130a6ff9d91ff11d6fa46d7d1912a3431f751558ef3c4d9c2"),
CARGO_CONNECTOR_NODE("07b7ef6fd7864865c31c1dc87bed24ab5973579f5c6638fecb8dedeb443ff0"),
CARGO_INSULATOR("ac8962e46ee8ba5517f3f524175391fca35af4ca3c01995a8da2c8898573c50c"),
iTwins marked this conversation as resolved.
Show resolved Hide resolved
CARGO_INPUT_NODE("16d1c1a69a3de9fec962a77bf3b2e376dd25c873a3d8f14f1dd345dae4c4"),
CARGO_OUTPUT_NODE("55b21fd480c1c43bf3b9f842c869bdc3bc5acc2599bf2eb6b8a1c95dce978f"),
FILLED_CAN("b439e3f5acbee9be4c4259289d6d9f35c635ffa661114687b3ea6dda8c79"),
Expand Down
Loading