started to update to 1.21.1

This commit is contained in:
candle 2025-09-28 17:20:41 -04:00
parent 5d6b018a75
commit 8266691770
23 changed files with 257 additions and 335 deletions

View File

@ -1,7 +1,7 @@
plugins {
id 'dev.architectury.loom' version '1.11-SNAPSHOT' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'architectury-plugin' version '3.4-SNAPSHOT'
}
architectury {
@ -23,13 +23,7 @@ subprojects {
archivesName = "$rootProject.archives_name-$project.name"
}
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}
// repositories are declared in settings.gradle
dependencies {
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
@ -42,12 +36,12 @@ subprojects {
// If you remove this line, sources will not be generated.
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}
// Configure Maven publishing.

View File

@ -3,7 +3,9 @@ architectury {
}
dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version"
modApi "dev.architectury:architectury:$rootProject.architectury_api_version"
}

View File

@ -1,5 +1,6 @@
package io.lampnet.betterlodestones;
import io.lampnet.betterlodestones.component.BetterLodestonesComponents;
import io.lampnet.betterlodestones.config.ConfigManager;
import io.lampnet.betterlodestones.registry.BetterLodestonesRegistry;
import org.slf4j.Logger;
@ -10,6 +11,7 @@ public final class BetterLodestones {
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static void init() {
BetterLodestonesComponents.init();
BetterLodestonesRegistry.init();
LOGGER.info("Better Lodestones initialized.");

View File

@ -1,20 +1,25 @@
package io.lampnet.betterlodestones;
import io.lampnet.betterlodestones.component.BetterLodestonesComponents;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CompassItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
@ -30,96 +35,39 @@ public class CompassDataHandler {
private static final String BROKEN_LODESTONE_FLAG = "BrokenLodestone";
public static List<GlobalPos> getLodestones(ItemStack compass) {
List<GlobalPos> lodestones = new ArrayList<>();
CompoundTag tag = compass.getTag();
if (tag == null || !tag.contains(LODESTONES_KEY)) {
return lodestones;
}
ListTag lodestoneList = tag.getList(LODESTONES_KEY, Tag.TAG_COMPOUND);
for (int i = 0; i < lodestoneList.size(); i++) {
CompoundTag lodestoneTag = lodestoneList.getCompound(i);
int x = lodestoneTag.getInt(POS_X_KEY);
int y = lodestoneTag.getInt(POS_Y_KEY);
int z = lodestoneTag.getInt(POS_Z_KEY);
String dimensionString = lodestoneTag.getString(DIMENSION_KEY);
try {
ResourceKey<Level> dimension = ResourceKey.create(Registries.DIMENSION,
new ResourceLocation(dimensionString));
BlockPos pos = new BlockPos(x, y, z);
lodestones.add(GlobalPos.of(dimension, pos));
} catch (Exception e) {
// Skip invalid lodestone entries
}
}
return lodestones;
return compass.get(BetterLodestonesComponents.LODESTONES);
}
public static void addLodestone(ItemStack compass, GlobalPos lodestone) {
CompoundTag tag = compass.getOrCreateTag();
ListTag lodestoneList = tag.getList(LODESTONES_KEY, Tag.TAG_COMPOUND);
for (int i = 0; i < lodestoneList.size(); i++) {
CompoundTag existing = lodestoneList.getCompound(i);
if (isSameLodestone(existing, lodestone)) {
return;
List<GlobalPos> lodestones = new ArrayList<>(getLodestones(compass));
if (!lodestones.contains(lodestone)) {
lodestones.add(lodestone);
compass.set(BetterLodestonesComponents.LODESTONES, lodestones);
if (lodestones.size() == 1) {
compass.set(BetterLodestonesComponents.CURRENT_LODESTONE_INDEX, 0);
}
}
CompoundTag lodestoneTag = new CompoundTag();
lodestoneTag.putInt(POS_X_KEY, lodestone.pos().getX());
lodestoneTag.putInt(POS_Y_KEY, lodestone.pos().getY());
lodestoneTag.putInt(POS_Z_KEY, lodestone.pos().getZ());
lodestoneTag.putString(DIMENSION_KEY, lodestone.dimension().location().toString());
lodestoneList.add(lodestoneTag);
tag.put(LODESTONES_KEY, lodestoneList);
if (lodestoneList.size() == 1) {
tag.putInt(CURRENT_INDEX_KEY, 0);
}
}
public static void removeLodestone(ItemStack compass, GlobalPos lodestone) {
CompoundTag tag = compass.getTag();
if (tag == null || !tag.contains(LODESTONES_KEY)) {
return;
}
ListTag lodestoneList = tag.getList(LODESTONES_KEY, Tag.TAG_COMPOUND);
List<GlobalPos> lodestones = new ArrayList<>(getLodestones(compass));
int currentIndex = getCurrentLodestoneIndex(compass);
for (int i = lodestoneList.size() - 1; i >= 0; i--) {
CompoundTag existing = lodestoneList.getCompound(i);
if (isSameLodestone(existing, lodestone)) {
lodestoneList.remove(i);
if (i < currentIndex) {
currentIndex--;
} else if (i == currentIndex && currentIndex >= lodestoneList.size()) {
currentIndex = lodestoneList.size() - 1;
if (lodestones.remove(lodestone)) {
if (lodestones.isEmpty()) {
compass.remove(BetterLodestonesComponents.LODESTONES);
compass.remove(BetterLodestonesComponents.CURRENT_LODESTONE_INDEX);
} else {
if (currentIndex >= lodestones.size()) {
currentIndex = lodestones.size() - 1;
}
break;
compass.set(BetterLodestonesComponents.LODESTONES, lodestones);
compass.set(BetterLodestonesComponents.CURRENT_LODESTONE_INDEX, Math.max(0, currentIndex));
}
}
if (lodestoneList.isEmpty()) {
tag.remove(CURRENT_INDEX_KEY);
tag.remove(LODESTONES_KEY);
} else {
tag.putInt(CURRENT_INDEX_KEY, Math.max(0, currentIndex));
}
}
public static int getCurrentLodestoneIndex(ItemStack compass) {
CompoundTag tag = compass.getTag();
if (tag == null) {
return 0;
}
return tag.getInt(CURRENT_INDEX_KEY);
return compass.getOrDefault(BetterLodestonesComponents.CURRENT_LODESTONE_INDEX, 0);
}
public static Optional<GlobalPos> getCurrentLodestone(ItemStack compass) {
@ -127,12 +75,10 @@ public class CompassDataHandler {
if (lodestones.isEmpty()) {
return Optional.empty();
}
int index = getCurrentLodestoneIndex(compass);
if (index < 0 || index >= lodestones.size()) {
return Optional.empty();
}
return Optional.of(lodestones.get(index));
}
@ -142,12 +88,9 @@ public class CompassDataHandler {
validateCurrentLodestone(compass, level);
return;
}
int currentIndex = getCurrentLodestoneIndex(compass);
int nextIndex = (currentIndex + 1) % lodestones.size();
CompoundTag tag = compass.getOrCreateTag();
tag.putInt(CURRENT_INDEX_KEY, nextIndex);
compass.set(BetterLodestonesComponents.CURRENT_LODESTONE_INDEX, nextIndex);
GlobalPos newLodestone = lodestones.get(nextIndex);
if (isLodestoneValid(level, newLodestone)) {
@ -164,12 +107,9 @@ public class CompassDataHandler {
}
public static void clearAllLodestones(ItemStack compass) {
CompoundTag tag = compass.getTag();
if (tag != null) {
tag.remove(LODESTONES_KEY);
tag.remove(CURRENT_INDEX_KEY);
tag.remove(BROKEN_LODESTONE_FLAG);
}
compass.remove(BetterLodestonesComponents.LODESTONES);
compass.remove(BetterLodestonesComponents.CURRENT_LODESTONE_INDEX);
compass.remove(BetterLodestonesComponents.BROKEN_LODESTONE);
}
public static void removeCurrentLodestone(ItemStack compass) {
@ -178,19 +118,7 @@ public class CompassDataHandler {
}
public static boolean isLodestoneAlreadyBound(ItemStack compass, GlobalPos lodestone) {
CompoundTag tag = compass.getTag();
if (tag == null || !tag.contains(LODESTONES_KEY)) {
return false;
}
ListTag lodestoneList = tag.getList(LODESTONES_KEY, Tag.TAG_COMPOUND);
for (int i = 0; i < lodestoneList.size(); i++) {
CompoundTag existing = lodestoneList.getCompound(i);
if (isSameLodestone(existing, lodestone)) {
return true;
}
}
return false;
return getLodestones(compass).contains(lodestone);
}
public static boolean isLodestoneValid(Level level, GlobalPos lodestone) {
@ -259,20 +187,15 @@ public class CompassDataHandler {
}
public static void markLodestoneAsBroken(ItemStack compass) {
CompoundTag tag = compass.getOrCreateTag();
tag.putBoolean(BROKEN_LODESTONE_FLAG, true);
compass.set(BetterLodestonesComponents.BROKEN_LODESTONE, true);
}
public static boolean hasBrokenLodestone(ItemStack compass) {
CompoundTag tag = compass.getTag();
return tag != null && tag.getBoolean(BROKEN_LODESTONE_FLAG);
return compass.getOrDefault(BetterLodestonesComponents.BROKEN_LODESTONE, false);
}
public static void clearBrokenLodestoneFlag(ItemStack compass) {
CompoundTag tag = compass.getTag();
if (tag != null) {
tag.remove(BROKEN_LODESTONE_FLAG);
}
compass.remove(BetterLodestonesComponents.BROKEN_LODESTONE);
}
public static void onLodestoneRemoved(Level level, BlockPos removedPos) {
@ -328,10 +251,10 @@ public class CompassDataHandler {
}
private static boolean isSameLodestone(CompoundTag tag, GlobalPos lodestone) {
int x = tag.getInt(POS_X_KEY);
int y = tag.getInt(POS_Y_KEY);
int z = tag.getInt(POS_Z_KEY);
String dimension = tag.getString(DIMENSION_KEY);
int x = tag.getInt("PosX");
int y = tag.getInt("PosY");
int z = tag.getInt("PosZ");
String dimension = tag.getString("Dimension");
return x == lodestone.pos().getX() &&
y == lodestone.pos().getY() &&
@ -344,40 +267,17 @@ public class CompassDataHandler {
return false;
}
CompoundTag tag = compass.getTag();
if (tag == null) {
var lodestoneTarget = compass.get(DataComponents.LODESTONE_TRACKER);
if (lodestoneTarget == null) {
return false;
}
boolean hasVanillaLodestone = tag.contains("LodestonePos") && tag.contains("LodestoneDimension");
if (!hasVanillaLodestone) {
return false;
}
lodestoneTarget.target().ifPresent(globalPos -> {
addLodestone(compass, globalPos);
compass.remove(DataComponents.LODESTONE_TRACKER);
});
try {
CompoundTag lodestonePos = tag.getCompound("LodestonePos");
String dimensionString = tag.getString("LodestoneDimension");
int x = lodestonePos.getInt("X");
int y = lodestonePos.getInt("Y");
int z = lodestonePos.getInt("Z");
ResourceKey<Level> dimension = ResourceKey.create(Registries.DIMENSION,
new ResourceLocation(dimensionString));
BlockPos pos = new BlockPos(x, y, z);
GlobalPos vanillaLodestone = GlobalPos.of(dimension, pos);
addLodestone(compass, vanillaLodestone);
tag.remove("LodestonePos");
tag.remove("LodestoneDimension");
tag.remove("LodestoneTracked");
return true;
} catch (Exception e) {
// If conversion fails, skip this compass
return false;
}
return true;
}
public static int convertPlayerLodestoneCompasses(Player player) {

View File

@ -1,6 +1,7 @@
package io.lampnet.betterlodestones.advancement;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.lampnet.betterlodestones.BetterLodestones;
import io.lampnet.betterlodestones.CompassDataHandler;
import net.minecraft.advancements.critereon.*;
@ -8,40 +9,31 @@ import net.minecraft.core.GlobalPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public final class DimensionalCompassBindingTrigger extends SimpleCriterionTrigger<DimensionalCompassBindingTrigger.TriggerInstance> {
static final ResourceLocation ID = new ResourceLocation(BetterLodestones.MOD_ID, "dimensional_compass_binding");
static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(BetterLodestones.MOD_ID, "dimensional_compass_binding");
@Override
public @NotNull ResourceLocation getId() {
return ID;
}
@Override
public @NotNull TriggerInstance createInstance(JsonObject json, ContextAwarePredicate player, DeserializationContext context) {
int minDimensions = GsonHelper.getAsInt(json, "min_dimensions", 1);
return new TriggerInstance(player, minDimensions);
public Codec<TriggerInstance> codec() {
return TriggerInstance.CODEC;
}
public void trigger(ServerPlayer player, ItemStack compass) {
this.trigger(player, (triggerInstance) -> triggerInstance.matches(compass));
}
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
private final int minDimensions;
public TriggerInstance(ContextAwarePredicate player, int minDimensions) {
super(ID, player);
this.minDimensions = minDimensions;
}
public record TriggerInstance(Optional<ContextAwarePredicate> player, int minDimensions) implements SimpleCriterionTrigger.SimpleInstance {
public static final Codec<TriggerInstance> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ContextAwarePredicate.CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player),
Codec.INT.fieldOf("min_dimensions").forGetter(TriggerInstance::minDimensions)
).apply(instance, TriggerInstance::new));
public boolean matches(ItemStack compass) {
List<GlobalPos> lodestones = CompassDataHandler.getLodestones(compass);
@ -55,12 +47,5 @@ public final class DimensionalCompassBindingTrigger extends SimpleCriterionTrigg
return uniqueDimensions.size() >= this.minDimensions;
}
@Override
public @NotNull JsonObject serializeToJson(SerializationContext context) {
JsonObject json = super.serializeToJson(context);
json.addProperty("min_dimensions", this.minDimensions);
return json;
}
}
}

View File

@ -0,0 +1,30 @@
package io.lampnet.betterlodestones.component;
import com.mojang.serialization.Codec;
import io.lampnet.betterlodestones.BetterLodestones;
import net.minecraft.core.GlobalPos;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import java.util.List;
import java.util.function.UnaryOperator;
public class BetterLodestonesComponents {
public static final DataComponentType<List<GlobalPos>> LODESTONES = register("lodestones", builder -> builder.persistent(Codec.list(GlobalPos.CODEC)).cacheEncoding());
public static final DataComponentType<Integer> CURRENT_LODESTONE_INDEX = register("current_lodestone_index", builder -> builder.persistent(Codec.INT).cacheEncoding());
public static final DataComponentType<Boolean> BROKEN_LODESTONE = register("broken_lodestone", builder -> builder.persistent(Codec.BOOL).cacheEncoding());
private static <T> DataComponentType<T> register(String name, UnaryOperator<DataComponentType.Builder<T>> builder) {
return Registry.register(
BuiltInRegistries.DATA_COMPONENT_TYPE,
ResourceLocation.fromNamespaceAndPath(BetterLodestones.MOD_ID, name),
builder.apply(DataComponentType.builder()).build()
);
}
public static void init() {
// This method is called to ensure the components are registered
}
}

View File

@ -1,41 +1,38 @@
package io.lampnet.betterlodestones.mixin;
import io.lampnet.betterlodestones.CompassDataHandler;
import io.lampnet.betterlodestones.component.BetterLodestonesComponents;
import net.minecraft.core.GlobalPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.CompassItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.LodestoneTracker;
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 org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import java.util.Optional;
@Mixin(CompassItem.class)
public class CompassItemMixinPointing {
@Inject(method = "getLodestonePosition", at = @At("HEAD"), cancellable = true)
private static void getCustomLodestonePosition(CompoundTag tag,
CallbackInfoReturnable<GlobalPos> cir) {
ItemStack tempStack = new ItemStack(Items.COMPASS);
tempStack.setTag(tag);
if (CompassDataHandler.hasBrokenLodestone(tempStack)) {
cir.setReturnValue(null);
return;
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;has(Lnet/minecraft/core/component/DataComponentType;)Z"),
slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=angle"), to = @At(value = "CONSTANT", args = "stringValue=lodestone_angle")))
private static boolean hasCustomLodestone(ItemStack itemStack, DataComponentType<?> dataComponentType) {
if (dataComponentType == DataComponents.LODESTONE_TRACKER) {
return itemStack.has(DataComponents.LODESTONE_TRACKER) || itemStack.has(BetterLodestonesComponents.LODESTONES);
}
Optional<GlobalPos> currentLodestone = CompassDataHandler.getCurrentLodestone(tempStack);
currentLodestone.ifPresent(cir::setReturnValue);
return itemStack.has(dataComponentType);
}
@Inject(method = "isLodestoneCompass", at = @At("HEAD"), cancellable = true)
private static void isCustomLodestoneCompass(ItemStack stack,
CallbackInfoReturnable<Boolean> cir) {
if (CompassDataHandler.getLodestoneCount(stack) > 0) {
cir.setReturnValue(true);
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;get(Lnet/minecraft/core/component/DataComponentType;)Ljava/lang/Object;"),
slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=lodestone_angle")))
private static Object getCustomLodestoneTarget(ItemStack itemStack, DataComponentType<?> dataComponentType) {
if (dataComponentType == DataComponents.LODESTONE_TRACKER && itemStack.has(BetterLodestonesComponents.LODESTONES)) {
Optional<GlobalPos> current = CompassDataHandler.getCurrentLodestone(itemStack);
return current.map(globalPos -> new LodestoneTracker(Optional.of(globalPos), true)).orElse(null);
}
return itemStack.get(dataComponentType);
}
}

View File

@ -29,19 +29,12 @@ public class CompassTooltipMixin {
private static final int UNSELECTED_TICK_INTERVAL = 40;
@Inject(method = "appendHoverText", at = @At("TAIL"))
private void addCustomTooltip(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag, CallbackInfo ci) {
private void addCustomTooltip(ItemStack stack, Item.TooltipContext context, List<Component> tooltip, TooltipFlag flag, CallbackInfo ci) {
if (!(stack.getItem() instanceof CompassItem)) {
return;
}
if (level != null && !level.isClientSide()) {
CompassDataHandler.convertVanillaLodestoneCompass(stack);
}
if (level != null) {
CompassDataHandler.validateCurrentLodestone(stack, level);
}
// Tooltip is client-side, so we don't do server-side validation here
int lodestoneCount = CompassDataHandler.getLodestoneCount(stack);
if (lodestoneCount > 0) {
@ -61,9 +54,7 @@ public class CompassTooltipMixin {
tooltip.add(Component.literal("§7Current: §f" + currentIndex + "/" + lodestoneCount +
" §7at §f" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ()));
if (CompassDataHandler.isLodestoneInDifferentDimension(level, lodestone)) {
tooltip.add(Component.literal("§7Dimension: §c" + better_lodestones$formatDimensionName(dimensionName)));
} else if (CompassDataHandler.hasBrokenLodestone(stack)) {
if (CompassDataHandler.hasBrokenLodestone(stack)) {
tooltip.add(Component.literal("§cLodestone destroyed!"));
} else {
tooltip.add(Component.literal("§7Dimension: §f" + better_lodestones$formatDimensionName(dimensionName)));

View File

@ -4,6 +4,7 @@ import io.lampnet.betterlodestones.CompassDataHandler;
import io.lampnet.betterlodestones.BetterLodestones;
import net.minecraft.network.Connection;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -14,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class PlayerJoinMixin {
@Inject(method = "placeNewPlayer", at = @At("TAIL"))
private void onPlayerJoin(Connection connection, ServerPlayer player, CallbackInfo ci) {
private void onPlayerJoin(Connection connection, ServerPlayer player, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
if (player != null) {
int convertedCount = CompassDataHandler.convertPlayerLodestoneCompasses(player);
if (convertedCount > 0) {

View File

@ -1,11 +1,17 @@
package io.lampnet.betterlodestones.recipe;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.lampnet.betterlodestones.CompassDataHandler;
import io.lampnet.betterlodestones.component.BetterLodestonesComponents;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.CompassItem;
import net.minecraft.world.item.ItemStack;
@ -17,16 +23,16 @@ import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class CompassUnbindingRecipe extends CustomRecipe {
public CompassUnbindingRecipe(ResourceLocation id, CraftingBookCategory category) {
super(id, category);
public CompassUnbindingRecipe(CraftingBookCategory category) {
super(category);
}
@Override
public boolean matches(CraftingContainer craftingContainer, Level level) {
public boolean matches(CraftingInput craftingInput, Level level) {
ItemStack compass = ItemStack.EMPTY;
for (int i = 0; i < craftingContainer.getContainerSize(); ++i) {
ItemStack currentStack = craftingContainer.getItem(i);
for (int i = 0; i < craftingInput.size(); ++i) {
ItemStack currentStack = craftingInput.getItem(i);
if (!currentStack.isEmpty()) {
if (currentStack.getItem() instanceof CompassItem) {
if (!compass.isEmpty()) {
@ -39,20 +45,15 @@ public class CompassUnbindingRecipe extends CustomRecipe {
}
}
if (compass.isEmpty() || !compass.hasTag()) {
return false;
}
CompoundTag tag = compass.getTag();
return tag != null && (tag.contains("LodestonePos") || tag.contains("BetterLodestones"));
return !compass.isEmpty() && (compass.has(BetterLodestonesComponents.LODESTONES) || compass.has(net.minecraft.core.component.DataComponents.LODESTONE_TRACKER));
}
@Override
public @NotNull ItemStack assemble(CraftingContainer craftingContainer, RegistryAccess registryAccess) {
public @NotNull ItemStack assemble(@NotNull CraftingInput craftingInput, @NotNull HolderLookup.Provider provider) {
ItemStack compass = ItemStack.EMPTY;
for (int i = 0; i < craftingContainer.getContainerSize(); i++) {
ItemStack currentStack = craftingContainer.getItem(i);
for (int i = 0; i < craftingInput.size(); i++) {
ItemStack currentStack = craftingInput.getItem(i);
if (!currentStack.isEmpty() && currentStack.getItem() instanceof CompassItem) {
compass = currentStack.copy();
compass.setCount(1);
@ -86,19 +87,25 @@ public class CompassUnbindingRecipe extends CustomRecipe {
public static class CompassUnbindingRecipeSerializer implements RecipeSerializer<CompassUnbindingRecipe> {
public static final CompassUnbindingRecipeSerializer INSTANCE = new CompassUnbindingRecipeSerializer();
private static final Codec<CompassUnbindingRecipe> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(CustomRecipe::category)
).apply(instance, CompassUnbindingRecipe::new)
);
private static final StreamCodec<RegistryFriendlyByteBuf, CompassUnbindingRecipe> STREAM_CODEC = StreamCodec.of(
(buf, recipe) -> buf.writeEnum(recipe.category()),
buf -> new CompassUnbindingRecipe(buf.readEnum(CraftingBookCategory.class))
);
@Override
public @NotNull CompassUnbindingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
return new CompassUnbindingRecipe(recipeId, CraftingBookCategory.MISC);
public @NotNull com.mojang.serialization.MapCodec<CompassUnbindingRecipe> codec() {
return CODEC.fieldOf("recipe");
}
@Override
public @NotNull CompassUnbindingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
return new CompassUnbindingRecipe(recipeId, CraftingBookCategory.MISC);
}
@Override
public void toNetwork(FriendlyByteBuf buffer, CompassUnbindingRecipe recipe) {
public @NotNull StreamCodec<RegistryFriendlyByteBuf, CompassUnbindingRecipe> streamCodec() {
return STREAM_CODEC;
}
}
}

View File

@ -1,11 +1,15 @@
package io.lampnet.betterlodestones.recipe;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.lampnet.betterlodestones.config.ConfigManager;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
@ -16,18 +20,18 @@ import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
public class ConfigurableLodestoneRecipe extends CustomRecipe {
public ConfigurableLodestoneRecipe(ResourceLocation id, CraftingBookCategory category) {
super(id, category);
public ConfigurableLodestoneRecipe(CraftingBookCategory category) {
super(category);
}
@Override
public boolean matches(CraftingContainer craftingContainer, Level level) {
if (craftingContainer.getWidth() != 3 || craftingContainer.getHeight() != 3) {
public boolean matches(CraftingInput craftingInput, Level level) {
if (craftingInput.width() != 3 || craftingInput.height() != 3) {
return false;
}
Item expectedCenterItem = ConfigManager.useModernLodestoneRecipe() ? Items.IRON_INGOT : Items.NETHERITE_INGOT;
if (!craftingContainer.getItem(4).is(expectedCenterItem)) {
if (!craftingInput.getItem(4).is(expectedCenterItem)) {
return false;
}
@ -35,7 +39,7 @@ public class ConfigurableLodestoneRecipe extends CustomRecipe {
if (i == 4) {
continue;
}
if (!craftingContainer.getItem(i).is(Items.CHISELED_STONE_BRICKS)) {
if (!craftingInput.getItem(i).is(Items.CHISELED_STONE_BRICKS)) {
return false;
}
}
@ -43,7 +47,7 @@ public class ConfigurableLodestoneRecipe extends CustomRecipe {
}
@Override
public @NotNull ItemStack assemble(@NotNull CraftingContainer craftingContainer, RegistryAccess registryAccess) {
public @NotNull ItemStack assemble(@NotNull CraftingInput craftingInput, @NotNull HolderLookup.Provider provider) {
return new ItemStack(Items.LODESTONE);
}
@ -59,19 +63,24 @@ public class ConfigurableLodestoneRecipe extends CustomRecipe {
public static class Serializer implements RecipeSerializer<ConfigurableLodestoneRecipe> {
public static final Serializer INSTANCE = new Serializer();
private static final Codec<ConfigurableLodestoneRecipe> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(CustomRecipe::category)
).apply(instance, ConfigurableLodestoneRecipe::new)
);
private static final StreamCodec<RegistryFriendlyByteBuf, ConfigurableLodestoneRecipe> STREAM_CODEC = StreamCodec.of(
(buf, recipe) -> buf.writeEnum(recipe.category()),
buf -> new ConfigurableLodestoneRecipe(buf.readEnum(CraftingBookCategory.class))
);
@Override
public @NotNull ConfigurableLodestoneRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
return new ConfigurableLodestoneRecipe(recipeId, CraftingBookCategory.MISC);
public @NotNull com.mojang.serialization.MapCodec<ConfigurableLodestoneRecipe> codec() {
return CODEC.fieldOf("recipe");
}
@Override
public @NotNull ConfigurableLodestoneRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
return new ConfigurableLodestoneRecipe(recipeId, CraftingBookCategory.MISC);
}
@Override
public void toNetwork(FriendlyByteBuf buffer, ConfigurableLodestoneRecipe recipe) {
public @NotNull StreamCodec<RegistryFriendlyByteBuf, ConfigurableLodestoneRecipe> streamCodec() {
return STREAM_CODEC;
}
}
}

View File

@ -20,10 +20,10 @@ public final class BetterLodestonesRegistry {
public static final RegistrySupplier<RecipeSerializer<?>> COMPASS_UNBINDING =
RECIPE_SERIALIZERS.register("compass_unbinding", () -> CompassUnbindingRecipe.CompassUnbindingRecipeSerializer.INSTANCE);
public static final DimensionalCompassBindingTrigger DIMENSIONAL_COMPASS_BINDING = new DimensionalCompassBindingTrigger();
public static final DimensionalCompassBindingTrigger DIMENSIONAL_COMPASS_BINDING =
CriteriaTriggers.register("dimensional_compass_binding", new DimensionalCompassBindingTrigger());
public static void init() {
RECIPE_SERIALIZERS.register();
CriteriaTriggers.register(DIMENSIONAL_COMPASS_BINDING);
}
}

View File

@ -23,9 +23,9 @@
],
"depends": {
"fabricloader": ">=0.17.2",
"minecraft": "~1.20.1",
"java": ">=17",
"architectury": ">=9.2.14",
"minecraft": "~1.21.1",
"java": ">=21",
"architectury": ">=13.0.8",
"fabric-api": "*"
}
}

View File

@ -1 +0,0 @@
loom.platform=forge

View File

@ -1,32 +0,0 @@
package io.lampnet.betterlodestones.forge;
import io.lampnet.betterlodestones.BetterLodestones;
import io.lampnet.betterlodestones.config.ConfigManager;
import io.lampnet.betterlodestones.forge.config.BetterLodestonesForgeConfig;
import dev.architectury.platform.forge.EventBuses;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod(BetterLodestones.MOD_ID)
public final class BetterLodestonesForge {
public BetterLodestonesForge() {
var modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
EventBuses.registerModEventBus(BetterLodestones.MOD_ID, modEventBus);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, BetterLodestonesForgeConfig.SPEC, "better-lodestones.toml");
modEventBus.addListener(this::onConfigLoad);
BetterLodestones.init();
}
private void onConfigLoad(final ModConfigEvent event) {
if (event.getConfig().getSpec() == BetterLodestonesForgeConfig.SPEC) {
ConfigManager.setMaxLodestones(BetterLodestonesForgeConfig.getMaxLodestones());
ConfigManager.setUseModernLodestoneRecipe(BetterLodestonesForgeConfig.useModernLodestoneRecipe());
BetterLodestones.LOGGER.info("Loaded Forge config and updated ConfigManager.");
}
}
}

View File

@ -2,14 +2,16 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true
# Mod properties
mod_version=0.9
mod_version=0.10
maven_group=io.lampnet
archives_name=better-lodestones
enabled_platforms=fabric,forge
enabled_platforms=fabric,neoforge
# Minecraft properties
minecraft_version=1.20.1
minecraft_version=1.21.1
# Dependencies
architectury_api_version=9.2.14
architectury_api_version=13.0.8
fabric_loader_version=0.17.2
fabric_api_version=0.92.6+1.20.1
forge_version=1.20.1-47.4.9
fabric_api_version=0.116.6+1.21.1
neoforge_version=21.1.209
loom.experimental.official_data_components=true

View File

@ -2,15 +2,9 @@ plugins {
id 'com.github.johnrengelman.shadow'
}
loom {
forge {
mixinConfig "better_lodestones.mixins.json"
}
}
architectury {
platformSetupLoomIde()
forge()
neoForge()
}
configurations {
@ -20,7 +14,7 @@ configurations {
}
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
developmentNeoForge.extendsFrom common
// Files in this configuration will be bundled into your mod using the Shadow plugin.
// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
@ -30,19 +24,26 @@ configurations {
}
}
dependencies {
forge "net.minecraftforge:forge:$rootProject.forge_version"
repositories {
maven {
name = 'NeoForged'
url = 'https://maven.neoforged.net/releases'
}
}
modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version"
dependencies {
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
modImplementation "dev.architectury:architectury-neoforge:$rootProject.architectury_api_version"
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionForge')
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')
}
processResources {
inputs.property 'version', project.version
filesMatching('META-INF/mods.toml') {
filesMatching('META-INF/neoforge.mods.toml') {
expand version: project.version
}
}

View File

@ -0,0 +1 @@
loom.platform=neoforge

View File

@ -0,0 +1,29 @@
package io.lampnet.betterlodestones.neoforge;
import io.lampnet.betterlodestones.BetterLodestones;
import io.lampnet.betterlodestones.config.ConfigManager;
import io.lampnet.betterlodestones.neoforge.config.BetterLodestonesNeoForgeConfig;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.config.ModConfigEvent;
import net.neoforged.bus.api.IEventBus;
@Mod(BetterLodestones.MOD_ID)
public final class BetterLodestonesNeoForge {
public BetterLodestonesNeoForge(IEventBus modEventBus, ModContainer modContainer) {
modContainer.registerConfig(ModConfig.Type.COMMON, BetterLodestonesNeoForgeConfig.SPEC, "better-lodestones.toml");
modEventBus.addListener(this::onConfigLoad);
BetterLodestones.init();
}
private void onConfigLoad(final ModConfigEvent event) {
if (event.getConfig().getSpec() == BetterLodestonesNeoForgeConfig.SPEC) {
ConfigManager.setMaxLodestones(BetterLodestonesNeoForgeConfig.getMaxLodestones());
ConfigManager.setUseModernLodestoneRecipe(BetterLodestonesNeoForgeConfig.useModernLodestoneRecipe());
BetterLodestones.LOGGER.info("Loaded NeoForge config and updated ConfigManager.");
}
}
}

View File

@ -1,14 +1,14 @@
package io.lampnet.betterlodestones.forge.config;
package io.lampnet.betterlodestones.neoforge.config;
import net.minecraftforge.common.ForgeConfigSpec;
import net.neoforged.neoforge.common.ModConfigSpec;
public class BetterLodestonesForgeConfig {
public static final ForgeConfigSpec SPEC;
public static final ForgeConfigSpec.IntValue MAX_LODESTONES;
public static final ForgeConfigSpec.BooleanValue USE_MODERN_LODESTONE_RECIPE;
public class BetterLodestonesNeoForgeConfig {
public static final ModConfigSpec SPEC;
public static final ModConfigSpec.IntValue MAX_LODESTONES;
public static final ModConfigSpec.BooleanValue USE_MODERN_LODESTONE_RECIPE;
static {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
builder.comment("Maximum number of Lodestones that can be bound to a single compass")
.comment("0 = No limit (default)")

View File

@ -1,6 +1,6 @@
modLoader = "javafml"
loaderVersion = "[47,)"
#issueTrackerURL = ""
loaderVersion = "[2,)"
issueTrackerURL = "https://github.com/C4ndle/better-lodestones/issues"
license = "MIT"
[[mods]]
@ -12,23 +12,27 @@ description = 'Reworks Lodestone system, allowing Compasses to be bound to multi
#logoFile = ""
[[mixins]]
type = "COMMON"
config = "better_lodestones.mixins.json"
[[dependencies.better_lodestones]]
modId = "forge"
modId = "neoforge"
mandatory = true
versionRange = "[47,)"
versionRange = "[21.0,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.better_lodestones]]
modId = "minecraft"
mandatory = true
versionRange = "[1.20.1,)"
versionRange = "[1.21.1,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.better_lodestones]]
modId = "architectury"
mandatory = true
versionRange = "[9.2.14,)"
versionRange = "[13.0,)"
ordering = "AFTER"
side = "BOTH"

View File

@ -7,8 +7,8 @@ pluginManagement {
}
}
rootProject.name = 'better_lodestones'
rootProject.name = "Better Lodestones"
include 'common'
include 'fabric'
include 'forge'
include('common')
include('fabric')
include('neoforge')