Skip to content

Commit bd10374

Browse files
authored
Merge pull request #82 from sylviameows/feat/dark-mode
codeclient dark mode resource pack
2 parents ce2ca46 + 8b11dde commit bd10374

6 files changed

Lines changed: 63 additions & 1 deletion

File tree

src/main/java/dev/dfonline/codeclient/CodeClient.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
1919
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
2020
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
21+
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
22+
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
23+
import net.fabricmc.loader.api.FabricLoader;
24+
import net.fabricmc.loader.api.ModContainer;
2125
import net.minecraft.block.Blocks;
2226
import net.minecraft.block.entity.SignBlockEntity;
2327
import net.minecraft.client.MinecraftClient;
@@ -31,13 +35,14 @@
3135
import net.minecraft.network.packet.Packet;
3236
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
3337
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
38+
import net.minecraft.text.Text;
39+
import net.minecraft.util.Formatting;
3440
import net.minecraft.util.Identifier;
3541
import net.minecraft.util.math.BlockPos;
3642
import org.jetbrains.annotations.NotNull;
3743
import org.slf4j.Logger;
3844
import org.slf4j.LoggerFactory;
3945

40-
4146
public class CodeClient implements ModInitializer {
4247
public static final String MOD_NAME = "CodeClient";
4348
public static final String MOD_ID = "codeclient";
@@ -222,12 +227,53 @@ public static void onModeChange(Location location) {
222227
currentAction.onModeChange(location);
223228
}
224229

230+
/**
231+
* Gets the mod container needed for registering resources like data packs and resource packs to CodeClient.
232+
* @return the mod container.
233+
* @throws NullPointerException the mod's container was not found.
234+
*/
235+
public static ModContainer getModContainer() throws NullPointerException {
236+
var container = FabricLoader.getInstance().getModContainer(CodeClient.MOD_ID);
237+
if (container.isEmpty()) throw new NullPointerException("Could not get mod container.");
238+
return container.get();
239+
}
240+
241+
/**
242+
* Registers a resource pack with a normal activation type.
243+
* @param id the resource id
244+
* @param name the resource pack's display name
245+
* @return if the resource pack was created
246+
* @throws NullPointerException if the mod container is not found
247+
*/
248+
private boolean registerResourcePack(String id, Text name) throws NullPointerException {
249+
return registerResourcePack(id, name, ResourcePackActivationType.NORMAL);
250+
}
251+
252+
/**
253+
* Registers a resource pack with the given activation type.
254+
* @param id the resource id
255+
* @param name the resource pack's display name
256+
* @param type the resource pack's activation type
257+
* @return if the resource pack was created
258+
* @throws NullPointerException if the mod container is not found
259+
*/
260+
private boolean registerResourcePack(String id, Text name, ResourcePackActivationType type) throws NullPointerException {
261+
var prefix = String.format("[%s] ", MOD_NAME);
262+
return ResourceManagerHelper.registerBuiltinResourcePack(
263+
new Identifier(CodeClient.MOD_ID, id),
264+
getModContainer(),
265+
Text.literal(prefix).formatted(Formatting.GRAY).append(name),
266+
type
267+
);
268+
}
269+
225270
/**
226271
* Registers barriers as visible.
227272
* Starts the API.
228273
* Sets up auto join if enabled.
229274
* Setups the edit bind.
230275
* Registers command callback.
276+
* Registers dark mode resource pack.
231277
*/
232278
@Override
233279
public void onInitialize() {
@@ -259,6 +305,12 @@ public void onInitialize() {
259305
Commands.register(dispatcher);
260306
});
261307

308+
try {
309+
registerResourcePack("dark_mode", Text.literal("Dark Mode").formatted(Formatting.WHITE));
310+
} catch (NullPointerException exception) {
311+
CodeClient.LOGGER.warn("Could not load dark mode resource pack!");
312+
}
313+
262314
CodeClient.LOGGER.info("CodeClient, making it easier to wipe your plot and get banned for hacks since 2022");
263315
}
264316

2.93 KB
Loading
3.17 KB
Loading
2.99 KB
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"pack": {
3+
"pack_format": 22,
4+
"supported_formats": {
5+
"min_inclusive": 22,
6+
"max_inclusive": 34
7+
},
8+
"description": "Darkens the UI of CodeClient (use with DefaultDarkMode)\n"
9+
}
10+
}
44 KB
Loading

0 commit comments

Comments
 (0)