diff --git a/README.md b/README.md index bfb9b55..e82a1c5 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,75 @@ forge: modApi "dev.tocraft:craftedcore-forge:1.20.2-2.0" ``` +## Building and installing locally + +This fork targets **Minecraft 26.1.2** and publishes to Maven Local (`~/.m2`). + +**Requirements:** JDK 21+, internet access for the first Gradle run (downloads MC assets). + +```bash +# Compile and publish all three artifacts (common, fabric, neoforge) to ~/.m2 +./gradlew publishToMavenLocal +``` + +To use the locally published artifacts in a dependent mod, add `mavenLocal()` to its repository list before any remote repos: + +```kotlin +repositories { + mavenLocal() + // ... other repos +} +``` + +Then depend on the artifacts as normal: + +```kotlin +// common +modApi("dev.tocraft:craftedcore:8.0") +// fabric +modApi("dev.tocraft:craftedcore-fabric:8.0") +// neoforge +modApi("dev.tocraft:craftedcore-neoforge:8.0") +``` + +To launch the Fabric test client: + +```bash +./gradlew :fabric:runClient +``` + +## Fork notes (MC 26.1.2) + +This is a fork of [ToCraft/craftedcore](https://github.com/ToCraft/craftedcore) updated to be compatible with **Minecraft Java Edition 26.1.2**, the first unobfuscated MC release (April 2026). The upstream library targets 1.21.x and below. + +### What changed + +**Minecraft API renames (global)** +- `net.minecraft.resources.ResourceLocation` → `net.minecraft.resources.Identifier` +- `net.minecraft.client.gui.GuiGraphics` → `net.minecraft.client.gui.GuiGraphicsExtractor` +- `GuiGraphics.renderItem()` → `GuiGraphicsExtractor.item()` +- `AbstractScrollArea` constructor requires a `ScrollbarSettings` argument; use `AbstractScrollArea.defaultSettings(width)` +- `MultiLineTextWidget.setColor()` removed; apply via `Component.copy().withStyle(s -> s.withColor(TextColor.fromRgb(...)))` +- `ServerLevel.getDayTime()` → `ServerLevel.getOverworldClockTime()` +- `player.hasPermissions(int)` → `player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER)` +- `Player.interactOn(Entity, InteractionHand)` gained a `Vec3` parameter +- `MultiPlayerGameMode.interact(Player, Entity, InteractionHand)` gained an `EntityHitResult` parameter +- `Minecraft.disconnect(Screen, boolean)` now delegates to a new 3-param overload; the actual disconnect logic (including the `GameNarrator.clear()` call site) moved to `disconnect(Screen, boolean, boolean)` + +**Fabric API renames (fabric-api 0.147.0+26.1.2)** +- `KeyBindingHelper` / `registerKeyBinding` → `KeyMappingHelper` / `registerKeyMapping` (package `keymapping.v1`) +- `ResourceLoader.registerReloader` → `registerReloadListener` +- `HudRenderCallback` removed; replaced by `HudElementRegistry.addLast(id, HudElement)` with `extractRenderState(GuiGraphicsExtractor, DeltaTracker)` method +- `ServerWorldEvents` → `ServerLevelEvents` (now matches craftedcore's own class name; use FQN to disambiguate) +- `EntitySleepEvents.ALLOW_SLEEP_TIME` removed; replaced by `ALLOW_SLEEPING` with `(Player, BlockPos) → BedSleepingProblem` callback (return `null` to allow, `OTHER_PROBLEM` to deny) +- `PayloadTypeRegistry.playC2S()` / `playS2C()` → `serverboundPlay()` / `clientboundPlay()` +- `FabricRegistryBuilder.createSimple` → `FabricRegistryBuilder.create` + +**NeoForge API renames** +- `SleepFinishedTimeEvent.getNewTime()` / `setTimeAddition(long)` removed; replaced by `getAdjustment()` / `setAdjustment(ClockAdjustment)`. Use `new ClockAdjustment.Absolute(time)` — `ClockAdjustment` is not a functional interface so lambdas do not work. + +**Build** +- Added `maven-publish` plugin to all subprojects for `publishToMavenLocal` support +- `processResources` `expand()` blocks: capture `project.property(...)` into local vals before the `filesMatching` block (inside the block `this` is `FileCopyDetails`, not `Project`) +- Added `compileOnly("net.fabricmc:fabric-loader:...")` to the neoforge subproject so common `@Environment(EnvType.CLIENT)` annotations compile + diff --git a/build.gradle.kts b/build.gradle.kts index 297adac..4cfbcc6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,15 +1,15 @@ plugins { - id("dev.tocraft.modmaster.root") version ("single-1.10.1") + id("dev.tocraft.modmaster.root") version ("2.1") } -val clothConfigVersion: String? = properties["cloth_config_version"] as String - -ext { - val modMeta = mutableMapOf() - modMeta["minecraft"] = project.properties["minecraft"] as String - modMeta["version"] = version - if (clothConfigVersion != null) { - modMeta["clothConfig"] = clothConfigVersion +subprojects { + repositories { + maven("https://maven.fabricmc.net/") // fabric api + maven("https://maven.terraformersmc.com/releases/") // mod menu mod + maven("https://maven.shedaniel.me/") // cloth config + maven { + name = "Minecraft Libraries" + url = uri("https://libraries.minecraft.net") + } } - set("mod_meta", modMeta) } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index a2b586c..1afec61 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -2,18 +2,15 @@ plugins { id("dev.tocraft.modmaster.common") } -val clothConfigVersion: String = parent!!.properties["cloth_config_version"] as String - -repositories { - maven("https://maven.terraformersmc.com/releases/") - maven("https://maven.shedaniel.me/") -} +val clothConfigVersion: String? = parent!!.properties["cloth_config_version"] as String? dependencies { - // mixin extras - implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:${rootProject.properties["mixinextras_version"]}")!!) - // Cloth Config - modCompileOnly("me.shedaniel.cloth:cloth-config:${clothConfigVersion}") { - exclude("net.fabricmc.fabric-api") + compileOnly("org.spongepowered:mixin:0.8.5") + compileOnly("io.github.llamalad7:mixinextras-common:${property("mixinextras_version")}") + annotationProcessor("io.github.llamalad7:mixinextras-common:${property("mixinextras_version")}") + if (clothConfigVersion != null) { + compileOnly("me.shedaniel.cloth:cloth-config:${clothConfigVersion}") { + exclude("net.fabricmc.fabric-api") + } } } \ No newline at end of file diff --git a/common/src/main/java/dev/tocraft/craftedcore/CraftedCore.java b/common/src/main/java/dev/tocraft/craftedcore/CraftedCore.java index 211b90a..7f29456 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/CraftedCore.java +++ b/common/src/main/java/dev/tocraft/craftedcore/CraftedCore.java @@ -9,9 +9,8 @@ import dev.tocraft.craftedcore.platform.PlayerProfile; import dev.tocraft.craftedcore.platform.VersionChecker; import dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistry; -import net.fabricmc.api.EnvType; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; @@ -28,7 +27,7 @@ public class CraftedCore { @ApiStatus.Internal public final static Path CACHE_DIR = PlatformData.getConfigPath().resolve(CraftedCore.MODID + File.separatorChar + "cache"); @ApiStatus.Internal - public static final ResourceLocation CLEAR_CACHE_PACKET = id("clear_cache"); + public static final Identifier CLEAR_CACHE_PACKET = id("clear_cache"); public static final String MODID = "craftedcore"; public void initialize() { @@ -60,7 +59,7 @@ public void initialize() { CraftedCoreCommand.initialize(); // register config screen - if (PlatformData.getEnv() == EnvType.CLIENT) { + if (PlatformData.getEnv() == PlatformData.Env.CLIENT) { PlatformData.registerConfigScreen(CraftedCoreConfig.INSTANCE.getName()); } } @@ -76,8 +75,8 @@ public static void reportMissingInternet(Throwable cause) { @Contract("_ -> new") @ApiStatus.Internal - public static @NotNull ResourceLocation id(String name) { - return ResourceLocation.fromNamespaceAndPath(MODID, name); + public static @NotNull Identifier id(String name) { + return Identifier.fromNamespaceAndPath(MODID, name); } @ApiStatus.Internal diff --git a/common/src/main/java/dev/tocraft/craftedcore/config/ConfigLoader.java b/common/src/main/java/dev/tocraft/craftedcore/config/ConfigLoader.java index 29adb6d..6b7091e 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/config/ConfigLoader.java +++ b/common/src/main/java/dev/tocraft/craftedcore/config/ConfigLoader.java @@ -13,9 +13,10 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; + import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -32,7 +33,7 @@ // heavily based on the work of Draylar - https://github.com/Draylar/omega-config/ and therefore this class is licensed under MIT public class ConfigLoader { - public static final ResourceLocation CONFIG_SYNC = CraftedCore.id("config_sync"); + public static final Identifier CONFIG_SYNC = CraftedCore.id("config_sync"); private static final Map LOADED_CONFIGS = new ConcurrentHashMap<>(); private static final List CLIENT_CONFIGS = new ArrayList<>(); private static final Gson GSON = new GsonBuilder().setPrettyPrinting().setStrictness(Strictness.LENIENT).create(); @@ -75,7 +76,7 @@ public static C register(String name, C @NotNull ... typeGett C config = read(name, clazz); - if (PlatformData.getEnv() == EnvType.CLIENT) { + if (PlatformData.getEnv() == PlatformData.Env.CLIENT) { PlatformData.registerConfigScreen(name); } diff --git a/common/src/main/java/dev/tocraft/craftedcore/data/PlayerDataSynchronizer.java b/common/src/main/java/dev/tocraft/craftedcore/data/PlayerDataSynchronizer.java index f1a02da..20b2946 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/data/PlayerDataSynchronizer.java +++ b/common/src/main/java/dev/tocraft/craftedcore/data/PlayerDataSynchronizer.java @@ -8,7 +8,7 @@ import dev.tocraft.craftedcore.registration.PlayerDataRegistry; import net.minecraft.core.UUIDUtil; import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.NotNull; @@ -18,7 +18,7 @@ public class PlayerDataSynchronizer { private static final String PLAYER_DATA_SYNC = "player_data_sync"; - public static final ResourceLocation PLAYER_DATA_SYNC_ID = CraftedCore.id(PLAYER_DATA_SYNC); + public static final Identifier PLAYER_DATA_SYNC_ID = CraftedCore.id(PLAYER_DATA_SYNC); public static void registerPacketHandler() { ModernNetworking.registerReceiver(ModernNetworking.Side.S2C, PLAYER_DATA_SYNC_ID, (context, tag) -> { diff --git a/common/src/main/java/dev/tocraft/craftedcore/data/SynchronizedJsonReloadListener.java b/common/src/main/java/dev/tocraft/craftedcore/data/SynchronizedJsonReloadListener.java index 70be284..3d7302b 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/data/SynchronizedJsonReloadListener.java +++ b/common/src/main/java/dev/tocraft/craftedcore/data/SynchronizedJsonReloadListener.java @@ -10,9 +10,10 @@ import dev.tocraft.craftedcore.platform.PlatformData; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; + import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.FileToIdConverter; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; @@ -31,11 +32,11 @@ */ @SuppressWarnings("unused") public abstract class SynchronizedJsonReloadListener extends - SimplePreparableReloadListener> { - public final ResourceLocation RELOAD_SYNC; + SimplePreparableReloadListener> { + public final Identifier RELOAD_SYNC; protected final String directory; protected final Gson gson; - private final Map map = new HashMap<>(); + private final Map map = new HashMap<>(); public SynchronizedJsonReloadListener(Gson gson, String directory) { this.gson = gson; @@ -43,22 +44,22 @@ public SynchronizedJsonReloadListener(Gson gson, String directory) { this.RELOAD_SYNC = CraftedCore.id("data_sync_" + directory); } - protected @NotNull Map prepare(ResourceManager resourceManager, ProfilerFiller profilerFiller) { - Map map = new HashMap<>(); + protected @NotNull Map prepare(ResourceManager resourceManager, ProfilerFiller profilerFiller) { + Map map = new HashMap<>(); scanDirectory(resourceManager, map); return map; } @Override - protected void apply(Map map, ResourceManager resourceManager, ProfilerFiller profiler) { + protected void apply(Map map, ResourceManager resourceManager, ProfilerFiller profiler) { this.map.clear(); this.map.putAll(map); - if (PlatformData.getEnv() == EnvType.SERVER) { + if (PlatformData.getEnv() == PlatformData.Env.SERVER) { this.onApply(this.map); } } - protected abstract void onApply(Map map); + protected abstract void onApply(Map map); public void sendSyncPacket(ServerPlayer player) { // Serialize unlocked to tag @@ -71,11 +72,11 @@ public void sendSyncPacket(ServerPlayer player) { @Environment(EnvType.CLIENT) private void onPacketReceive(ModernNetworking.Context context, CompoundTag compound) { - Map map = new HashMap<>(); + Map map = new HashMap<>(); if (compound != null) { for (String key : compound.keySet()) { String json = compound.getString(key).orElseThrow(); - map.put(ResourceLocation.parse(key), JsonParser.parseString(json)); + map.put(Identifier.parse(key), JsonParser.parseString(json)); } } this.onApply(map); @@ -86,12 +87,12 @@ public void registerPacketReceiver() { ModernNetworking.registerReceiver(ModernNetworking.Side.S2C, RELOAD_SYNC, this::onPacketReceive); } - private void scanDirectory(ResourceManager resourceManager, Map map) { + private void scanDirectory(ResourceManager resourceManager, Map map) { FileToIdConverter var4 = FileToIdConverter.json(directory); - Iterable> entrySet = var4.listMatchingResources(resourceManager).entrySet(); - for (Map.Entry entry : entrySet) { - ResourceLocation var7 = entry.getKey(); - ResourceLocation var8 = var4.fileToId(var7); + Iterable> entrySet = var4.listMatchingResources(resourceManager).entrySet(); + for (Map.Entry entry : entrySet) { + Identifier var7 = entry.getKey(); + Identifier var8 = var4.fileToId(var7); try { BufferedReader reader = entry.getValue().openAsReader(); try { diff --git a/common/src/main/java/dev/tocraft/craftedcore/event/client/RenderEvents.java b/common/src/main/java/dev/tocraft/craftedcore/event/client/RenderEvents.java index 008332d..c1401cc 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/event/client/RenderEvents.java +++ b/common/src/main/java/dev/tocraft/craftedcore/event/client/RenderEvents.java @@ -5,7 +5,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.DeltaTracker; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.Nullable; @@ -22,12 +22,12 @@ public final class RenderEvents { @Environment(EnvType.CLIENT) @FunctionalInterface public interface HUDRendering { - void render(GuiGraphics graphics, DeltaTracker tickCounter); + void extractRenderState(GuiGraphicsExtractor graphics, DeltaTracker tickCounter); } @Environment(EnvType.CLIENT) @FunctionalInterface public interface OverlayRendering { - InteractionResult render(@Nullable GuiGraphics graphics, Player player); + InteractionResult render(@Nullable GuiGraphicsExtractor graphics, Player player); } } diff --git a/common/src/main/java/dev/tocraft/craftedcore/event/common/PlayerEvents.java b/common/src/main/java/dev/tocraft/craftedcore/event/common/PlayerEvents.java index 8153351..497fcd2 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/event/common/PlayerEvents.java +++ b/common/src/main/java/dev/tocraft/craftedcore/event/common/PlayerEvents.java @@ -25,7 +25,7 @@ public final class PlayerEvents { long newNewTime = 0; for (SleepFinishedTime callback : callbacks) { long newTimeIn = callback.setTimeAddition(level, newTime); - if (level.getDayTime() <= newTime) { + if (level.getOverworldClockTime() <= newTime) { newNewTime = newTimeIn; } } diff --git a/common/src/main/java/dev/tocraft/craftedcore/gui/LongTextWidget.java b/common/src/main/java/dev/tocraft/craftedcore/gui/LongTextWidget.java index 5ec9d49..90719cd 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/gui/LongTextWidget.java +++ b/common/src/main/java/dev/tocraft/craftedcore/gui/LongTextWidget.java @@ -2,7 +2,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.components.AbstractScrollArea; import net.minecraft.client.gui.components.MultiLineTextWidget; import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; @@ -13,6 +13,7 @@ import net.minecraft.client.sounds.SoundManager; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.TextColor; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -25,7 +26,7 @@ public class LongTextWidget extends AbstractScrollArea { private final int row_width; public LongTextWidget(int x, int y, int width, int height, boolean separators, int row_width) { - super(x, y, width, height, Component.nullToEmpty("")); + super(x, y, width, height, Component.nullToEmpty(""), AbstractScrollArea.defaultSettings(SCROLLBAR_WIDTH)); this.separators = separators; this.row_width = row_width; } @@ -46,7 +47,8 @@ public void addText(Component text) { } public void addText(Component text, Font font, int color) { - this.text.add(new MultiLineTextWidget(text, font).setColor(color)); + Component styled = (color != -1) ? text.copy().withStyle(s -> s.withColor(TextColor.fromRgb(color & 0xFFFFFF))) : text; + this.text.add(new MultiLineTextWidget(styled, font)); } protected int textWidth() { @@ -64,7 +66,7 @@ protected int scrollBarX() { } @Override - protected void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { + protected void extractWidgetRenderState(@NotNull GuiGraphicsExtractor guiGraphics, int mouseX, int mouseY, float delta) { guiGraphics.enableScissor(this.getX(), this.getY(), this.getRight(), this.getBottom()); int x = this.getX() + (getWidth() - textWidth()) / 2; @@ -72,20 +74,20 @@ protected void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mo for (MultiLineTextWidget widget : this.text) { widget.setPosition(x, y); widget.setMaxWidth(textWidth()); - widget.render(guiGraphics, mouseX, mouseY, delta); + widget.extractRenderState(guiGraphics, mouseX, mouseY, delta); y += widget.getHeight(); } guiGraphics.disableScissor(); - renderScrollbar(guiGraphics, mouseX, mouseY); + extractScrollbar(guiGraphics, mouseX, mouseY); if (separators) { renderSeparators(guiGraphics); } } - protected void renderSeparators(@NotNull GuiGraphics guiGraphics) { + protected void renderSeparators(@NotNull GuiGraphicsExtractor guiGraphics) { guiGraphics.blit(RenderPipelines.GUI_TEXTURED, Screen.INWORLD_HEADER_SEPARATOR, this.getX(), this.getY() - 2, 0.0F, 0.0F, this.getWidth(), 2, 32, 2); guiGraphics.blit(RenderPipelines.GUI_TEXTURED, Screen.INWORLD_FOOTER_SEPARATOR, this.getX(), this.getBottom(), 0.0F, 0.0F, this.getWidth(), 2, 32, 2); } diff --git a/common/src/main/java/dev/tocraft/craftedcore/gui/TextureCache.java b/common/src/main/java/dev/tocraft/craftedcore/gui/TextureCache.java index 85ca6ba..c3b21e2 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/gui/TextureCache.java +++ b/common/src/main/java/dev/tocraft/craftedcore/gui/TextureCache.java @@ -6,7 +6,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; import java.io.ByteArrayInputStream; @@ -20,7 +20,7 @@ @SuppressWarnings("unused") @Environment(EnvType.CLIENT) public class TextureCache { - private static final Map> TEXTURE_CACHE = new ConcurrentHashMap<>(); + private static final Map> TEXTURE_CACHE = new ConcurrentHashMap<>(); /** * Converts a URL to a readable id @@ -33,9 +33,9 @@ public class TextureCache { * @return the id if the texture could be cached or null, if there was an exception */ @Nullable - public static ResourceLocation getTextureId(String namespace, String type, String prefix, String fileType, URL textureURL) { + public static Identifier getTextureId(String namespace, String type, String prefix, String fileType, URL textureURL) { return TEXTURE_CACHE.computeIfAbsent(String.valueOf(textureURL), key -> { - ResourceLocation id = ResourceLocation.fromNamespaceAndPath(namespace, "textures/" + type + "/" + prefix + key.hashCode() + "." + fileType); + Identifier id = Identifier.fromNamespaceAndPath(namespace, "textures/" + type + "/" + prefix + key.hashCode() + "." + fileType); try (InputStream is = textureURL.openStream()) { NativeImage image = NativeImage.read(new ByteArrayInputStream(is.readAllBytes())); DynamicTexture dynamicTexture = new DynamicTexture(id::toString, image); diff --git a/common/src/main/java/dev/tocraft/craftedcore/gui/TimerOverlayRenderer.java b/common/src/main/java/dev/tocraft/craftedcore/gui/TimerOverlayRenderer.java index e17c899..1c6c78d 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/gui/TimerOverlayRenderer.java +++ b/common/src/main/java/dev/tocraft/craftedcore/gui/TimerOverlayRenderer.java @@ -1,14 +1,14 @@ package dev.tocraft.craftedcore.gui; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.client.gui.screens.ChatScreen; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @SuppressWarnings("unused") public class TimerOverlayRenderer { - public static void register(GuiGraphics graphics, int currentCooldown, int maxCooldown, Item item) { + public static void register(GuiGraphicsExtractor graphics, int currentCooldown, int maxCooldown, Item item) { Minecraft client = Minecraft.getInstance(); if (client.screen instanceof ChatScreen || currentCooldown <= 0 || item == null) { @@ -32,7 +32,7 @@ public static void register(GuiGraphics graphics, int currentCooldown, int maxCo } ItemStack stack = new ItemStack(item); - graphics.renderItem(stack, (int) (width * .95f), (int) (height * .92f)); + graphics.item(stack, (int) (width * .95f), (int) (height * .92f)); if (cooldownScale != 1) { graphics.disableScissor(); diff --git a/common/src/main/java/dev/tocraft/craftedcore/mixin/MultiPlayerGameModeMixin.java b/common/src/main/java/dev/tocraft/craftedcore/mixin/MultiPlayerGameModeMixin.java index c76cf27..d8f1adb 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/mixin/MultiPlayerGameModeMixin.java +++ b/common/src/main/java/dev/tocraft/craftedcore/mixin/MultiPlayerGameModeMixin.java @@ -6,6 +6,7 @@ import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.EntityHitResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,7 +18,7 @@ public class MultiPlayerGameModeMixin { at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;send(Lnet/minecraft/network/protocol/Packet;)V", shift = At.Shift.AFTER), cancellable = true) - private void entityInteract(Player player, Entity entity, InteractionHand interactionHand, CallbackInfoReturnable cir) { + private void entityInteract(Player player, Entity entity, EntityHitResult hitResult, InteractionHand interactionHand, CallbackInfoReturnable cir) { InteractionResult result = EntityEvents.INTERACT_WITH_PLAYER.invoke().interact(player, entity, interactionHand); if (result != InteractionResult.PASS) { cir.setReturnValue(result); diff --git a/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java b/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java index 9849c8d..7528e0b 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java +++ b/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerAdvancementsMixin.java @@ -22,6 +22,8 @@ private void afterAward(AdvancementHolder advancement, String criterionKey, Call @Inject(method = "revoke", at = @At(value = "RETURN")) private void afterRevoke(AdvancementHolder advancement, String criterionKey, CallbackInfoReturnable cir) { - PlayerEvents.REVOKE_ADVANCEMENT.invoke().revoke(this.player, advancement, criterionKey); + if (cir.getReturnValue()) { + PlayerEvents.REVOKE_ADVANCEMENT.invoke().revoke(this.player, advancement, criterionKey); + } } } diff --git a/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerMixin.java b/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerMixin.java index 052a2d8..d55fa2f 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerMixin.java +++ b/common/src/main/java/dev/tocraft/craftedcore/mixin/PlayerMixin.java @@ -9,6 +9,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; +import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -47,7 +48,7 @@ private void writeNbt(ValueOutput out, CallbackInfo ci) { target = "Lnet/minecraft/world/entity/player/Player;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;", ordinal = 0), cancellable = true) - private void onInteraction(Entity entity, InteractionHand interactionHand, CallbackInfoReturnable cir) { + private void onInteraction(Entity entity, InteractionHand interactionHand, Vec3 hitVec, CallbackInfoReturnable cir) { InteractionResult result = EntityEvents.INTERACT_WITH_PLAYER.invoke().interact((Player) (Object) this, entity, interactionHand); if (result != InteractionResult.PASS) { cir.setReturnValue(result); diff --git a/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworking.java b/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworking.java index ec34073..b4ae8b9 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworking.java +++ b/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworking.java @@ -1,6 +1,5 @@ package dev.tocraft.craftedcore.network; -import dev.architectury.injectables.annotations.ExpectPlatform; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -10,7 +9,7 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.ApiStatus; @@ -19,40 +18,41 @@ import java.util.HashMap; import java.util.Map; +import java.util.ServiceLoader; @SuppressWarnings("unused") public class ModernNetworking { - private static final Map> TYPES = new HashMap<>(); + private static final ModernNetworkingService SERVICE = + ServiceLoader.load(ModernNetworkingService.class).findFirst().orElseThrow(); + private static final Map> TYPES = new HashMap<>(); - @ExpectPlatform - public static void registerReceiver(Side side, ResourceLocation id, Receiver receiver) { - throw new AssertionError(); + public static void registerReceiver(Side side, Identifier id, Receiver receiver) { + SERVICE.registerReceiver(side, id, receiver); } - @ExpectPlatform - public static void registerType(ResourceLocation id) { - throw new AssertionError(); + public static void registerType(Identifier id) { + SERVICE.registerType(id); } - public static CustomPacketPayload.Type getType(ResourceLocation id) { + public static CustomPacketPayload.Type getType(Identifier id) { if (!TYPES.containsKey(id)) { TYPES.put(id, new CustomPacketPayload.Type<>(id)); } return TYPES.get(id); } - public static void sendToPlayer(@NotNull ServerPlayer player, ResourceLocation packetId, CompoundTag data) { + public static void sendToPlayer(@NotNull ServerPlayer player, Identifier packetId, CompoundTag data) { player.connection.send(toPacket(Side.S2C, new PacketPayload(packetId, data))); } - public static void sendToPlayers(@NotNull Iterable players, ResourceLocation packetId, CompoundTag data) { + public static void sendToPlayers(@NotNull Iterable players, Identifier packetId, CompoundTag data) { for (ServerPlayer player : players) { sendToPlayer(player, packetId, data); } } @Environment(EnvType.CLIENT) - public static void sendToServer(ResourceLocation packetId, CompoundTag data) { + public static void sendToServer(Identifier packetId, CompoundTag data) { ClientPacketListener connection = Minecraft.getInstance().getConnection(); if (connection != null) { @@ -60,10 +60,9 @@ public static void sendToServer(ResourceLocation packetId, CompoundTag data) { } } - @ExpectPlatform @ApiStatus.Internal public static Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { - throw new AssertionError(); + return SERVICE.toPacket(side, payload); } @FunctionalInterface @@ -88,16 +87,16 @@ public enum Env { } @ApiStatus.Internal - public record PacketPayload(ResourceLocation id, + public record PacketPayload(Identifier id, CompoundTag nbt) implements CustomPacketPayload { public void write(@NotNull RegistryFriendlyByteBuf buf) { - buf.writeResourceLocation(id); + buf.writeIdentifier(id); buf.writeNbt(nbt); } public PacketPayload(@NotNull RegistryFriendlyByteBuf buf) { - this(buf.readResourceLocation(), buf.readNbt()); + this(buf.readIdentifier(), buf.readNbt()); } @Override @@ -115,7 +114,7 @@ public PacketPayload(@NotNull RegistryFriendlyByteBuf buf) { @Override public void encode(@NotNull RegistryFriendlyByteBuf buf, @NotNull PacketPayload payload) { - buf.writeResourceLocation(payload.id); + buf.writeIdentifier(payload.id); buf.writeNbt(payload.nbt); } }; diff --git a/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworkingService.java b/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworkingService.java new file mode 100644 index 0000000..5ca359b --- /dev/null +++ b/common/src/main/java/dev/tocraft/craftedcore/network/ModernNetworkingService.java @@ -0,0 +1,13 @@ +package dev.tocraft.craftedcore.network; + +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.Identifier; + +public interface ModernNetworkingService { + void registerReceiver(ModernNetworking.Side side, Identifier id, ModernNetworking.Receiver receiver); + + void registerType(Identifier id); + + Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload); +} diff --git a/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionChecker.java b/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionChecker.java index 27fac1b..13335d7 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionChecker.java +++ b/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionChecker.java @@ -1,16 +1,14 @@ package dev.tocraft.craftedcore.permission; -import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.NotNull; -/** - * Cross-platform permission manager interface for ReMorphed mod. - * Implementations handle platform-specific permission checks. - * NOTE: Requires Fabric Permissions API on Fabric to work properly - */ +import java.util.ServiceLoader; + @SuppressWarnings("unused") public class PermissionChecker { + private static final PermissionCheckerService SERVICE = + ServiceLoader.load(PermissionCheckerService.class).findFirst().orElseThrow(); /** * Check if a player has a specific permission node @@ -20,8 +18,7 @@ public class PermissionChecker { * @param permission The permission node to check * @return true if the player has the permission */ - @ExpectPlatform public static boolean hasPermission(@NotNull ServerPlayer player, @NotNull String namespace, @NotNull String permission) { - throw new AssertionError(); + return SERVICE.hasPermission(player, namespace, permission); } } diff --git a/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionCheckerService.java b/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionCheckerService.java new file mode 100644 index 0000000..a169bd1 --- /dev/null +++ b/common/src/main/java/dev/tocraft/craftedcore/permission/PermissionCheckerService.java @@ -0,0 +1,8 @@ +package dev.tocraft.craftedcore.permission; + +import net.minecraft.server.level.ServerPlayer; +import org.jetbrains.annotations.NotNull; + +public interface PermissionCheckerService { + boolean hasPermission(@NotNull ServerPlayer player, @NotNull String namespace, @NotNull String permission); +} diff --git a/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformData.java b/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformData.java index ba11afd..504c2ed 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformData.java +++ b/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformData.java @@ -1,6 +1,5 @@ package dev.tocraft.craftedcore.platform; -import dev.architectury.injectables.annotations.ExpectPlatform; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; @@ -9,51 +8,56 @@ import java.lang.module.ModuleDescriptor.Version; import java.nio.file.Path; +import java.util.ServiceLoader; @SuppressWarnings({"unused", "Contract"}) public final class PlatformData { - @ExpectPlatform + private static final PlatformDataService SERVICE = + ServiceLoader.load(PlatformDataService.class).findFirst().orElseThrow(); + public static boolean isModLoaded(String modid) { - throw new AssertionError(); + return SERVICE.isModLoaded(modid); } - @ExpectPlatform @Nullable public static Version getModVersion(String modid) { - throw new AssertionError(); + return SERVICE.getModVersion(modid); } - @ExpectPlatform public static boolean isDevEnv() { - throw new AssertionError(); + return SERVICE.isDevEnv(); } @Contract(value = " -> !null", pure = true) - @ExpectPlatform - public static EnvType getEnv() { - throw new AssertionError(); + public static Env getEnv() { + return SERVICE.getEnv(); } - @ExpectPlatform @Contract(value = " -> !null", pure = true) public static Path getConfigPath() { - throw new AssertionError(); + return SERVICE.getConfigPath(); } - @ExpectPlatform @Contract(value = " -> !null", pure = true) public static ModLoader getModLoaderId() { - throw new AssertionError(); + return SERVICE.getModLoaderId(); } - @ExpectPlatform @ApiStatus.Internal @Environment(EnvType.CLIENT) public static void registerConfigScreen(String name) { - throw new AssertionError(); + SERVICE.registerConfigScreen(name); } public enum ModLoader { FABRIC, FORGE, NEOFORGE, OTHER } + + public enum Env { + CLIENT, SERVER; + + public boolean isClient() { + return this == CLIENT; + } + } } diff --git a/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformDataService.java b/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformDataService.java new file mode 100644 index 0000000..c6645e8 --- /dev/null +++ b/common/src/main/java/dev/tocraft/craftedcore/platform/PlatformDataService.java @@ -0,0 +1,23 @@ +package dev.tocraft.craftedcore.platform; + +import org.jetbrains.annotations.Nullable; + +import java.lang.module.ModuleDescriptor.Version; +import java.nio.file.Path; + +public interface PlatformDataService { + boolean isModLoaded(String modid); + + @Nullable + Version getModVersion(String modid); + + boolean isDevEnv(); + + PlatformData.Env getEnv(); + + Path getConfigPath(); + + PlatformData.ModLoader getModLoaderId(); + + void registerConfigScreen(String name); +} diff --git a/common/src/main/java/dev/tocraft/craftedcore/platform/PlayerProfile.java b/common/src/main/java/dev/tocraft/craftedcore/platform/PlayerProfile.java index 55ace16..04be97a 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/platform/PlayerProfile.java +++ b/common/src/main/java/dev/tocraft/craftedcore/platform/PlayerProfile.java @@ -5,7 +5,7 @@ import dev.tocraft.craftedcore.CraftedCoreConfig; import dev.tocraft.craftedcore.gui.TextureCache; import dev.tocraft.craftedcore.util.NetUtils; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -213,7 +213,7 @@ private static PlayerProfile _ofId(@NotNull final UUID uuid) { } @Nullable - public ResourceLocation getSkinId() { + public Identifier getSkinId() { if (skin != null) { return TextureCache.getTextureId(CraftedCore.MODID, "entity", "custom_skin_", "png", skin); } else { @@ -222,7 +222,7 @@ public ResourceLocation getSkinId() { } @Nullable - public ResourceLocation getCapeId() { + public Identifier getCapeId() { if (cape != null) { return TextureCache.getTextureId(CraftedCore.MODID, "entity", "custom_cape_", "png", cape); } else { diff --git a/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistry.java b/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistry.java index ec238b1..a9c0c7b 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistry.java +++ b/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistry.java @@ -1,15 +1,18 @@ package dev.tocraft.craftedcore.registration; -import dev.architectury.injectables.annotations.ExpectPlatform; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.KeyMapping; +import java.util.ServiceLoader; + @SuppressWarnings("unused") @Environment(EnvType.CLIENT) public final class KeyBindingRegistry { - @ExpectPlatform + private static final KeyBindingRegistryService SERVICE = + ServiceLoader.load(KeyBindingRegistryService.class).findFirst().orElseThrow(); + public static void register(KeyMapping keyMapping) { - throw new AssertionError(); + SERVICE.register(keyMapping); } } diff --git a/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistryService.java b/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistryService.java new file mode 100644 index 0000000..296975d --- /dev/null +++ b/common/src/main/java/dev/tocraft/craftedcore/registration/KeyBindingRegistryService.java @@ -0,0 +1,7 @@ +package dev.tocraft.craftedcore.registration; + +import net.minecraft.client.KeyMapping; + +public interface KeyBindingRegistryService { + void register(KeyMapping keyMapping); +} diff --git a/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistry.java b/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistry.java index a0abc42..bd8e512 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistry.java +++ b/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistry.java @@ -1,14 +1,17 @@ package dev.tocraft.craftedcore.registration; -import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryDataLoader; import net.minecraft.resources.ResourceKey; +import java.util.ServiceLoader; + public class RegistryRegistry { - @ExpectPlatform + private static final RegistryRegistryService SERVICE = + ServiceLoader.load(RegistryRegistryService.class).findFirst().orElseThrow(); + public static Registry createSimpleRegistry(ResourceKey> key) { - throw new AssertionError(); + return SERVICE.createSimpleRegistry(key); } public static void registerWorldgen(RegistryDataLoader.RegistryData registryData) { diff --git a/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistryService.java b/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistryService.java new file mode 100644 index 0000000..1ccea0f --- /dev/null +++ b/common/src/main/java/dev/tocraft/craftedcore/registration/RegistryRegistryService.java @@ -0,0 +1,8 @@ +package dev.tocraft.craftedcore.registration; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; + +public interface RegistryRegistryService { + Registry createSimpleRegistry(ResourceKey> key); +} diff --git a/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java b/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java index c6afc59..d507956 100644 --- a/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java +++ b/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistry.java @@ -1,12 +1,10 @@ package dev.tocraft.craftedcore.registration; -import dev.architectury.injectables.annotations.ExpectPlatform; import dev.tocraft.craftedcore.data.SynchronizedJsonReloadListener; import dev.tocraft.craftedcore.event.common.ResourceEvents; import dev.tocraft.craftedcore.network.ModernNetworking; import dev.tocraft.craftedcore.platform.PlatformData; -import net.fabricmc.api.EnvType; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; @@ -14,45 +12,35 @@ import java.util.HashMap; import java.util.Map; +import java.util.ServiceLoader; @SuppressWarnings("UnreachableCode") public class SynchronizedReloadListenerRegistry { - private static final Map listener = new HashMap<>(); + private static final SynchronizedReloadListenerRegistryService SERVICE = + ServiceLoader.load(SynchronizedReloadListenerRegistryService.class).findFirst().orElseThrow(); + private static final Map listener = new HashMap<>(); - /** - * Register a serverside synchronized json reload listener - */ @SuppressWarnings("unused") - public static void register(SynchronizedJsonReloadListener reloadListener, ResourceLocation id) { + public static void register(SynchronizedJsonReloadListener reloadListener, Identifier id) { listener.put(id, reloadListener); - // Register Data Packet receiver - if (PlatformData.getEnv() == EnvType.CLIENT) { + if (PlatformData.getEnv() == PlatformData.Env.CLIENT) { reloadListener.registerPacketReceiver(); } - - // register Network packet ModernNetworking.registerType(reloadListener.RELOAD_SYNC); - onRegister(reloadListener, id); - } - - @SuppressWarnings("unused") - @ApiStatus.Internal - @ExpectPlatform - private static void onRegister(SynchronizedJsonReloadListener reloadListener, ResourceLocation id) { - throw new AssertionError(); + SERVICE.onRegister(reloadListener, id); } @Contract(" -> new") @ApiStatus.Internal - public static @NotNull Map getAllListener() { + public static @NotNull Map getAllListener() { return new HashMap<>(listener); } @SuppressWarnings("unused") - public static SynchronizedJsonReloadListener get(ResourceLocation id) { + public static SynchronizedJsonReloadListener get(Identifier id) { return listener.get(id); } diff --git a/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistryService.java b/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistryService.java new file mode 100644 index 0000000..cb02778 --- /dev/null +++ b/common/src/main/java/dev/tocraft/craftedcore/registration/SynchronizedReloadListenerRegistryService.java @@ -0,0 +1,8 @@ +package dev.tocraft.craftedcore.registration; + +import dev.tocraft.craftedcore.data.SynchronizedJsonReloadListener; +import net.minecraft.resources.Identifier; + +public interface SynchronizedReloadListenerRegistryService { + void onRegister(SynchronizedJsonReloadListener reloadListener, Identifier id); +} diff --git a/common/src/main/resources/craftedcore.mixins.json b/common/src/main/resources/craftedcore.mixins.json index c01e667..c0ca90e 100644 --- a/common/src/main/resources/craftedcore.mixins.json +++ b/common/src/main/resources/craftedcore.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "dev.tocraft.craftedcore.mixin", - "compatibilityLevel": "JAVA_21", + "compatibilityLevel": "JAVA_25", "mixins": [ "CrashReportCategoryMixin", "CrashReportMixin", diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index bf13828..eb5c8d0 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -2,36 +2,43 @@ plugins { id("dev.tocraft.modmaster.fabric") } -tasks.withType { - @Suppress("UNCHECKED_CAST") val modMeta = parent!!.ext["mod_meta"]!! as Map - //inputs.properties.putAll(modMeta) - - filesMatching("fabric.mod.json") { - expand(modMeta) - } - - outputs.upToDateWhen { false } -} - -val modMenuVersion: String? = parent!!.properties["modmenu_version"] as String +dependencies { + minecraft("com.mojang:minecraft:${property("minecraft")}") + implementation("net.fabricmc:fabric-loader:${property("fabric_loader")}") + implementation("net.fabricmc.fabric-api:fabric-api:${property("fabric")}") -val clothConfigVersion: String = parent!!.properties["cloth_config_version"] as String + commonJava(project(":common", "commonJava")) + commonResources(project(":common", "commonResources")) -repositories { - maven("https://maven.terraformersmc.com/releases/") - maven("https://maven.shedaniel.me/") -} + // MixinExtras bundled with the mod + include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${property("mixinextras_version")}")!!)!!) -dependencies { - // mixin extras - include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${rootProject.properties["mixinextras_version"]}")!!)!!) + val modMenuVersion = properties["modmenu_version"] as String? if (modMenuVersion != null) { - modRuntimeOnly("com.terraformersmc:modmenu:${modMenuVersion}") { - isTransitive = false + compileOnly("com.terraformersmc:modmenu:${modMenuVersion}") { isTransitive = false } + runtimeOnly("com.terraformersmc:modmenu:${modMenuVersion}") { isTransitive = false } + } + val clothConfigVersion = properties["cloth_config_version"] as String? + if (clothConfigVersion != null) { + compileOnly("me.shedaniel.cloth:cloth-config-fabric:${clothConfigVersion}") { + exclude(group = "net.fabricmc.fabric-api") + } + runtimeOnly("me.shedaniel.cloth:cloth-config-fabric:${clothConfigVersion}") { + exclude(group = "net.fabricmc.fabric-api") } } - // Cloth Config - modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:${clothConfigVersion}") { - exclude("net.fabricmc.fabric-api") +} + +tasks.processResources { + from("commonResources") + val mcVersion = project.property("minecraft") + val clothVersion = project.property("cloth_config_version") + filesMatching("fabric.mod.json") { + expand(mapOf( + "version" to project.version, + "minecraft" to mcVersion, + "clothConfig" to clothVersion + )) } + outputs.upToDateWhen { false } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java index 8d27b7b..75176e1 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/CraftedCoreFabricEventHandler.java @@ -5,16 +5,20 @@ import dev.tocraft.craftedcore.event.common.ServerLevelEvents; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal public class CraftedCoreFabricEventHandler { public static void initialize() { - EntitySleepEvents.ALLOW_SLEEP_TIME.register((player, sleepingPos, vanillaResult) -> PlayerEvents.ALLOW_SLEEP_TIME.invoke().allowSleepTime(player, sleepingPos, vanillaResult)); + EntitySleepEvents.ALLOW_SLEEPING.register((player, sleepingPos) -> { + InteractionResult result = PlayerEvents.ALLOW_SLEEP_TIME.invoke().allowSleepTime(player, sleepingPos, true); + return result == InteractionResult.FAIL ? Player.BedSleepingProblem.OTHER_PROBLEM : null; + }); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandEvents.REGISTRATION.invoke().register(dispatcher, registryAccess, environment)); - ServerWorldEvents.LOAD.register((server, world) -> ServerLevelEvents.LEVEL_LOAD.invoke().call(world)); - ServerWorldEvents.UNLOAD.register((server, world) -> ServerLevelEvents.LEVEL_UNLOAD.invoke().call(world)); + net.fabricmc.fabric.api.event.lifecycle.v1.ServerLevelEvents.LOAD.register((server, world) -> ServerLevelEvents.LEVEL_LOAD.invoke().call(world)); + net.fabricmc.fabric.api.event.lifecycle.v1.ServerLevelEvents.UNLOAD.register((server, world) -> ServerLevelEvents.LEVEL_UNLOAD.invoke().call(world)); } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/client/CraftedCoreFabricEventHandlerClient.java b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/client/CraftedCoreFabricEventHandlerClient.java index 0c9cdf6..54a65e5 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/client/CraftedCoreFabricEventHandlerClient.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/client/CraftedCoreFabricEventHandlerClient.java @@ -1,10 +1,11 @@ package dev.tocraft.craftedcore.fabric.client; +import dev.tocraft.craftedcore.CraftedCore; import dev.tocraft.craftedcore.event.client.RenderEvents; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; +import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal @@ -12,7 +13,7 @@ public class CraftedCoreFabricEventHandlerClient { public static void initialize() { - HudRenderCallback.EVENT.register((graphics, tickCounter) -> RenderEvents.HUD_RENDERING.invoke().render(graphics, tickCounter)); + HudElementRegistry.addLast(CraftedCore.id("hud_render"), (graphics, tickCounter) -> RenderEvents.HUD_RENDERING.invoke().extractRenderState(graphics, tickCounter)); ClientTickEvents.START_CLIENT_TICK.register(instance -> dev.tocraft.craftedcore.event.client.ClientTickEvents.CLIENT_PRE.invoke().tick(instance)); ClientTickEvents.END_CLIENT_TICK.register(instance -> dev.tocraft.craftedcore.event.client.ClientTickEvents.CLIENT_POST.invoke().tick(instance)); } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java index 405e305..13ec028 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/GuiMixin.java @@ -4,7 +4,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiGraphicsExtractor; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.ApiStatus; @@ -23,32 +23,32 @@ public abstract class GuiMixin { @Shadow protected abstract Player getCameraPlayer(); - @Inject(method = "renderAirBubbles", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), cancellable = true) - private void shouldRenderBreath(GuiGraphics guiGraphics, Player player, int i, int j, int k, CallbackInfo ci) { + @Inject(method = "extractAirBubbles", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), cancellable = true) + private void shouldRenderBreath(GuiGraphicsExtractor guiGraphics, Player player, int i, int j, int k, CallbackInfo ci) { InteractionResult result = RenderEvents.RENDER_BREATH.invoke().render(guiGraphics, this.getCameraPlayer()); if (result == InteractionResult.FAIL) { ci.cancel(); } } - @Inject(method = "renderHearts", at = @At(value = "HEAD"), cancellable = true) - private void shouldRenderHealth(GuiGraphics guiGraphics, Player player, int x, int y, int height, int offsetHeartIndex, float maxHealth, int currentHealth, int displayHealth, int absorptionAmount, boolean renderHighlight, CallbackInfo ci) { + @Inject(method = "extractHearts", at = @At(value = "HEAD"), cancellable = true) + private void shouldRenderHealth(GuiGraphicsExtractor guiGraphics, Player player, int x, int y, int height, int offsetHeartIndex, float maxHealth, int currentHealth, int displayHealth, int absorptionAmount, boolean renderHighlight, CallbackInfo ci) { InteractionResult result = RenderEvents.RENDER_HEALTH.invoke().render(guiGraphics, player); if (result == InteractionResult.FAIL) { ci.cancel(); } } - @Inject(method = "renderFood", at = @At(value = "HEAD"), cancellable = true) - private void shouldRenderFood(GuiGraphics guiGraphics, Player player, int y, int x, CallbackInfo ci) { + @Inject(method = "extractFood", at = @At(value = "HEAD"), cancellable = true) + private void shouldRenderFood(GuiGraphicsExtractor guiGraphics, Player player, int y, int x, CallbackInfo ci) { InteractionResult result = RenderEvents.RENDER_FOOD.invoke().render(guiGraphics, player); if (result == InteractionResult.FAIL) { ci.cancel(); } } - @Inject(method = "renderVehicleHealth", at = @At(value = "HEAD"), cancellable = true) - private void shouldRenderMountHealth(GuiGraphics guiGraphics, CallbackInfo ci) { + @Inject(method = "extractVehicleHealth", at = @At(value = "HEAD"), cancellable = true) + private void shouldRenderMountHealth(GuiGraphicsExtractor guiGraphics, CallbackInfo ci) { InteractionResult result = RenderEvents.RENDER_MOUNT_HEALTH.invoke().render(guiGraphics, this.getCameraPlayer()); if (result == InteractionResult.FAIL) { ci.cancel(); diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java index b1793c1..ee946f8 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/fabric/mixin/client/MinecraftClientMixin.java @@ -16,9 +16,9 @@ @Environment(EnvType.CLIENT) @Mixin(Minecraft.class) public abstract class MinecraftClientMixin { - @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V", + @Inject(method = "disconnect(Lnet/minecraft/client/gui/screens/Screen;ZZ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/GameNarrator;clear()V")) - private void onDisconnect(Screen screen, boolean retainDownloadedPacks, CallbackInfo ci) { + private void onDisconnect(Screen screen, boolean retainDownloadedPacks, boolean dropClientLevel, CallbackInfo ci) { ClientPlayerEvents.CLIENT_PLAYER_QUIT.invoke().quit(Minecraft.getInstance().player); } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java b/fabric/src/main/java/dev/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java index 34c59f0..f80b464 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/network/fabric/ModernNetworkingImpl.java @@ -2,6 +2,7 @@ import dev.tocraft.craftedcore.network.ModernNetworking; import dev.tocraft.craftedcore.network.ModernNetworking.PacketPayload; +import dev.tocraft.craftedcore.network.ModernNetworkingService; import net.fabricmc.api.EnvType; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; @@ -11,7 +12,7 @@ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.MinecraftServer; import net.minecraft.world.entity.player.Player; import org.jetbrains.annotations.ApiStatus; @@ -21,10 +22,11 @@ import static dev.tocraft.craftedcore.network.ModernNetworking.getType; @SuppressWarnings({"unused", "resource"}) -public class ModernNetworkingImpl { - public static void registerReceiver(ModernNetworking.Side side, ResourceLocation id, ModernNetworking.Receiver receiver) { +public class ModernNetworkingImpl implements ModernNetworkingService { + @Override + public void registerReceiver(ModernNetworking.Side side, Identifier id, ModernNetworking.Receiver receiver) { if (side == ModernNetworking.Side.C2S) { - PayloadTypeRegistry.playC2S().register(getType(id), PacketPayload.streamCodec()); + PayloadTypeRegistry.serverboundPlay().register(getType(id), PacketPayload.streamCodec()); ServerPlayNetworking.registerGlobalReceiver(getType(id), (payload, context) -> receiver.receive(new ModernNetworking.Context() { @Override public Player getPlayer() { @@ -45,7 +47,7 @@ public void queue(Runnable runnable) { } }, payload.nbt())); } else if (side == ModernNetworking.Side.S2C) { - PayloadTypeRegistry.playS2C().register(getType(id), PacketPayload.streamCodec()); + PayloadTypeRegistry.clientboundPlay().register(getType(id), PacketPayload.streamCodec()); ClientPlayNetworking.registerGlobalReceiver(getType(id), (payload, context) -> receiver.receive(new ModernNetworking.Context() { @Override public Player getPlayer() { @@ -65,16 +67,18 @@ public void queue(Runnable runnable) { } } - public static void registerType(ResourceLocation id) { + @Override + public void registerType(Identifier id) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) { ModernNetworking.getType(id); - PayloadTypeRegistry.playS2C().register(getType(id), PacketPayload.streamCodec()); + PayloadTypeRegistry.clientboundPlay().register(getType(id), PacketPayload.streamCodec()); } } @Contract("_, _ -> new") + @Override @ApiStatus.Internal - public static @NotNull Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { + public @NotNull Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { if (side == ModernNetworking.Side.C2S) { return new ServerboundCustomPayloadPacket(payload); } else { @@ -82,4 +86,3 @@ public static void registerType(ResourceLocation id) { } } } - diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/permission/fabric/PermissionCheckerImpl.java b/fabric/src/main/java/dev/tocraft/craftedcore/permission/fabric/PermissionCheckerImpl.java index e4f4cfa..c3e0f09 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/permission/fabric/PermissionCheckerImpl.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/permission/fabric/PermissionCheckerImpl.java @@ -1,23 +1,21 @@ package dev.tocraft.craftedcore.permission.fabric; import dev.tocraft.craftedcore.CraftedCore; +import dev.tocraft.craftedcore.permission.PermissionCheckerService; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.permissions.Permissions; import net.minecraft.world.entity.Entity; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicBoolean; -/** - * Clean Fabric implementation of the PermissionManager using Fabric Permissions API - * Based on the clean approach used in OldSchoolJail - */ @SuppressWarnings("unused") -public class PermissionCheckerImpl { +public class PermissionCheckerImpl implements PermissionCheckerService { private static final AtomicBoolean CRASHED = new AtomicBoolean(false); - public static boolean hasPermission(@NotNull ServerPlayer player, @NotNull String namespace, @NotNull String permission) { - // Try to use Fabric Permissions API if available + @Override + public boolean hasPermission(@NotNull ServerPlayer player, @NotNull String namespace, @NotNull String permission) { try { if (!CRASHED.get()) { Class clazz = Class.forName("me.lucko.fabric.api.permissions.v0.Permissions"); @@ -28,8 +26,6 @@ public static boolean hasPermission(@NotNull ServerPlayer player, @NotNull Strin CraftedCore.LOGGER.error("Could not access Fabric-Permission-API-v0!", e); CRASHED.set(true); } - // Permissions API not available, fall back to OP level 2 - return player.hasPermissions(2); - + return player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER); } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/platform/fabric/PlatformDataImpl.java b/fabric/src/main/java/dev/tocraft/craftedcore/platform/fabric/PlatformDataImpl.java index 4bf590b..eab628a 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/platform/fabric/PlatformDataImpl.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/platform/fabric/PlatformDataImpl.java @@ -2,6 +2,7 @@ import dev.tocraft.craftedcore.fabric.client.CraftedCoreFabricClient; import dev.tocraft.craftedcore.platform.PlatformData; +import dev.tocraft.craftedcore.platform.PlatformDataService; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; @@ -12,35 +13,43 @@ import java.nio.file.Path; @SuppressWarnings({"unused", "SameReturnValue"}) -public final class PlatformDataImpl { - public static boolean isModLoaded(String modid) { +public final class PlatformDataImpl implements PlatformDataService { + @Override + public boolean isModLoaded(String modid) { return FabricLoader.getInstance().isModLoaded(modid); } + @Override @Nullable - public static Version getModVersion(String modid) { + public Version getModVersion(String modid) { return FabricLoader.getInstance().getModContainer(modid).map(modContainer -> Version.parse(modContainer.getMetadata().getVersion().getFriendlyString())).orElse(null); } - public static boolean isDevEnv() { + @Override + public boolean isDevEnv() { return FabricLoader.getInstance().isDevelopmentEnvironment(); } - public static EnvType getEnv() { - return FabricLoader.getInstance().getEnvironmentType(); + @Override + public PlatformData.Env getEnv() { + return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT + ? PlatformData.Env.CLIENT : PlatformData.Env.SERVER; } - public static Path getConfigPath() { + @Override + public Path getConfigPath() { return FabricLoader.getInstance().getConfigDir(); } - public static PlatformData.ModLoader getModLoaderId() { + @Override + public PlatformData.ModLoader getModLoaderId() { return PlatformData.ModLoader.FABRIC; } + @Override @ApiStatus.Internal @Environment(EnvType.CLIENT) - public static void registerConfigScreen(String name) { + public void registerConfigScreen(String name) { CraftedCoreFabricClient.CONFIGS.add(name); } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/KeyBindingRegistryImpl.java b/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/KeyBindingRegistryImpl.java index efd699d..afa734e 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/KeyBindingRegistryImpl.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/KeyBindingRegistryImpl.java @@ -1,14 +1,16 @@ package dev.tocraft.craftedcore.registration.fabric; +import dev.tocraft.craftedcore.registration.KeyBindingRegistryService; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper; import net.minecraft.client.KeyMapping; @SuppressWarnings("unused") @Environment(EnvType.CLIENT) -public final class KeyBindingRegistryImpl { - public static void register(KeyMapping keyMapping) { - KeyBindingHelper.registerKeyBinding(keyMapping); +public final class KeyBindingRegistryImpl implements KeyBindingRegistryService { + @Override + public void register(KeyMapping keyMapping) { + KeyMappingHelper.registerKeyMapping(keyMapping); } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/RegistryRegistryImpl.java b/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/RegistryRegistryImpl.java index 7e6b8b1..473733f 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/RegistryRegistryImpl.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/RegistryRegistryImpl.java @@ -1,12 +1,14 @@ package dev.tocraft.craftedcore.registration.fabric; +import dev.tocraft.craftedcore.registration.RegistryRegistryService; import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; @SuppressWarnings("unused") -public class RegistryRegistryImpl { - public static Registry createSimpleRegistry(ResourceKey> key) { - return FabricRegistryBuilder.createSimple(key).buildAndRegister(); +public class RegistryRegistryImpl implements RegistryRegistryService { + @Override + public Registry createSimpleRegistry(ResourceKey> key) { + return FabricRegistryBuilder.create(key).buildAndRegister(); } } diff --git a/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/SynchronizedReloadListenerRegistryImpl.java b/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/SynchronizedReloadListenerRegistryImpl.java index e2d2972..b694a4b 100644 --- a/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/SynchronizedReloadListenerRegistryImpl.java +++ b/fabric/src/main/java/dev/tocraft/craftedcore/registration/fabric/SynchronizedReloadListenerRegistryImpl.java @@ -1,15 +1,17 @@ package dev.tocraft.craftedcore.registration.fabric; import dev.tocraft.craftedcore.data.SynchronizedJsonReloadListener; +import dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService; import net.fabricmc.fabric.api.resource.v1.ResourceLoader; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.packs.PackType; import org.jetbrains.annotations.ApiStatus; @SuppressWarnings("unused") @ApiStatus.Internal -public class SynchronizedReloadListenerRegistryImpl { - public static void onRegister(SynchronizedJsonReloadListener reloadListener, ResourceLocation id) { - ResourceLoader.get(PackType.SERVER_DATA).registerReloader(id, reloadListener); +public class SynchronizedReloadListenerRegistryImpl implements SynchronizedReloadListenerRegistryService { + @Override + public void onRegister(SynchronizedJsonReloadListener reloadListener, Identifier id) { + ResourceLoader.get(PackType.SERVER_DATA).registerReloadListener(id, reloadListener); } } diff --git a/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.network.ModernNetworkingService b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.network.ModernNetworkingService new file mode 100644 index 0000000..762c4f8 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.network.ModernNetworkingService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.network.fabric.ModernNetworkingImpl diff --git a/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.permission.PermissionCheckerService b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.permission.PermissionCheckerService new file mode 100644 index 0000000..b96dee3 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.permission.PermissionCheckerService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.permission.fabric.PermissionCheckerImpl diff --git a/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.platform.PlatformDataService b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.platform.PlatformDataService new file mode 100644 index 0000000..6866e97 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.platform.PlatformDataService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.platform.fabric.PlatformDataImpl diff --git a/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.KeyBindingRegistryService b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.KeyBindingRegistryService new file mode 100644 index 0000000..c8e7a6b --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.KeyBindingRegistryService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.registration.fabric.KeyBindingRegistryImpl diff --git a/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.RegistryRegistryService b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.RegistryRegistryService new file mode 100644 index 0000000..86ccc73 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.RegistryRegistryService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.registration.fabric.RegistryRegistryImpl diff --git a/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService new file mode 100644 index 0000000..582974d --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.registration.fabric.SynchronizedReloadListenerRegistryImpl diff --git a/fabric/src/main/resources/craftedcore-fabric.mixins.json b/fabric/src/main/resources/craftedcore-fabric.mixins.json index 4da2716..72d05d6 100644 --- a/fabric/src/main/resources/craftedcore-fabric.mixins.json +++ b/fabric/src/main/resources/craftedcore-fabric.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "dev.tocraft.craftedcore.fabric.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_25", "mixins": [ "LivingBreatheMixin", "LivingDeathMixin", diff --git a/gradle.properties b/gradle.properties index bd149a9..a196c65 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,13 @@ org.gradle.jvmargs=-Xmx4G # Base Versions -archives_base_name=craftedcore -mod_version=7.1 +modid=craftedcore +mod_version=8.0-tgboyles_1 artifact_type=release maven_group=dev.tocraft # Loader Versions -fabric_loader=0.17.2 -mixinextras_version=0.5.1 +fabric_loader=0.18.6 +neoform_version=26.1.2-1 +mixinextras_version=0.5.3 # Upload data curseforge_id=923377 modrinth_id=Dg7PHdkJ @@ -14,12 +15,12 @@ optional_dependencies=cloth-config # Discord Webhook ping_role=1247931121019261070 # <--- ModMaster ---> -minecraft=1.21.9 -supported_versions=1.21.9,1.21.10 -java=21 -mappings=2025.10.05 -fabric=0.134.0 -neoforge=21.9.16-beta +minecraft=26.1.2 +supported_versions=26.1.2 +java=25 +#mappings=2025.12.20 +fabric=0.147.0+26.1.2 +neoforge=26.1.2.43-beta # Dependencies -modmenu_version=16.0.0-rc.1 -cloth_config_version=20.0.148 \ No newline at end of file +modmenu_version=18.0.0-alpha.8 +cloth_config_version=26.1.154 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 9bbc975..d997cfc 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e11132..dbc3ce4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index faf9300..0262dcb 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,8 +210,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 9d21a21..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index 58b4278..6a42a37 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -4,32 +4,27 @@ plugins { id("dev.tocraft.modmaster.neoforge") } -tasks.withType { - @Suppress("UNCHECKED_CAST") val modMeta = parent!!.ext["mod_meta"]!! as Map +dependencies { + compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${property("mixinextras_version")}")!!) + implementation(jarJar("io.github.llamalad7:mixinextras-neoforge:${property("mixinextras_version")}")!!) - filesMatching("META-INF/mods.toml") { - expand(modMeta) + val clothConfigVersion = properties["cloth_config_version"] as String? + if (clothConfigVersion != null) { + compileOnly("me.shedaniel.cloth:cloth-config-neoforge:${clothConfigVersion}") + runtimeOnly("me.shedaniel.cloth:cloth-config-neoforge:${clothConfigVersion}") } +} - filesMatching("META-INF/neoforge.mods.toml") { - expand(modMeta) +tasks.processResources { + from("commonResources") + val mcVersion = project.property("minecraft") + val clothVersion = project.property("cloth_config_version") + filesMatching(listOf("META-INF/neoforge.mods.toml", "META-INF/mods.toml")) { + expand(mapOf( + "version" to project.version, + "minecraft" to mcVersion, + "clothConfig" to clothVersion + )) } - - outputs.upToDateWhen { false } } - -val clothConfigVersion: String = parent!!.properties["cloth_config_version"] as String - -repositories { - maven("https://maven.terraformersmc.com/releases/") - maven("https://maven.shedaniel.me/") -} - -dependencies { - // mixin extras - compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${rootProject.properties["mixinextras_version"]}")!!) - implementation(include("io.github.llamalad7:mixinextras-neoforge:${rootProject.properties["mixinextras_version"]}")!!) - // Cloth Config - modRuntimeOnly("me.shedaniel.cloth:cloth-config-neoforge:${clothConfigVersion}") -} \ No newline at end of file diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/CraftedCoreNeoForgeEventHandler.java b/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/CraftedCoreNeoForgeEventHandler.java index 6ef2f97..75f0afe 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/CraftedCoreNeoForgeEventHandler.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/CraftedCoreNeoForgeEventHandler.java @@ -6,7 +6,7 @@ import dev.tocraft.craftedcore.event.common.PlayerEvents; import dev.tocraft.craftedcore.event.common.ServerLevelEvents; import dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistry; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -18,6 +18,7 @@ import net.neoforged.neoforge.event.entity.player.CanContinueSleepingEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.event.level.LevelEvent; +import net.neoforged.neoforge.common.util.ClockAdjustment; import net.neoforged.neoforge.event.level.SleepFinishedTimeEvent; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -29,7 +30,7 @@ public class CraftedCoreNeoForgeEventHandler { @SubscribeEvent public void addReloadListenerEvent(AddServerReloadListenersEvent event) { - for (Map.Entry entry : SynchronizedReloadListenerRegistry.getAllListener().entrySet()) { + for (Map.Entry entry : SynchronizedReloadListenerRegistry.getAllListener().entrySet()) { event.addListener(entry.getKey(), entry.getValue()); } } @@ -57,8 +58,12 @@ public void allowSleepTime(@NotNull CanContinueSleepingEvent event) { @SubscribeEvent public void sleepFinishedTime(@NotNull SleepFinishedTimeEvent event) { - long newTimeIn = PlayerEvents.SLEEP_FINISHED_TIME.invoke().setTimeAddition((ServerLevel) event.getLevel(), event.getNewTime()); - event.setTimeAddition(newTimeIn); + ServerLevel level = (ServerLevel) event.getLevel(); + long currentTime = level.getOverworldClockTime(); + long newTimeIn = PlayerEvents.SLEEP_FINISHED_TIME.invoke().setTimeAddition(level, currentTime); + if (newTimeIn != currentTime) { + event.setAdjustment(new ClockAdjustment.Absolute(newTimeIn)); + } } @SubscribeEvent @@ -85,7 +90,9 @@ public void livingBreathe(@NotNull LivingBreatheEvent event) { event.setCanBreathe(EntityEvents.LIVING_BREATHE.invoke().breathe(event.getEntity(), event.canBreathe())); } + @SubscribeEvent private void destroySpeed(PlayerEvent.@NotNull BreakSpeed event) { - PlayerEvents.DESTROY_SPEED.invoke().setDestroySpeed(event.getEntity(), event.getNewSpeed()); + float speed = PlayerEvents.DESTROY_SPEED.invoke().setDestroySpeed(event.getEntity(), event.getNewSpeed()); + event.setNewSpeed(speed); } } diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/client/CraftedCoreNeoForgeEventHandlerClient.java b/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/client/CraftedCoreNeoForgeEventHandlerClient.java index c16018f..5263f2a 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/client/CraftedCoreNeoForgeEventHandlerClient.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/client/CraftedCoreNeoForgeEventHandlerClient.java @@ -21,7 +21,7 @@ public class CraftedCoreNeoForgeEventHandlerClient { @SubscribeEvent public void event(RenderGuiEvent.@NotNull Post event) { - RenderEvents.HUD_RENDERING.invoke().render(event.getGuiGraphics(), event.getPartialTick()); + RenderEvents.HUD_RENDERING.invoke().extractRenderState(event.getGuiGraphics(), event.getPartialTick()); } @SubscribeEvent diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/mixin/LivingBreatheMixin.java b/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/mixin/LivingBreatheMixin.java new file mode 100644 index 0000000..f0735a2 --- /dev/null +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/neoforge/mixin/LivingBreatheMixin.java @@ -0,0 +1,21 @@ +package dev.tocraft.craftedcore.neoforge.mixin; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.mojang.logging.LogUtils; +import dev.tocraft.craftedcore.event.common.EntityEvents; +import net.minecraft.world.entity.LivingEntity; +import org.jetbrains.annotations.ApiStatus; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; + +// TODO: Remove once NeoForge got the LivingBreathe event working +@SuppressWarnings({"DataFlowIssue", "unused"}) +@ApiStatus.Internal +@Mixin(LivingEntity.class) +public class LivingBreatheMixin { + @ModifyExpressionValue(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isEyeInFluid(Lnet/minecraft/tags/TagKey;)Z"), require = 0) + private boolean canBreathe(boolean cantBreathe) { + return !EntityEvents.LIVING_BREATHE.invoke().breathe((LivingEntity) (Object) this, !cantBreathe); + } +} diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java b/neoforge/src/main/java/dev/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java index 5008263..a968640 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/network/neoforge/ModernNetworkingImpl.java @@ -3,17 +3,16 @@ import dev.tocraft.craftedcore.neoforge.CraftedCoreNeoForge; import dev.tocraft.craftedcore.network.ModernNetworking; import dev.tocraft.craftedcore.network.ModernNetworking.PacketPayload; +import dev.tocraft.craftedcore.network.ModernNetworkingService; import net.minecraft.client.Minecraft; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.resources.Identifier; import net.minecraft.world.entity.player.Player; -import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.loading.FMLEnvironment; -import net.neoforged.fml.loading.FMLLoader; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; @@ -22,9 +21,9 @@ import static dev.tocraft.craftedcore.network.ModernNetworking.getType; @SuppressWarnings("unused") -public class ModernNetworkingImpl { - public static void registerReceiver(ModernNetworking.Side side, ResourceLocation id, ModernNetworking.Receiver - receiver) { +public class ModernNetworkingImpl implements ModernNetworkingService { + @Override + public void registerReceiver(ModernNetworking.Side side, Identifier id, ModernNetworking.Receiver receiver) { IEventBus eventBus = CraftedCoreNeoForge.getEventBus(); if (side == ModernNetworking.Side.C2S) { @@ -64,7 +63,8 @@ public void queue(Runnable runnable) { } } - public static void registerType(ResourceLocation id) { + @Override + public void registerType(Identifier id) { if (FMLEnvironment.getDist().isDedicatedServer()) { ModernNetworking.getType(id); registerReceiver(ModernNetworking.Side.S2C, id, (context, data) -> { @@ -73,8 +73,9 @@ public static void registerType(ResourceLocation id) { } @Contract("_, _ -> new") + @Override @ApiStatus.Internal - public static @NotNull Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { + public @NotNull Packet toPacket(ModernNetworking.Side side, CustomPacketPayload payload) { if (side == ModernNetworking.Side.C2S) { return new ServerboundCustomPayloadPacket(payload); } else { diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/permission/neoforge/PermissionCheckerImpl.java b/neoforge/src/main/java/dev/tocraft/craftedcore/permission/neoforge/PermissionCheckerImpl.java index 7dcef18..c2a0340 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/permission/neoforge/PermissionCheckerImpl.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/permission/neoforge/PermissionCheckerImpl.java @@ -1,7 +1,9 @@ package dev.tocraft.craftedcore.permission.neoforge; -import net.minecraft.resources.ResourceLocation; +import dev.tocraft.craftedcore.permission.PermissionCheckerService; +import net.minecraft.resources.Identifier; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.permissions.Permissions; import net.neoforged.neoforge.server.permission.PermissionAPI; import net.neoforged.neoforge.server.permission.nodes.PermissionNode; import net.neoforged.neoforge.server.permission.nodes.PermissionTypes; @@ -10,30 +12,20 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -/** - * NeoForge implementation of the PermissionManager using NeoForge PermissionAPI - */ @SuppressWarnings("unused") -public class PermissionCheckerImpl { +public class PermissionCheckerImpl implements PermissionCheckerService { + private static final ConcurrentMap> PERMISSION_NODES = new ConcurrentHashMap<>(); - // Cache for permission nodes to avoid recreating them - private static final ConcurrentMap> PERMISSION_NODES = new ConcurrentHashMap<>(); - - public static boolean hasPermission(@NotNull ServerPlayer player, @NotNull String namespace, @NotNull String permission) { - // Get or create permission node - ResourceLocation id = ResourceLocation.fromNamespaceAndPath(namespace, permission); + @Override + public boolean hasPermission(@NotNull ServerPlayer player, @NotNull String namespace, @NotNull String permission) { + Identifier id = Identifier.fromNamespaceAndPath(namespace, permission); PermissionNode node = PERMISSION_NODES.get(id); - - // Check permission using NeoForge PermissionAPI - return node != null ? PermissionAPI.getPermission(player, node) : player.hasPermissions(2); + return node != null ? PermissionAPI.getPermission(player, node) : player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER); } - /** - * This MUST be called while registering the nodes! - */ public static PermissionNode createNode(@NotNull String namespace, @NotNull String permission) { - ResourceLocation id = ResourceLocation.fromNamespaceAndPath(namespace, permission); + Identifier id = Identifier.fromNamespaceAndPath(namespace, permission); return PERMISSION_NODES.put(id, new PermissionNode<>(id, PermissionTypes.BOOLEAN, - (player, playerUUID, context) -> player != null && player.hasPermissions(2))); + (player, playerUUID, context) -> player != null && player.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER))); } } diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/platform/neoforge/PlatformDataImpl.java b/neoforge/src/main/java/dev/tocraft/craftedcore/platform/neoforge/PlatformDataImpl.java index 5cfb16e..cf33678 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/platform/neoforge/PlatformDataImpl.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/platform/neoforge/PlatformDataImpl.java @@ -3,6 +3,7 @@ import dev.tocraft.craftedcore.config.Config; import dev.tocraft.craftedcore.config.ConfigLoader; import dev.tocraft.craftedcore.platform.PlatformData; +import dev.tocraft.craftedcore.platform.PlatformDataService; import net.minecraft.client.gui.screens.Screen; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; @@ -19,35 +20,42 @@ @SuppressWarnings({"unused", "SameReturnValue"}) @ApiStatus.Internal -public final class PlatformDataImpl { - public static boolean isModLoaded(String modid) { +public final class PlatformDataImpl implements PlatformDataService { + @Override + public boolean isModLoaded(String modid) { return ModList.get().isLoaded(modid); } + @Override @Nullable - public static Version getModVersion(String modid) { + public Version getModVersion(String modid) { return ModList.get().getModContainerById(modid).map(modContainer -> Version.parse(modContainer.getModInfo().getVersion().toString())).orElse(null); } - public static boolean isDevEnv() { + @Override + public boolean isDevEnv() { return !FMLLoader.getCurrent().isProduction(); } - public static Dist getEnv() { - return FMLEnvironment.getDist(); + @Override + public PlatformData.Env getEnv() { + return FMLEnvironment.getDist().isClient() ? PlatformData.Env.CLIENT : PlatformData.Env.SERVER; } - public static Path getConfigPath() { + @Override + public Path getConfigPath() { return FMLPaths.CONFIGDIR.get(); } - public static PlatformData.ModLoader getModLoaderId() { + @Override + public PlatformData.ModLoader getModLoaderId() { return PlatformData.ModLoader.NEOFORGE; } + @Override @ApiStatus.Internal @OnlyIn(Dist.CLIENT) - public static void registerConfigScreen(String name) { + public void registerConfigScreen(String name) { if (ModList.get().getModContainerById("cloth_config").isPresent()) { ModList.get().getModContainerById(name).ifPresent(mod -> mod.registerExtensionPoint(IConfigScreenFactory.class, (minecraft, parent) -> { Config c; diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/KeyBindingRegistryImpl.java b/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/KeyBindingRegistryImpl.java index 1b60e40..f8c3690 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/KeyBindingRegistryImpl.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/KeyBindingRegistryImpl.java @@ -1,6 +1,7 @@ package dev.tocraft.craftedcore.registration.neoforge; import com.mojang.logging.LogUtils; +import dev.tocraft.craftedcore.registration.KeyBindingRegistryService; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; @@ -16,12 +17,13 @@ @SuppressWarnings("unused") @OnlyIn(Dist.CLIENT) -public final class KeyBindingRegistryImpl { +public final class KeyBindingRegistryImpl implements KeyBindingRegistryService { private static final Logger LOGGER = LogUtils.getLogger(); private static final List MAPPINGS = new ArrayList<>(); private static boolean eventCalled = false; - public static void register(KeyMapping mapping) { + @Override + public void register(KeyMapping mapping) { if (eventCalled) { Options options = Minecraft.getInstance().options; options.keyMappings = ArrayUtils.add(options.keyMappings, mapping); diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/RegistryRegistryImpl.java b/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/RegistryRegistryImpl.java index eb589b8..f2eefff 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/RegistryRegistryImpl.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/RegistryRegistryImpl.java @@ -1,5 +1,6 @@ package dev.tocraft.craftedcore.registration.neoforge; +import dev.tocraft.craftedcore.registration.RegistryRegistryService; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.neoforged.neoforge.registries.RegistryBuilder; @@ -10,10 +11,11 @@ import java.util.ArrayList; import java.util.List; -public class RegistryRegistryImpl { +public class RegistryRegistryImpl implements RegistryRegistryService { private static final List> registries = new ArrayList<>(); - public static @NotNull Registry createSimpleRegistry(ResourceKey> key) { + @Override + public @NotNull Registry createSimpleRegistry(ResourceKey> key) { var registry = new RegistryBuilder<>(key).create(); registries.add(registry); return registry; diff --git a/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/SynchronizedReloadListenerRegistryImpl.java b/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/SynchronizedReloadListenerRegistryImpl.java index c490ef2..a681af3 100644 --- a/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/SynchronizedReloadListenerRegistryImpl.java +++ b/neoforge/src/main/java/dev/tocraft/craftedcore/registration/neoforge/SynchronizedReloadListenerRegistryImpl.java @@ -1,13 +1,15 @@ package dev.tocraft.craftedcore.registration.neoforge; import dev.tocraft.craftedcore.data.SynchronizedJsonReloadListener; -import net.minecraft.resources.ResourceLocation; +import dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.ApiStatus; @SuppressWarnings("unused") @ApiStatus.Internal -public class SynchronizedReloadListenerRegistryImpl { +public class SynchronizedReloadListenerRegistryImpl implements SynchronizedReloadListenerRegistryService { + @Override @SuppressWarnings("EmptyMethod") - public static void onRegister(SynchronizedJsonReloadListener reloadListener, ResourceLocation id) { + public void onRegister(SynchronizedJsonReloadListener reloadListener, Identifier id) { } } diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 32ae60c..21a5640 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -6,6 +6,8 @@ license = "LGPL-3.0" [[mixins]] config = "craftedcore.mixins.json" +[[mixins]] +config = "craftedcore-neoforge.mixins.json" [[mods]] modId = "craftedcore" diff --git a/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.network.ModernNetworkingService b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.network.ModernNetworkingService new file mode 100644 index 0000000..1118d32 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.network.ModernNetworkingService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.network.neoforge.ModernNetworkingImpl diff --git a/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.permission.PermissionCheckerService b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.permission.PermissionCheckerService new file mode 100644 index 0000000..0fef267 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.permission.PermissionCheckerService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.permission.neoforge.PermissionCheckerImpl diff --git a/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.platform.PlatformDataService b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.platform.PlatformDataService new file mode 100644 index 0000000..acde246 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.platform.PlatformDataService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.platform.neoforge.PlatformDataImpl diff --git a/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.KeyBindingRegistryService b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.KeyBindingRegistryService new file mode 100644 index 0000000..f9b10f1 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.KeyBindingRegistryService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.registration.neoforge.KeyBindingRegistryImpl diff --git a/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.RegistryRegistryService b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.RegistryRegistryService new file mode 100644 index 0000000..dcdc2d4 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.RegistryRegistryService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.registration.neoforge.RegistryRegistryImpl diff --git a/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService new file mode 100644 index 0000000..16475e6 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/dev.tocraft.craftedcore.registration.SynchronizedReloadListenerRegistryService @@ -0,0 +1 @@ +dev.tocraft.craftedcore.registration.neoforge.SynchronizedReloadListenerRegistryImpl diff --git a/neoforge/src/main/resources/craftedcore-neoforge.mixins.json b/neoforge/src/main/resources/craftedcore-neoforge.mixins.json new file mode 100644 index 0000000..295db9a --- /dev/null +++ b/neoforge/src/main/resources/craftedcore-neoforge.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "dev.tocraft.craftedcore.neoforge.mixin", + "compatibilityLevel": "JAVA_25", + "mixins": [ + "LivingBreatheMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index aa35f98..124d768 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,11 +1,9 @@ pluginManagement { repositories { - maven("https://maven.fabricmc.net/") - maven("https://maven.architectury.dev/") - maven("https://maven.minecraftforge.net/") - maven("https://maven.parchmentmc.org") - maven("https://maven.tocraft.dev/public") - gradlePluginPortal() + maven("https://maven.fabricmc.net/") // fabric loom + maven("https://maven.neoforged.net/releases/") // neoforge mod dev + maven("https://maven.tocraft.dev/public") // mod master + gradlePluginPortal() // publishing plugins (CFGradle, Minotaur, Schoomp) } } diff --git a/testmod-common/src/main/java/dev/tocraft/craftedcore/testmod/TestMod.java b/testmod-common/src/main/java/dev/tocraft/craftedcore/testmod/TestMod.java index db15e6e..98b446c 100644 --- a/testmod-common/src/main/java/dev/tocraft/craftedcore/testmod/TestMod.java +++ b/testmod-common/src/main/java/dev/tocraft/craftedcore/testmod/TestMod.java @@ -26,34 +26,40 @@ public class TestMod { public static void initialize() { PlayerEvents.PLAYER_JOIN.register(player -> LOGGER.debug("player {} joined.", player != null ? player.getName().getString() : "")); PlayerEvents.PLAYER_QUIT.register(player -> LOGGER.debug("player {} quit.", player != null ? player.getName().getString() : "")); - PlayerEvents.AWARD_ADVANCEMENT.register((player, advancement, criterionKey) -> LOGGER.debug("{} unlocked advancement {}", player != null ? player.getDisplayName() : "", criterionKey)); - PlayerEvents.REVOKE_ADVANCEMENT.register((player, advancement, criterionKey) -> LOGGER.debug("{} revoked advancement {}", player != null ? player.getDisplayName() : "", criterionKey)); + PlayerEvents.AWARD_ADVANCEMENT.register((player, advancement, criterionKey) -> LOGGER.debug("{} unlocked advancement {}", player != null ? player.getName().getString() : "", criterionKey)); + PlayerEvents.REVOKE_ADVANCEMENT.register((player, advancement, criterionKey) -> LOGGER.debug("{} revoked advancement {}", player != null ? player.getName().getString() : "", criterionKey)); EntityEvents.INTERACT_WITH_PLAYER.register((player, entity, hand) -> { - LOGGER.debug("player {}just interacted with {}", player != null ? player.getName().getString() : "", entity.getName().getString()); + LOGGER.debug("player {} just interacted with {}", player != null ? player.getName().getString() : "", entity.getName().getString()); return InteractionResult.PASS; }); EntityEvents.LIVING_DEATH.register((entity, source) -> { - LOGGER.debug("{}Oh, I just died in your arms tonight.", entity != null ? entity.getName().getString() : ""); + LOGGER.debug("{} Oh, I just died in your arms tonight.", entity != null ? entity.getName().getString() : ""); return InteractionResult.PASS; }); EntityEvents.LIVING_BREATHE.register((entity, canBreathe) -> { if (entity instanceof Player) { if (canBreathe) { - LOGGER.debug("In and out."); + LOGGER.info("In and out."); } else { - LOGGER.debug("I need air!"); + LOGGER.info("I need air!"); } // revert value, the players will need to breathe underwater now return !canBreathe; } else { - LOGGER.debug("something is breathing here..."); + LOGGER.info("something is breathing here..."); return canBreathe; } }); - if (PlatformData.getEnv() == EnvType.CLIENT) { + PlayerEvents.DESTROY_SPEED.register((player, oSpeed) -> { + float speed = oSpeed * 5; + LOGGER.debug("{} is mining with {} speed.", player.getName().getString(), speed); + return speed; + }); + + if (PlatformData.getEnv() == PlatformData.Env.CLIENT) { TestModClient.initialize(); } } diff --git a/testmod-fabric/build.gradle.kts b/testmod-fabric/build.gradle.kts index 5a90726..ee394c4 100644 --- a/testmod-fabric/build.gradle.kts +++ b/testmod-fabric/build.gradle.kts @@ -1,3 +1,7 @@ plugins { id("dev.tocraft.modmaster.testmod-fabric") } + +dependencies { + implementation("net.fabricmc.fabric-api:fabric-api:${property("fabric")}") +} \ No newline at end of file