Add configurability to vxlan block
This commit is contained in:
@@ -65,8 +65,10 @@ public final class ConfigManager {
|
||||
|
||||
static {
|
||||
PARSERS.put(int.class, ConfigManager::parseIntField);
|
||||
PARSERS.put(short.class, ConfigManager::parseShortField);
|
||||
PARSERS.put(long.class, ConfigManager::parseLongField);
|
||||
PARSERS.put(double.class, ConfigManager::parseDoubleField);
|
||||
PARSERS.put(boolean.class, ConfigManager::parseBooleanField);
|
||||
PARSERS.put(String.class, ConfigManager::parseStringField);
|
||||
PARSERS.put(UUID.class, ConfigManager::parseUUIDField);
|
||||
PARSERS.put(ResourceLocation.class, ConfigManager::parseResourceLocationField);
|
||||
@@ -134,6 +136,16 @@ public final class ConfigManager {
|
||||
return new ConfigFieldPair<>(field, configValue);
|
||||
}
|
||||
|
||||
private static ConfigFieldPair<?> parseShortField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
|
||||
final short defaultValue = field.getShort(instance);
|
||||
final short minValue = (short) Math.max(getMin(field), Short.MIN_VALUE);
|
||||
final short maxValue = (short) Math.min(getMax(field), Short.MAX_VALUE);
|
||||
|
||||
final ForgeConfigSpec.IntValue configValue = builder.defineInRange(path, defaultValue, minValue, maxValue);
|
||||
|
||||
return new ConfigFieldPair<>(field, configValue);
|
||||
}
|
||||
|
||||
private static ConfigFieldPair<?> parseLongField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
|
||||
final long defaultValue = field.getLong(instance);
|
||||
final long minValue = (long) Math.max(getMin(field), Long.MIN_VALUE);
|
||||
@@ -170,6 +182,14 @@ public final class ConfigManager {
|
||||
return new ConfigFieldPair<>(field, configValue, UUID::fromString);
|
||||
}
|
||||
|
||||
private static ConfigFieldPair<?> parseBooleanField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
|
||||
final boolean defaultValue = (boolean) field.get(instance);
|
||||
|
||||
final ForgeConfigSpec.ConfigValue<Boolean> configValue = builder.define(path, defaultValue);
|
||||
|
||||
return new ConfigFieldPair<>(field, configValue);
|
||||
}
|
||||
|
||||
private static ConfigFieldPair<?> parseResourceLocationField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
|
||||
final ResourceLocation defaultValue = (ResourceLocation) field.get(instance);
|
||||
|
||||
|
||||
@@ -22,11 +22,8 @@ import li.cil.oc2.common.tags.BlockTags;
|
||||
import li.cil.oc2.common.tags.ItemTags;
|
||||
import li.cil.oc2.common.util.RegistryUtils;
|
||||
import li.cil.oc2.common.util.SoundEvents;
|
||||
<<<<<<< HEAD
|
||||
import li.cil.oc2.common.vm.provider.DeviceTreeProviders;
|
||||
=======
|
||||
import li.cil.oc2.common.vxlan.TunnelManager;
|
||||
>>>>>>> 7a7b14ef (Add initial work on the NetworkPortalBlock)
|
||||
import li.cil.sedna.Sedna;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
|
||||
@@ -83,10 +83,6 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
if (!level.isClientSide()) {
|
||||
// vti = tag.getInt("vti");
|
||||
adjacentBlockInterfaces[0] = TunnelManager.instance().registerVti(vti, packetQueue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,13 +104,9 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
System.out.println("Tunnel VTI: " + vti);
|
||||
adjacentBlockInterfaces[0] = TunnelManager.instance().registerVti(vti, this.packetQueue);
|
||||
}
|
||||
public void loadServer() {
|
||||
System.out.println("Tunnel VTI: " + vti);
|
||||
adjacentBlockInterfaces[0] = TunnelManager.instance().registerVti(vti, this.packetQueue);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -123,7 +115,7 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
|
||||
|
||||
@Override
|
||||
protected void collectCapabilities(final CapabilityCollector collector, @Nullable final Direction direction) {
|
||||
collector.offer(Capabilities.NETWORK_INTERFACE, this);
|
||||
collector.offer(Capabilities.networkInterface(), this);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -152,7 +144,7 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
|
||||
for (final Direction side : Constants.DIRECTIONS) {
|
||||
final BlockEntity neighborBlockEntity = LevelUtils.getBlockEntityIfChunkExists(level, pos.relative(side));
|
||||
if (neighborBlockEntity != null) {
|
||||
final LazyOptional<NetworkInterface> optional = neighborBlockEntity.getCapability(Capabilities.NETWORK_INTERFACE, side.getOpposite());
|
||||
final LazyOptional<NetworkInterface> optional = neighborBlockEntity.getCapability(Capabilities.networkInterface(), side.getOpposite());
|
||||
optional.ifPresent(adjacentInterface -> {
|
||||
adjacentBlockInterfaces[side.get3DDataValue() + 1] = adjacentInterface;
|
||||
LazyOptionalUtils.addWeakListener(optional, this, (hub, unused) -> hub.handleNeighborChanged());
|
||||
|
||||
@@ -28,15 +28,15 @@ public class TunnelManager {
|
||||
public static void initialize() {
|
||||
try {
|
||||
INSTANCE = new TunnelManager(
|
||||
InetAddress.getByName("2001:470:7398::a"), (short) Config.bindPort,
|
||||
InetAddress.getByName("2001:470:7398::10"), (short) Config.remotePort
|
||||
InetAddress.getByName(Config.bindHost), (short) Config.bindPort,
|
||||
InetAddress.getByName(Config.remoteHost), (short) Config.remotePort
|
||||
);
|
||||
} catch (SocketException | UnknownHostException e) {
|
||||
System.out.println("Failed to bind host: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//if (Config.enable) {
|
||||
if (Config.enable) {
|
||||
Thread bgThread = new Thread(() -> {
|
||||
try {
|
||||
INSTANCE.listen();
|
||||
@@ -46,18 +46,17 @@ public class TunnelManager {
|
||||
});
|
||||
bgThread.setName("VXLAN Background Thread");
|
||||
bgThread.start();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
public void listen() throws IOException {
|
||||
System.out.printf("Binding %s:%s\n", bindHost, bindPort);
|
||||
|
||||
//if (Config.enable) {
|
||||
socket = new DatagramSocket(bindPort/*, bindHost*/);
|
||||
//socket.connect(remoteHost, remotePort);
|
||||
//} else {
|
||||
// socket = null;
|
||||
//}
|
||||
if (Config.enable) {
|
||||
socket = new DatagramSocket(bindPort, bindHost);
|
||||
} else {
|
||||
socket = null;
|
||||
}
|
||||
System.out.printf("Bind successful: connected=%s bound=%s\n", socket.isConnected(), socket.isBound());
|
||||
|
||||
byte[] buffer = new byte[65535];
|
||||
|
||||
Reference in New Issue
Block a user