Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies {

implementation fg.deobf("mcjty.theoneprobe:TheOneProbe-1.12:${top_version}")

implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '3.12.10'
implementation fg.deobf("li.cil.oc:OpenComputers:MC${minecraft_version}-1.7.5.213:api")

implementation fg.deobf("curse.maven:baubles-227083:2518667")
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/sonar/fluxnetworks/FluxConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package sonar.fluxnetworks;

import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import org.bson.Document;
import org.bson.codecs.UuidCodec;
import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecRegistry;
import sonar.fluxnetworks.common.data.dto.FluxNetworkDataDTO;
import sonar.fluxnetworks.common.data.codecs.ChunkPosCodec;
import sonar.fluxnetworks.common.data.codecs.FluxConnectorCodec;
import sonar.fluxnetworks.common.data.codecs.FluxNetworkCodecProvider;
import sonar.fluxnetworks.common.data.codecs.FluxNetworkDataCodecProvider;
import sonar.fluxnetworks.common.data.codecs.NetworkMemberCodecProvider;
import sonar.fluxnetworks.common.handler.ItemEnergyHandler;
import sonar.fluxnetworks.common.handler.TileEntityHandler;

import java.io.File;
import java.util.UUID;

import static sonar.fluxnetworks.common.data.TagConstants.INDEX_FIELD;

public class FluxConfig {

Expand All @@ -17,12 +35,21 @@ public class FluxConfig {
public static final String ENERGY = "energy";
public static final String NETWORKS = "networks";
public static final String BLACKLIST = "blacklists";
public static final String DATABASE = "database";

public static MongoCollection<FluxNetworkDataDTO> MONGO_COLLECTION;

public static boolean enableButtonSound, enableOneProbeBasicInfo, enableOneProbeAdvancedInfo, enableOneProbeSneaking;
public static boolean enableFluxRecipe, enableOldRecipe, enableChunkLoading, enableSuperAdmin;
public static int defaultLimit, basicCapacity, basicTransfer, herculeanCapacity, herculeanTransfer, gargantuanCapacity, gargantuanTransfer;
public static int maximumPerPlayer, superAdminRequiredPermission;
public static String[] blockBlacklistStrings, itemBlackListStrings;
public static UUID MONGO_SERVER_ID;
private static MongoClient MONGO_CLIENT;
private static MongoDatabase MONGO_DB;
private static String MONGO_URL;
private static String MONGO_DB_NAME;
private static String MONGO_COLLECTION_NAME;

public static void init(File file) {
config = new Configuration(new File(file.getPath(), "flux_networks.cfg"));
Expand All @@ -31,6 +58,23 @@ public static void init(File file) {
verifyAndReadBlacklist();
config.save();
generateFluxChunkConfig();
connectToDB();
}

private static void connectToDB(){
MONGO_CLIENT = MongoClients.create(MONGO_URL);
ChunkPosCodec chunkPosCodec = new ChunkPosCodec();
UuidCodec uuidCodec = new UuidCodec();
FluxConnectorCodec fluxConnectorCodec = new FluxConnectorCodec();
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(CodecRegistries.fromRegistries(
CodecRegistries.fromCodecs(chunkPosCodec, uuidCodec, fluxConnectorCodec),
CodecRegistries.fromProviders(new FluxNetworkCodecProvider(), new FluxNetworkDataCodecProvider(), new NetworkMemberCodecProvider()),
MongoClientSettings.getDefaultCodecRegistry()));
MONGO_DB = MONGO_CLIENT.getDatabase(MONGO_DB_NAME);
MONGO_COLLECTION = MONGO_DB.getCollection(MONGO_COLLECTION_NAME, FluxNetworkDataDTO.class).withCodecRegistry(codecRegistry);
if (MONGO_COLLECTION.countDocuments(new Document(INDEX_FIELD, MONGO_SERVER_ID)) < 1) {
MONGO_COLLECTION.insertOne(new FluxNetworkDataDTO(MONGO_SERVER_ID));
}
}

public static void verifyAndReadBlacklist() {
Expand Down Expand Up @@ -85,6 +129,7 @@ public static void generateFluxChunkConfig() {
}

public static void read() {

defaultLimit = config.getInt("Default Transfer Limit", ENERGY, 800000, 0, Integer.MAX_VALUE, "The default transfer limit of a flux connector");

basicCapacity = config.getInt("Basic Storage Capacity", ENERGY, 1000000, 0, Integer.MAX_VALUE, "");
Expand All @@ -102,6 +147,11 @@ public static void read() {
enableOldRecipe = config.getBoolean("Enable Old Recipe", GENERAL, false, "Enables redstone being turned into Flux when dropped in fire. (Need \"Enable Flux Recipe\" = true, so the default recipe can't be disabled if turns this on)");
enableChunkLoading = config.getBoolean("Allow Flux Chunk Loading", GENERAL, true, "Allows flux tiles to work as chunk loaders");

MONGO_URL = config.getString("Url to connect to mongo instance", DATABASE, "mongodb://localhost:27017", "");
MONGO_DB_NAME = config.getString("Mongo database name", DATABASE, "local", "");
MONGO_COLLECTION_NAME = config.getString("Mongo collection name", DATABASE, "networks", "");
MONGO_SERVER_ID = UUID.fromString(config.getString("Unique server id for multi-server features", DATABASE, UUID.randomUUID().toString(), "Do not change this value unless you want to lose all network data!"));

enableButtonSound = config.getBoolean("Enable GUI Button Sound", CLIENT, true, "Enable navigation buttons sound when pressing it");
enableOneProbeBasicInfo = config.getBoolean("Enable Basic One Probe Info", CLIENT, true, "Displays: Network Name, Live Transfer Rate & Internal Buffer");
enableOneProbeAdvancedInfo = config.getBoolean("Enable Advanced One Probe Info", CLIENT, true, "Displays: Transfer Limit & Priority etc");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public interface IFluxNetwork {

default int getNetworkID() {
default long getNetworkID() {
return getSetting(NetworkSettings.NETWORK_ID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
///refers to anything which can be connected to a specific network, flux tiles & configurators
public interface INetworkConnector {

int getNetworkID();
long getNetworkID();

IFluxNetwork getNetwork();

Expand Down
24 changes: 18 additions & 6 deletions src/main/java/sonar/fluxnetworks/api/network/NetworkMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerProfileCache;
import net.minecraftforge.fml.common.FMLCommonHandler;
import sonar.fluxnetworks.common.data.dto.NetworkMemberDTO;

import java.util.UUID;

import static sonar.fluxnetworks.common.data.TagConstants.CACHED_NAME;
import static sonar.fluxnetworks.common.data.TagConstants.PLAYER_ACCESS;
import static sonar.fluxnetworks.common.data.TagConstants.PLAYER_UUID;

public class NetworkMember {

private UUID playerUUID;
Expand All @@ -22,6 +27,12 @@ public NetworkMember(NBTTagCompound nbt) {
readNetworkNBT(nbt);
}

public NetworkMember(NetworkMemberDTO networkMemberDTO) {
this.playerUUID = networkMemberDTO.getPlayerUUID();
this.cachedName = networkMemberDTO.getCachedName();
this.accessPermission = AccessLevel.values()[networkMemberDTO.getPlayerAccess()];
}

public static NetworkMember createNetworkMember(EntityPlayer player, AccessLevel permissionLevel) {
NetworkMember t = new NetworkMember();
GameProfile profile = player.getGameProfile();
Expand Down Expand Up @@ -72,15 +83,16 @@ public void setAccessPermission(AccessLevel accessPermission) {
}

public void readNetworkNBT(NBTTagCompound nbt) {
playerUUID = nbt.getUniqueId("playerUUID");
cachedName = nbt.getString("cachedName");
accessPermission = AccessLevel.values()[nbt.getByte("playerAccess")];
playerUUID = nbt.getUniqueId(PLAYER_UUID);
cachedName = nbt.getString(CACHED_NAME);
accessPermission = AccessLevel.values()[nbt.getByte(PLAYER_ACCESS)];
}

public NBTTagCompound writeNetworkNBT(NBTTagCompound nbt) {
nbt.setUniqueId("playerUUID", playerUUID);
nbt.setString("cachedName", cachedName);
nbt.setByte("playerAccess", (byte) accessPermission.ordinal());

nbt.setUniqueId(PLAYER_UUID, playerUUID);
nbt.setString(CACHED_NAME, cachedName);
nbt.setByte(PLAYER_ACCESS, (byte) accessPermission.ordinal());
return nbt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
///TODO remove common references
public class NetworkSettings<T> {

public static final NetworkSettings<Integer> NETWORK_ID = new NetworkSettings<>(s -> s.network_id);
public static final NetworkSettings<Long> NETWORK_ID = new NetworkSettings<>(s -> s.network_id);
public static final NetworkSettings<String> NETWORK_NAME = new NetworkSettings<>(s -> s.network_name);
public static final NetworkSettings<SecurityType> NETWORK_SECURITY = new NetworkSettings<>(s -> s.network_security);
public static final NetworkSettings<String> NETWORK_PASSWORD = new NetworkSettings<>(s -> s.network_password);
Expand Down
43 changes: 35 additions & 8 deletions src/main/java/sonar/fluxnetworks/api/utils/Coord4D.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import sonar.fluxnetworks.common.data.dto.FluxConnectorDTO;

import static sonar.fluxnetworks.common.data.TagConstants.DIMENSION;
import static sonar.fluxnetworks.common.data.TagConstants.X;
import static sonar.fluxnetworks.common.data.TagConstants.Y;
import static sonar.fluxnetworks.common.data.TagConstants.Z;

public class Coord4D {

private int x, y, z, dimension;

public Coord4D(int x, int y, int z, int dimension) {
this.x = x;
this.y = y;
this.z = z;
this.dimension = dimension;
}

public Coord4D(NBTTagCompound tag) {
read(tag);
}
Expand All @@ -25,18 +38,32 @@ public Coord4D(ByteBuf buf) {
}

public NBTTagCompound write(NBTTagCompound tag) {
tag.setInteger("x", x);
tag.setInteger("y", y);
tag.setInteger("z", z);
tag.setInteger("dimension", dimension);
tag.setInteger(X, x);
tag.setInteger(Y, y);
tag.setInteger(Z, z);
tag.setInteger(DIMENSION, dimension);
return tag;
}

public void write(FluxConnectorDTO dto) {
dto.setX(x);
dto.setY(y);
dto.setZ(z);
dto.setDimension(dimension);
}

public void read(NBTTagCompound tag) {
x = tag.getInteger("x");
y = tag.getInteger("y");
z = tag.getInteger("z");
dimension = tag.getInteger("dimension");
x = tag.getInteger(X);
y = tag.getInteger(Y);
z = tag.getInteger(Z);
dimension = tag.getInteger(DIMENSION);
}

public void read(FluxConnectorDTO dto) {
x = dto.getX();
y = dto.getY();
z = dto.getZ();
dimension = dto.getDimension();
}

public void write(ByteBuf buf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public String getNBTName() {

public static void copyNetwork(NBTTagCompound nbt, String key, TileFluxCore tile) {
if (!tile.getNetwork().isInvalid() && tile.getNetworkID() != -1) {
nbt.setInteger(key, tile.getNetworkID());
nbt.setLong(key, tile.getNetworkID());
}
}

public static void pasteNetwork(NBTTagCompound nbt, String key, TileFluxCore tile) {
int storedID = nbt.getInteger(key);
long storedID = nbt.getLong(key);
if (storedID != -1) {
IFluxNetwork newNetwork = FluxNetworkCache.instance.getNetwork(storedID);
tile.getNetwork().queueConnectionRemoval(tile, false);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sonar/fluxnetworks/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void setFeedback(EnumFeedbackInfo info, boolean operation) {
}

@Override
public void receiveColorCache(Map<Integer, Tuple<Integer, String>> cache) {
public void receiveColorCache(Map<Long, Tuple<Integer, String>> cache) {
FluxColorHandler.receiveCache(cache);
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/sonar/fluxnetworks/client/FluxColorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,36 @@ public class FluxColorHandler implements IBlockColor, IItemColor {

public static final int DEFAULT_COLOR = FluxUtils.getIntFromColor(41, 94, 138);
public static final int NO_NETWORK_COLOR = FluxUtils.getIntFromColor(178, 178, 178);
public static final Map<Integer, Integer> colorCache = new HashMap<>();
public static final Map<Integer, String> nameCache = new HashMap<>();
private static final List<Integer> requests = new ArrayList<>();
private static final List<Integer> sent_requests = new ArrayList<>();
public static final Map<Long, Integer> colorCache = new HashMap<>();
public static final Map<Long, String> nameCache = new HashMap<>();
private static final List<Long> requests = new ArrayList<>();
private static final List<Long> sent_requests = new ArrayList<>();

public static void reset() {
colorCache.clear();
nameCache.clear();
requests.clear();
}

public static void loadColorCache(int id, int color) {
public static void loadColorCache(long id, int color) {
if (id != -1) {
colorCache.put(id, color);
}
}

public static void loadNameCache(int id, String name) {
public static void loadNameCache(long id, String name) {
if (id != -1) {
nameCache.put(id, name);
}
}

public static void placeRequest(int id) {
public static void placeRequest(long id) {
if (id != -1 && !requests.contains(id) && !sent_requests.contains(id)) {
requests.add(id);
}
}

public static int getOrRequestNetworkColor(int id) {
public static int getOrRequestNetworkColor(long id) {
if (id == -1) {
return NO_NETWORK_COLOR;
}
Expand All @@ -79,7 +79,7 @@ public static int getOrRequestNetworkColor(int id) {
return NO_NETWORK_COLOR;
}

public static String getOrRequestNetworkName(int id) {
public static String getOrRequestNetworkName(long id) {
if (id == -1) {
return "NONE";
}
Expand All @@ -105,7 +105,7 @@ public static void sendRequests() {
}
}

public static void receiveCache(Map<Integer, Tuple<Integer, String>> cache) {
public static void receiveCache(Map<Long, Tuple<Integer, String>> cache) {
cache.forEach((ID, DETAILS) -> {
loadColorCache(ID, DETAILS.getFirst());
loadNameCache(ID, DETAILS.getSecond());
Expand Down Expand Up @@ -160,7 +160,7 @@ public static int colorMultiplierForConfigurator(ItemStack stack, int tintIndex)
}
NBTTagCompound tag = stack.getSubCompound(FluxUtils.CONFIGS_TAG);
if (tag != null) {
return getOrRequestNetworkColor(tag.getInteger(FluxConfigurationType.NETWORK.getNBTName()));
return getOrRequestNetworkColor(tag.getLong(FluxConfigurationType.NETWORK.getNBTName()));
}
return NO_NETWORK_COLOR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void onButtonClicked(GuiButtonCore button, int mouseX, int mouseY, int mo
if (button == apply) {
///send changes to server.
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger(FluxConfigurationType.NETWORK.getNBTName(), network.getNetworkID());
tag.setLong(FluxConfigurationType.NETWORK.getNBTName(), network.getNetworkID());
tag.setInteger(FluxConfigurationType.PRIORITY.getNBTName(), stackPriority);
tag.setLong(FluxConfigurationType.TRANSFER.getNBTName(), stackLimit);
tag.setBoolean(FluxConfigurationType.PRIORITY_SETTING.getNBTName(), stackSurgeMode);
Expand Down Expand Up @@ -169,7 +169,7 @@ public void onSettingsChanged() {
apply.clickable = true;
} else {
apply.clickable =
network.getNetworkID() != configTag.getInteger(FluxConfigurationType.NETWORK.getNBTName()) ||
network.getNetworkID() != configTag.getLong(FluxConfigurationType.NETWORK.getNBTName()) ||
stackPriority != configTag.getInteger(FluxConfigurationType.PRIORITY.getNBTName()) ||
stackLimit != configTag.getLong(FluxConfigurationType.TRANSFER.getNBTName()) ||
stackSurgeMode != configTag.getBoolean(FluxConfigurationType.PRIORITY_SETTING.getNBTName()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected List<String> getFluxInfo(IFluxConnector flux) {
public void onSuperAdminChanged() {
}

public void setConnectedNetwork(int networkID, String password) {
public void setConnectedNetwork(long networkID, String password) {
if (connector instanceof IFluxConnector) {
PacketHandler.network.sendToServer(new PacketTile.TileMessage(PacketTileType.SET_NETWORK, PacketTileHandler.getSetNetworkPacket(networkID, password), ((IFluxConnector) connector).getCoords().getPos(), ((IFluxConnector) connector).getCoords().getDimension()));
}
Expand Down
Loading