Skip to content

Commit dc0b78b

Browse files
Add support for the recipeBook tag, bump version
1 parent b95fadd commit dc0b78b

6 files changed

Lines changed: 38 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- Update to Minecraft 26.1-snapshot-10.
22
- Add support for the `active_effects` tag. This allows you to show an effect's icon without showing its particles, or vice versa, or to add a hidden effect to an effect instance.
3+
- Add support for the `recipeBook` tag.
34

45
This version was not released for NeoForge, as NeoForge does not yet support this version of Minecraft.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ NBT tags currently supported:
101101
- `warden_spawn_tracker`
102102
- `entered_nether_pos`
103103
- `seenCredits`
104+
- `recipeBook`
104105
- `respawn`
105106
- `spawn_extra_particles_on_fall`
106107
- `raid_omen_position`
@@ -126,7 +127,6 @@ NBT tags I won't add support for:
126127
- `playerGameType`
127128
- `previousPlayerGameType`[^6]
128129
- `RootVehicle`[^2]
129-
- `recipeBook`[^7]
130130
- `Dimension`
131131
- `ender_pearls`
132132

@@ -136,4 +136,3 @@ NBT tags I won't add support for:
136136
[^4]: Use the `/xp` command.
137137
[^5]: I can't think of any use cases for this tag, but will add support on request.
138138
[^6]: Unable to implement due to limitations within the vanilla client.
139-
[^7]: Use the `/recipe` command.

common/src/main/java/xyz/eclipseisoffline/modifyplayerdata/PlayerData.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
import com.mojang.serialization.Codec;
55
import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket;
66
import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
7+
import net.minecraft.resources.ResourceKey;
8+
import net.minecraft.stats.ServerRecipeBook;
79
import net.minecraft.world.effect.MobEffectInstance;
10+
import net.minecraft.world.item.crafting.Recipe;
11+
import net.minecraft.world.item.crafting.RecipeHolder;
812
import xyz.eclipseisoffline.modifyplayerdata.mixin.FoodDataAccessor;
913
import xyz.eclipseisoffline.modifyplayerdata.mixin.LivingEntityAccessor;
1014
import xyz.eclipseisoffline.modifyplayerdata.mixin.PlayerAccessor;
1115
import xyz.eclipseisoffline.modifyplayerdata.mixin.ServerPlayerAccessor;
1216

17+
import java.util.Collection;
1318
import java.util.HashSet;
1419
import java.util.List;
1520
import java.util.Optional;
@@ -37,6 +42,7 @@
3742
import net.minecraft.world.level.storage.ValueOutput;
3843
import net.minecraft.world.phys.Vec2;
3944
import net.minecraft.world.phys.Vec3;
45+
import xyz.eclipseisoffline.modifyplayerdata.mixin.ServerRecipeBookAccessor;
4046

4147
public class PlayerData {
4248

@@ -172,6 +178,17 @@ public static void apply(ServerPlayer player, ValueInput input) {
172178
input.read("warden_spawn_tracker", WardenSpawnTracker.CODEC).ifPresent(manager -> ((ServerPlayerAccessor) player).setWardenSpawnTracker(manager));
173179
input.read("entered_nether_pos", Vec3.CODEC).ifPresent(pos -> ((ServerPlayerAccessor) player).setEnteredNetherPosition(pos));
174180
getOptionalBoolean(input, "seenCredits").ifPresent(seenCredits -> ((ServerPlayerAccessor) player).setSeenCredits(seenCredits));
181+
182+
input.read("recipeBook", ServerRecipeBook.Packed.CODEC).ifPresent(packed -> {
183+
Set<ResourceKey<Recipe<?>>> known = ((ServerRecipeBookAccessor) player.getRecipeBook()).getKnown();
184+
185+
// Not the most efficient, but it gets the job done, annoying to do otherwise
186+
player.getRecipeBook().removeRecipes((Collection) known.stream().map(recipe -> new RecipeHolder<>(recipe, null)).toList(), player);
187+
188+
player.getRecipeBook().loadUntrusted(packed, id -> player.level().getServer().getRecipeManager().byKey(id).isPresent());
189+
player.getRecipeBook().sendInitialRecipeBook(player);
190+
});
191+
175192
input.read("respawn", ServerPlayer.RespawnConfig.CODEC).ifPresent(respawn -> player.setRespawnPosition(respawn, false));
176193
getOptionalBoolean(input, "spawn_extra_particles_on_fall").ifPresent(player::setSpawnExtraParticlesOnFall);
177194
input.read("raid_omen_position", BlockPos.CODEC).ifPresent(player::setRaidOmenPosition);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package xyz.eclipseisoffline.modifyplayerdata.mixin;
2+
3+
import net.minecraft.resources.ResourceKey;
4+
import net.minecraft.stats.ServerRecipeBook;
5+
import net.minecraft.world.item.crafting.Recipe;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.gen.Accessor;
8+
9+
import java.util.Set;
10+
11+
@Mixin(ServerRecipeBook.class)
12+
public interface ServerRecipeBookAccessor {
13+
14+
@Accessor
15+
Set<ResourceKey<Recipe<?>>> getKnown();
16+
}

common/src/main/resources/modifyplayerdata.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"LivingEntityAccessor",
1212
"PlayerAccessor",
1313
"ServerPlayerAccessor",
14-
"ServerPlayerMixin"
14+
"ServerPlayerMixin",
15+
"ServerRecipeBookAccessor"
1516
],
1617
"client": [
1718
],

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod_id=modifyplayerdata
55
mod_name=Modify Player Data
66
mod_description=Modify Player Data allows Minecraft's data commands (/data, /execute store, etc.) to modify player data
77

8-
version=0.4.0-26.1-snapshot-1
8+
version=0.4.1-26.1-snapshot-10
99

1010
# Publishing
1111
maven_group=xyz.eclipseisoffline

0 commit comments

Comments
 (0)