Skip to content

Commit

Permalink
Update to 1.21.4 and add some minor new features
Browse files Browse the repository at this point in the history
- Add ability to prevent message unless you are have any privilage level
- Reset tag cooked flag on reload
  • Loading branch information
Dragon-Seeker committed Dec 17, 2024
1 parent d775c40 commit de372ac
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false
}

architectury {
Expand Down
16 changes: 14 additions & 2 deletions common/src/main/java/io/wispforest/lmft/LMFTCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class LMFTCommon {
private static final Logger LOGGER = LogUtils.getLogger();

private static boolean disableIngameError = Boolean.getBoolean("lmft.disable_error_output");
private static boolean showToOnlyPrivileged = false;

public static void init(Path configPath) {
File configFile = new File(configPath + File.separator + "lmft.json");
Expand All @@ -41,6 +42,7 @@ public static void init(Path configPath) {

configObject = new JsonObject();
configObject.addProperty("disableIngameError", false);
configObject.addProperty("showToOnlyPrivileged", false);

try (FileWriter writer = new FileWriter(configFile)) { writer.write(GSON.toJson(configObject)); }
} else {
Expand All @@ -56,11 +58,21 @@ public static void init(Path configPath) {
LOGGER.error("[LMFT]: Unable to read the needed config file, using default values!", exception);
}

if(configObject != null && configObject.has("disableIngameError")) disableIngameError = disableIngameError || configObject.get("disableIngameError").getAsBoolean();
if(configObject != null) {
if (configObject.has("disableIngameError")) {
disableIngameError = disableIngameError || configObject.get("disableIngameError").getAsBoolean();
}

if (configObject.has("showToOnlyPrivileged")) {
showToOnlyPrivileged = configObject.get("showToOnlyPrivileged").getAsBoolean();
}
}
}

public static void sendMessage(Player entity){
if(!LMFTCommon.areTagsCooked || LMFTCommon.disableIngameError) return;
if (!LMFTCommon.areTagsCooked || LMFTCommon.disableIngameError) return;

if (LMFTCommon.showToOnlyPrivileged && entity.getPermissionLevel() <= 0) return;

entity.displayClientMessage(
Component.empty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package io.wispforest.lmft.mixin;

import com.google.common.collect.ImmutableSet;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.datafixers.util.Either;
import com.mojang.logging.LogUtils;
import io.wispforest.lmft.LMFTCommon;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagEntry;
import net.minecraft.tags.TagLoader;
import org.intellij.lang.annotations.Identifier;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Collection;
import java.util.List;
Expand All @@ -30,7 +27,7 @@ public class TagGroupLoaderMixin<T> {
@Unique private static final Logger LOGGER = LogUtils.getLogger();
@Unique private static final ThreadLocal<ResourceLocation> currentTagId = ThreadLocal.withInitial(() -> ResourceLocation.fromNamespaceAndPath("", ""));

@Inject(method = "tryBuildTag(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/List;)Lcom/mojang/datafixers/util/Either;", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "tryBuildTag(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/List;)Lcom/mojang/datafixers/util/Either;", at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"))
private void preventTagsFromFailingToLoad(TagEntry.Lookup<T> valueGetter, List<TagLoader.EntryWithSource> list, CallbackInfoReturnable<Either<Collection<TagLoader.EntryWithSource>, Collection<T>>> cir, @Local(ordinal = 1) List<TagLoader.EntryWithSource> list2){
if(list2.isEmpty()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.wispforest.lmft.LMFTCommon;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.loader.api.FabricLoader;

Expand All @@ -11,6 +12,7 @@ public class LMFTFabric implements ModInitializer {
public void onInitialize() {
LMFTCommon.init(FabricLoader.getInstance().getConfigDir());

ServerPlayConnectionEvents.JOIN.register((h, s, c) -> LMFTCommon.sendMessage(h.getPlayer()));
ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, resourceManager) -> LMFTCommon.areTagsCooked = false);
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> LMFTCommon.sendMessage(player));
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
enabled_platforms=fabric,neoforge

# General Properties
minecraft_version=1.21.2-pre2
minecraft_version=1.21.4

# Mod Properties
mod_version = 1.0.4+1.21
mod_version = 1.0.4+1.21.4
maven_group = io.wispforest
archives_base_name = lmft

# Fabric Dependencies
fabric_api_version=0.105.3+1.21.2
fabric_loader_version=0.16.7
fabric_api_version=0.112.1+1.21.4
fabric_loader_version=0.16.9

# NeoForge Dependencies
neoforge_version=21.1.65
neoforge_version=21.4.30-beta
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import io.wispforest.lmft.LMFTCommon;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.AddReloadListenerEvent;
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
import net.neoforged.neoforge.event.TagsUpdatedEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.loading.FMLPaths;
Expand All @@ -11,7 +14,6 @@ public class LMFTForge {
public LMFTForge() {
LMFTCommon.init(FMLPaths.CONFIGDIR.get());

NeoForge.EVENT_BUS
.addListener((PlayerEvent.PlayerLoggedInEvent e) -> LMFTCommon.sendMessage(e.getEntity()));
NeoForge.EVENT_BUS.addListener((OnDatapackSyncEvent e) -> e.getRelevantPlayers().forEach(LMFTCommon::sendMessage));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.wispforest.lmft.forge.mixin;

import io.wispforest.lmft.LMFTCommon;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;

@Mixin(MinecraftServer.class)
public abstract class MinecraftServerMixin {

@Inject(method = "reloadResources", at = @At("HEAD"))
private void startResourceReload(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> cir) {
LMFTCommon.areTagsCooked = false;
}
}
2 changes: 2 additions & 0 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Simple mod that makes Tag Loading less of a Pain
logoFile = "assets/lmft/icon.png"
[[mixins]]
config = 'lmft-common.mixins.json'
[[mixins]]
config = 'lmft-neoforge.mixins.json'

[[dependencies.lmft]]
modId = "neoforge"
Expand Down
14 changes: 14 additions & 0 deletions neoforge/src/main/resources/lmft-neoforge.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "io.wispforest.lmft.forge.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"mixins": [
"MinecraftServerMixin"
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pluginManagement {

include("common")
include("fabric")
//include("neoforge")
include("neoforge")

rootProject.name = "lmft"

0 comments on commit de372ac

Please sign in to comment.