|
4 | 4 | import com.mojang.serialization.Codec; |
5 | 5 | import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; |
6 | 6 | import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; |
| 7 | +import net.minecraft.resources.ResourceKey; |
| 8 | +import net.minecraft.stats.ServerRecipeBook; |
7 | 9 | import net.minecraft.world.effect.MobEffectInstance; |
| 10 | +import net.minecraft.world.item.crafting.Recipe; |
| 11 | +import net.minecraft.world.item.crafting.RecipeHolder; |
8 | 12 | import xyz.eclipseisoffline.modifyplayerdata.mixin.FoodDataAccessor; |
9 | 13 | import xyz.eclipseisoffline.modifyplayerdata.mixin.LivingEntityAccessor; |
10 | 14 | import xyz.eclipseisoffline.modifyplayerdata.mixin.PlayerAccessor; |
11 | 15 | import xyz.eclipseisoffline.modifyplayerdata.mixin.ServerPlayerAccessor; |
12 | 16 |
|
| 17 | +import java.util.Collection; |
13 | 18 | import java.util.HashSet; |
14 | 19 | import java.util.List; |
15 | 20 | import java.util.Optional; |
|
37 | 42 | import net.minecraft.world.level.storage.ValueOutput; |
38 | 43 | import net.minecraft.world.phys.Vec2; |
39 | 44 | import net.minecraft.world.phys.Vec3; |
| 45 | +import xyz.eclipseisoffline.modifyplayerdata.mixin.ServerRecipeBookAccessor; |
40 | 46 |
|
41 | 47 | public class PlayerData { |
42 | 48 |
|
@@ -172,6 +178,17 @@ public static void apply(ServerPlayer player, ValueInput input) { |
172 | 178 | input.read("warden_spawn_tracker", WardenSpawnTracker.CODEC).ifPresent(manager -> ((ServerPlayerAccessor) player).setWardenSpawnTracker(manager)); |
173 | 179 | input.read("entered_nether_pos", Vec3.CODEC).ifPresent(pos -> ((ServerPlayerAccessor) player).setEnteredNetherPosition(pos)); |
174 | 180 | 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 | + |
175 | 192 | input.read("respawn", ServerPlayer.RespawnConfig.CODEC).ifPresent(respawn -> player.setRespawnPosition(respawn, false)); |
176 | 193 | getOptionalBoolean(input, "spawn_extra_particles_on_fall").ifPresent(player::setSpawnExtraParticlesOnFall); |
177 | 194 | input.read("raid_omen_position", BlockPos.CODEC).ifPresent(player::setRaidOmenPosition); |
|
0 commit comments