Skip to content

Commit

Permalink
Merge pull request #4 from DaNussi/nono
Browse files Browse the repository at this point in the history
Nono
  • Loading branch information
DaNussi committed Jun 15, 2023
2 parents 3b8305f + 1ee8a0e commit 7756404
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ConfigCommand {
public static ForgeConfigSpec.ConfigValue<String> CONFIG_VALUE_REDIS_USERNAME;
public static ForgeConfigSpec.ConfigValue<String> CONFIG_VALUE_REDIS_PASSWORD;
public static ForgeConfigSpec.ConfigValue<Boolean> CONFIG_VALUE_BEHAVIOUR_AUTOSTART;
public static ForgeConfigSpec.ConfigValue<Boolean> CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY;

static {
CONFIG_BUILDER.push("Config for DAE2!");
Expand All @@ -55,6 +56,7 @@ public class ConfigCommand {
CONFIG_VALUE_REDIS_PASSWORD = CONFIG_BUILDER.define("REDIS_PASSWORD", pendingConfig.getPassword());

CONFIG_VALUE_BEHAVIOUR_AUTOSTART = CONFIG_BUILDER.define("BEHAVIOUR_AUTOSTART", pendingConfig.getAutostart());
CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY = CONFIG_BUILDER.define("BEHAVIOUR_VIRTUAL_INVENTORY", pendingConfig.getVirtualInventory());

CONFIG_BUILDER.pop();
CONFIG_SPEC = CONFIG_BUILDER.build();
Expand All @@ -70,6 +72,10 @@ public ConfigCommand(CommandDispatcher<CommandSourceStack> dispatcher) {
.then(Commands.literal("enable").executes(context -> autostart(context.getSource(), true)))
.then(Commands.literal("disable").executes(context -> autostart(context.getSource(),false)))
)
.then(Commands.literal("virtual_inventory")
.then(Commands.literal("enable").executes(context -> virtualInventory(context.getSource(), true)))
.then(Commands.literal("disable").executes(context -> virtualInventory(context.getSource(),false)))
)
.then(Commands.literal("config")
.then(Commands.literal("get")
.then(Commands.literal("current").executes(context -> currentConfig(context.getSource())))
Expand Down Expand Up @@ -115,7 +121,8 @@ private static int status(CommandSourceStack commandSourceStack) {
commandSourceStack.sendSystemMessage(Component.literal(
"IsRunning: " + IsRunning + "\n" +
"IsApplied: " + IsApplied + "\n" +
"Autostart: " + currentConfig.autostart + ""
"Autostart: " + currentConfig.autostart + "\n" +
"VirtualInventory: " + currentConfig.getVirtualInventory() + ""
));

return 1;
Expand Down Expand Up @@ -209,9 +216,20 @@ private static int autostart(CommandSourceStack commandSourceStack, boolean enab
return 1;
}

private static int virtualInventory(CommandSourceStack commandSourceStack, boolean enabled) {
if(enabled == currentConfig.getVirtualInventory()) {
commandSourceStack.sendSystemMessage(Component.literal("Virtual inventory already " + enabled + "!"));
} else {
currentConfig.setVirtualInventory(enabled);
saveConfig();
commandSourceStack.sendSystemMessage(Component.literal("Set virtual inventory to " + enabled + "!"));
}
return 1;
}

private static void onStart() throws Exception {
InterDimensionalStorageCell.redisInit();
VirtualInventory.Init();
if(currentConfig.getVirtualInventory()) VirtualInventory.Init();
}

private static void onStop() throws Exception {
Expand All @@ -224,8 +242,9 @@ public static void saveConfig() {
CONFIG_VALUE_REDIS_PORT.set(currentConfig.getPort());
CONFIG_VALUE_REDIS_USERNAME.set(currentConfig.getUsername());
CONFIG_VALUE_REDIS_PASSWORD.set(currentConfig.getPassword());
CONFIG_VALUE_BEHAVIOUR_AUTOSTART.set(currentConfig.getAutostart());

CONFIG_VALUE_BEHAVIOUR_AUTOSTART.set(currentConfig.getAutostart());
CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.set(currentConfig.getVirtualInventory());
}

public static void loadConfig() {
Expand All @@ -237,6 +256,7 @@ public static void loadConfig() {
);

currentConfig.setAutostart(CONFIG_VALUE_BEHAVIOUR_AUTOSTART.get());
currentConfig.setVirtualInventory(CONFIG_VALUE_BEHAVIOUR_VIRTUAL_INVENTORY.get());
}

@SubscribeEvent
Expand Down Expand Up @@ -350,6 +370,7 @@ public static class Config {
private String password;

private boolean autostart = false;
private boolean virtualInventory = false;

public Config(String data) throws CommandSyntaxException {
CompoundTag compoundTag = TagParser.parseTag(data);
Expand All @@ -370,6 +391,14 @@ public static Config getDefault() {
return new Config("localhost", 6379, "kevin", "klein");
}

public boolean getVirtualInventory() {
return virtualInventory;
}

public void setVirtualInventory(boolean virtualInventory) {
this.virtualInventory = virtualInventory;
}

public boolean getAutostart() {
return autostart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
import com.mojang.logging.LogUtils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.nussi.dedicated_applied_energistics.DedicatedAppliedEnegistics;
import net.nussi.dedicated_applied_energistics.blockentities.InterDimensionalInterfaceBlockEntity;
import net.nussi.dedicated_applied_energistics.blockentities.TestBlockEntity;
import net.nussi.dedicated_applied_energistics.commands.ConfigCommand;
import org.slf4j.Logger;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -54,7 +51,7 @@ public void persist() {}
static JedisPool jedisPool = new JedisPool();
static Jedis jedis;
static Jedis reciveJedis;
static HashMap<AEKey, Long> localHashMap = new HashMap<>();
static Hashtable<AEKey, Long> localHashMap = new Hashtable<>();
static int inventoryIndex = 0;
static String UUID = java.util.UUID.randomUUID().toString();
static Thread thread;
Expand Down Expand Up @@ -238,7 +235,9 @@ public static void offset(AEKey what, long amount, Actionable mode, boolean from

@Override
public void getAvailableStacks(KeyCounter out) {
for(Map.Entry<AEKey, Long> pair : localHashMap.entrySet()) {
Hashtable<AEKey, Long> temp = (Hashtable<AEKey, Long>) localHashMap.clone();

for(Map.Entry<AEKey, Long> pair : temp.entrySet()) {
out.add(pair.getKey(), pair.getValue());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ displayName="Dedicated Applied Energistics" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
displayURL="https://github.com/DaNussi/DedicatedAppliedEnergistics" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="logo.png" #optional
# A text field displayed in the mod UI
credits="Thanks for all the Contributors over at the base mod https://github.com/AppliedEnergistics/Applied-Energistics-2" #optional
credits="Thanks for all the Contributors over at the AE2 https://github.com/AppliedEnergistics/Applied-Energistics-2" #optional
# A text field displayed in the mod UI
authors="DaNussi" #optional
# Display Test controls the display for your mod in the server connection screen
Expand Down
File renamed without changes

0 comments on commit 7756404

Please sign in to comment.