Skip to content

Commit

Permalink
Fix servers not letting clients with Fabric API join
Browse files Browse the repository at this point in the history
- Vanilla clients as well as clients who have the mod installed locally could join, but clients with *just* Fabric API were rejected.

This is due to a registry mismatch, specifically because the mod was registering a data component for items.

Unfortunately, the "alternate server-side cost display" feature had to be temporarily removed for this.
  • Loading branch information
mschae23 committed May 14, 2024
1 parent d2b3341 commit 50fef7a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 172 deletions.
15 changes: 5 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.10
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.11

# Mod Properties
mod_version = 3.2.0
mod_version = 3.2.1
maven_group = de.mschae23.minecraft.mod
archives_base_name = grind-enchantments

# Dependencies
fabric_api_version=0.97.6+1.20.5
fabric_api_version=0.98.0+1.20.6
codec_config_api_version=2.0.0+1.20.5-rc3
tax_free_levels_version=loom-SNAPSHOT

# Vineflower properties
# suppress inspection "TrailingSpacesInProperty"
vineflower.preference.ind =\ \ \ \
vineflower.preference.nls =1
14 changes: 11 additions & 3 deletions src/main/java/de/mschae23/grindenchantments/GrindEnchantments.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.component.type.LoreComponent;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import de.mschae23.grindenchantments.config.DedicatedServerConfig;
import de.mschae23.grindenchantments.config.FilterConfig;
import de.mschae23.grindenchantments.cost.CostFunction;
import de.mschae23.grindenchantments.item.GrindEnchantmentsDataComponent;

public class GrindEnchantments {
public static int getLevelCost(ItemStack stack, CostFunction costFunction, FilterConfig filter, RegistryWrapper.WrapperLookup wrapperLookup) {
Expand All @@ -51,7 +52,13 @@ public static ItemStack addLevelCostComponent(ItemStack stack, IntSupplier cost,
return stack;

ItemStack changed = stack.copy();
changed.set(GrindEnchantmentsDataComponent.TYPE, new GrindEnchantmentsDataComponent(cost.getAsInt(), canTakeItem));
changed.apply(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT, nbt -> nbt.apply(compound -> {
NbtCompound tag = new NbtCompound();
tag.putInt("Cost", cost.getAsInt());
tag.putBoolean("CanTake", canTakeItem);

compound.put(GrindEnchantmentsMod.MODID, tag);
}));
return changed;
}

Expand All @@ -71,7 +78,8 @@ public static ItemStack addLevelCostLore(ItemStack stack, IntSupplier cost, bool
public static ItemStack removeLevelCostNbt(ItemStack stack) {
// Relies on ItemStacks being mutable AND the stack not being copied into the player inventory before calling this method

stack.remove(GrindEnchantmentsDataComponent.TYPE);
stack.apply(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT, nbt -> nbt.apply(compound ->
compound.remove(GrindEnchantmentsMod.MODID)));
return stack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import de.mschae23.grindenchantments.impl.DisenchantOperation;
import de.mschae23.grindenchantments.impl.MoveOperation;
import de.mschae23.grindenchantments.impl.ResetRepairCostOperation;
import de.mschae23.grindenchantments.item.GrindEnchantmentsDataComponent;
import de.mschae23.grindenchantments.registry.GrindEnchantmentsRegistries;
import io.github.fourmisain.taxfreelevels.TaxFreeLevels;
import org.apache.logging.log4j.Level;
Expand Down Expand Up @@ -68,8 +67,6 @@ public void onInitialize() {
GrindEnchantmentsRegistries.init();
CostFunctionType.init();

GrindEnchantmentsDataComponent.init();

DisenchantOperation disenchant = new DisenchantOperation();
MoveOperation move = new MoveOperation();
ResetRepairCostOperation resetRepairCost = new ResetRepairCostOperation();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ private void onGetOutputStack(ItemStack input1, ItemStack input2, CallbackInfoRe
ItemStack result = GrindstoneEvents.UPDATE_RESULT.invoker().onUpdateResult(input1, input2, player, player.getRegistryManager());

if (!result.isEmpty()) {
int cost = GrindstoneEvents.LEVEL_COST.invoker().getLevelCost(input1, input2, player, player.getRegistryManager());

if (cost >= 0) {
boolean canTake = GrindstoneEvents.CAN_TAKE_RESULT.invoker().canTakeResult(input1, input2, player, player.getRegistryManager());
result = GrindEnchantments.addLevelCostComponent(result, () -> cost, canTake, GrindEnchantmentsMod.getConfig().dedicatedServerConfig());
}

cir.setReturnValue(result);
}
}
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/resources/grindenchantments.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"GrindstoneScreenHandlerMixin",
"GrindstoneScreenHandlerMixin$Anonymous2Mixin",
"GrindstoneScreenHandlerMixin$Anonymous3Mixin",
"GrindstoneScreenHandlerMixin$Anonymous4Mixin",
"ScreenHandlerMixin"
"GrindstoneScreenHandlerMixin$Anonymous4Mixin"
],
"client": [
"GrindstoneScreenMixin"
Expand Down

0 comments on commit 50fef7a

Please sign in to comment.