Skip to content

Commit

Permalink
v.0.4.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
mistorvadysha committed Jan 5, 2022
1 parent 5a27256 commit ecfeb3a
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 33 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
}

dependencies {
Expand All @@ -24,6 +26,12 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modApi("me.shedaniel.cloth:cloth-config-fabric:6.1.48") {
exclude(group: "net.fabricmc.fabric-api")
}
modImplementation "com.terraformersmc:modmenu:3.0.1"
//modImplementation 'me.sargunvohra.mcmods:autoconfig1u:3.3.0'

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.java.home=C:/Program Files/Eclipse Adoptium/jdk-17.0.1.12-hotspot
loader_version=0.12.12

# Mod Properties
mod_version = 0.3.2
mod_version = 0.4.0
maven_group = com.nssg.blockmixer
archives_base_name = blockmixer

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/nssg/blockmixer/BlockMixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.nssg.blockmixer.command.BmAddCommand;
import com.nssg.blockmixer.command.BmClearCommand;
import com.nssg.blockmixer.config.JsonManager;

import net.fabricmc.api.ModInitializer;

Expand All @@ -18,6 +19,8 @@ public class BlockMixer implements ModInitializer {
public static boolean toggleMod = false;

public static boolean[] hotbarSlots = {false, false, false, false, false, false, false, false, false};
public static int lastSlot = -1;
public static int lastSlot1 = -1;
public static ArrayList<Integer> hotbarSlotsInt = new ArrayList<>();
static Random random = new Random();

Expand All @@ -42,7 +45,7 @@ public static void SlotRemove(int slot) {
hotbarSlots[slot] = false;
// hotbarSlotsInt.remove(slot);
for (int i = 0; i < hotbarSlotsInt.size(); i++) {
System.out.printf("\n[i: %d] [%d] [slot: %d]\n", i, hotbarSlotsInt.get(i), slot);
//System.out.printf("\n[i: %d] [%d] [slot: %d]\n", i, hotbarSlotsInt.get(i), slot);
if (hotbarSlotsInt.get(i) == slot) { hotbarSlotsInt.remove(Integer.valueOf(slot)); }
}
if (hotbarSlotsInt.isEmpty()) { toggleMod = false; }
Expand All @@ -54,7 +57,11 @@ public static void SwtichSlot(LivingEntity placer) {
if ((self.getWorld().toString() == "ClientLevel") && (toggleMod == true))
{
int index = random.nextInt(hotbarSlotsInt.size());
if (JsonManager.configJSON.getSettingMixMode() == "Non-repeating" && hotbarSlotsInt.size() > 1) { while (index == lastSlot) { index = random.nextInt(hotbarSlotsInt.size()); } }
else if (JsonManager.configJSON.getSettingMixMode() == "Non-repeating [2]" && hotbarSlotsInt.size() > 1) { while (index == lastSlot && index == lastSlot1) { index = random.nextInt(hotbarSlotsInt.size()); } }
self.getInventory().selectedSlot = hotbarSlotsInt.get(index);
lastSlot1 = lastSlot;
lastSlot = index;
//
//System.out.println("Selected hotbar slot number " + (index+1));
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/nssg/blockmixer/BlockMixerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import net.minecraft.client.option.KeyBinding;

import java.io.IOException;

import com.nssg.blockmixer.config.JsonManager;

import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.ClientModInitializer;
Expand All @@ -16,6 +20,8 @@ public class BlockMixerClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
try { JsonManager.Load(); } catch (IOException e) { e.printStackTrace(); }

keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.blockmixer.addslot",
InputUtil.Type.KEYSYM,
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/nssg/blockmixer/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.nssg.blockmixer.config;

public class Config {
private String settingMixMode;

public String getSettingMixMode() {
return settingMixMode;
}
public void setSettingMixMode(String settingMixMode) {
this.settingMixMode = settingMixMode;
}
}
59 changes: 59 additions & 0 deletions src/main/java/com/nssg/blockmixer/config/JsonManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.nssg.blockmixer.config;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.nssg.blockmixer.BlockMixer;

import net.fabricmc.loader.api.FabricLoader;

public class JsonManager {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final Path configPath = FabricLoader.getInstance().getConfigDir().resolve(BlockMixer.MOD_ID + ".json");

public static Config configJSON;

public static void Load() throws IOException {
Config config = new Config();

try (BufferedReader reader = new BufferedReader(new FileReader(configPath.toString()))) {
String configString = reader.lines().collect(Collectors.joining());
reader.close();
configJSON = GSON.fromJson(configString, Config.class);
System.out.println(configJSON.getSettingMixMode());
}

catch (IOException e) {
SetDefaults(config);
Files.createFile(configPath);
BufferedWriter writer = new BufferedWriter(new FileWriter(configPath.toFile()));
String configString = GSON.toJson(config);
writer.write(configString);
writer.close();
}
}

public static void SetDefaults(Config config) {
config.setSettingMixMode("Default");
}

public static void RewriteConfig() {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(configPath.toFile()));
String configString = GSON.toJson(configJSON);
writer.write(configString);
writer.close();

} catch (IOException e) {
e.printStackTrace();
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/nssg/blockmixer/config/ModMenuIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nssg.blockmixer.config;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;

import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.text.TranslatableText;

public class ModMenuIntegration implements ModMenuApi{

public String[] modeList = {"Default", "Non-repeating", "Non-repeating [2]"};

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> {
ConfigBuilder builder = ConfigBuilder
.create()
.setParentScreen(null)
.setTitle(new TranslatableText("title.blockmixer.config"));

builder.setSavingRunnable(() -> {
JsonManager.RewriteConfig();
});

ConfigEntryBuilder entryBuilder = builder.entryBuilder();

ConfigCategory general = builder
.getOrCreateCategory(new TranslatableText("category.blockmixer.general"))

.addEntry(entryBuilder.startSelector(new TranslatableText("option.blockmixer.mixmode"), modeList, JsonManager.configJSON.getSettingMixMode())
.setDefaultValue("Default")
.setTooltip(new TranslatableText("option.blockmixer.mixmode.tooltip"))
.setSaveConsumer(newValue -> JsonManager.configJSON.setSettingMixMode(newValue))
.build());

return builder.build();
};
}
}
25 changes: 0 additions & 25 deletions src/main/java/com/nssg/blockmixer/util/ModCommandRegister.java

This file was deleted.

8 changes: 7 additions & 1 deletion src/main/resources/assets/nssgs-blockmixer/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"key.blockmixer.addslot": "Add/remove hotbar slot",

"commands.blockmixer.addslot": "Added slot %d",
"commands.blockmixer.alreadyaddedslot": "is already added!",
"commands.blockmixer.clearslot": "BlockMixer now is empty",
"commands.blockmixer.removeslot": "Slot %d removed"
"commands.blockmixer.removeslot": "Slot %d removed",

"title.blockmixer.config": "BlockMixer options",
"category.blockmixer.general": "Main settings",
"option.blockmixer.mixmode": "Mix Mode",
"option.blockmixer.mixmode.tooltip": "Default: random selection of slots\nNon-repeating: slot cannot be repeated twice in a row\nNon-repeating [2]: the slot cannot be repeated three times in a row"
}
7 changes: 6 additions & 1 deletion src/main/resources/assets/nssgs-blockmixer/lang/rpr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"commands.blockmixer.addslot": "Ячейка %d добавлѣна",
"commands.blockmixer.alreadyaddedslot": "ужѣ добавлѣна!",
"commands.blockmixer.clearslot": "BlockMixer очищенъ",
"commands.blockmixer.removeslot": "Ячейка %d удалѣна"
"commands.blockmixer.removeslot": "Ячейка %d удалѣна",

"title.blockmixer.config": "Настройки BlockMixer",
"category.blockmixer.general": "Основные настройки",
"option.blockmixer.mixmode": "Рѣжимъ BlockMixer",
"option.blockmixer.mixmode.tooltip": "Default: случайный выборъ ячеякъ\nNon-repeating: ячейка не можѣтъ быть выбрана два раза подрядъ\nNon-repeating [2]: ячейка не можѣтъ быть выбрана три раза подрядъ"
}
7 changes: 6 additions & 1 deletion src/main/resources/assets/nssgs-blockmixer/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"commands.blockmixer.addslot": "Слот %d добавлен",
"commands.blockmixer.alreadyaddedslot": "уже добавлен!",
"commands.blockmixer.clearslot": "BlockMixer очищен",
"commands.blockmixer.removeslot": "Слот %d удалён"
"commands.blockmixer.removeslot": "Слот %d удалён",

"title.blockmixer.config": "Настройки BlockMixer",
"category.blockmixer.general": "Основные настройки",
"option.blockmixer.mixmode": "Режим BlockMixer",
"option.blockmixer.mixmode.tooltip": "Default: случайный выбор слотов\nNon-repeating: слот не может быть выбран два раза подряд\nNon-repeating [2]: слот не может быть выбран три раза подряд"
}
10 changes: 7 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"version": "${version}",

"name": "BlockMixer",
"description": "A mod that automatically chooses the next random block from your hotbar to build",
"description": "A mod that automatically chooses the next random block from your hotbar to build.",
"authors": [
"NSSG"
],
"contact": {
"homepage": "",
"issues": "https://github.com/mistorvadysha/BlockMixerMod/issues",
"homepage": "https://github.com/mistorvadysha/BlockMixerMod",
"sources": "https://github.com/mistorvadysha/BlockMixerMod"
},

Expand All @@ -24,7 +25,10 @@
"client": [
"com.nssg.blockmixer.BlockMixerClient",
"com.nssg.blockmixer.SlotStatus"
]
],
"modmenu": [
"com.nssg.blockmixer.config.ModMenuIntegration"
]
},
"mixins": [
"nssgs-blockmixer.mixins.json"
Expand Down

0 comments on commit ecfeb3a

Please sign in to comment.