|
18 | 18 | import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; |
19 | 19 | import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; |
20 | 20 | 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; |
21 | 25 | import net.minecraft.block.Blocks; |
22 | 26 | import net.minecraft.block.entity.SignBlockEntity; |
23 | 27 | import net.minecraft.client.MinecraftClient; |
|
31 | 35 | import net.minecraft.network.packet.Packet; |
32 | 36 | import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; |
33 | 37 | import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket; |
| 38 | +import net.minecraft.text.Text; |
| 39 | +import net.minecraft.util.Formatting; |
34 | 40 | import net.minecraft.util.Identifier; |
35 | 41 | import net.minecraft.util.math.BlockPos; |
36 | 42 | import org.jetbrains.annotations.NotNull; |
37 | 43 | import org.slf4j.Logger; |
38 | 44 | import org.slf4j.LoggerFactory; |
39 | 45 |
|
40 | | - |
41 | 46 | public class CodeClient implements ModInitializer { |
42 | 47 | public static final String MOD_NAME = "CodeClient"; |
43 | 48 | public static final String MOD_ID = "codeclient"; |
@@ -222,12 +227,53 @@ public static void onModeChange(Location location) { |
222 | 227 | currentAction.onModeChange(location); |
223 | 228 | } |
224 | 229 |
|
| 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 | + |
225 | 270 | /** |
226 | 271 | * Registers barriers as visible. |
227 | 272 | * Starts the API. |
228 | 273 | * Sets up auto join if enabled. |
229 | 274 | * Setups the edit bind. |
230 | 275 | * Registers command callback. |
| 276 | + * Registers dark mode resource pack. |
231 | 277 | */ |
232 | 278 | @Override |
233 | 279 | public void onInitialize() { |
@@ -259,6 +305,12 @@ public void onInitialize() { |
259 | 305 | Commands.register(dispatcher); |
260 | 306 | }); |
261 | 307 |
|
| 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 | + |
262 | 314 | CodeClient.LOGGER.info("CodeClient, making it easier to wipe your plot and get banned for hacks since 2022"); |
263 | 315 | } |
264 | 316 |
|
|
0 commit comments