1.21.11 Early Access

waypoint has force disabled because of some serious bug
This commit is contained in:
Helvetica Volubi
2025-12-18 09:42:25 +08:00
parent c26d8d1ee3
commit bbcc85fa93
155 changed files with 1517 additions and 1688 deletions
@@ -1,15 +0,0 @@
package fun.bm.lophine.config.modules.fixes;
import me.earthme.luminol.config.IConfigModule;
import me.earthme.luminol.config.flags.ConfigClassInfo;
import me.earthme.luminol.config.flags.ConfigInfo;
import me.earthme.luminol.config.flags.TransformedConfig;
import me.earthme.luminol.enums.EnumConfigCategory;
@ConfigClassInfo(category = EnumConfigCategory.FIXES, name = "end-void-ring")
public class EndVoidRingsConfig implements IConfigModule {
@TransformedConfig(name = "enabled", directory = {"gameplay", "end_void_rings"})
@ConfigInfo(name = "enabled", comments = """
If enabled, it will generate end void rings, like MC-159283.""")
public static boolean enabled = false;
}
@@ -8,6 +8,8 @@ import me.earthme.luminol.enums.EnumConfigCategory;
@ConfigClassInfo(category = EnumConfigCategory.REMOVED, name = "removed_config")
public class RemovedConfig implements IConfigModule {
@TransformedConfig(name = "enabled", directory = {"fixes", "end-void-ring"}, transform = false)
@TransformedConfig(name = "enabled", directory = {"gameplay", "end_void_rings"}, transform = false)
@TransformedConfig(name = "datapack_command_enabled", directory = {"experiment", "command"}, transform = false)
@TransformedConfig(name = "disable_end_crystal_check", directory = {"fixes", "end_crystal"}, transform = false)
@TransformedConfig(name = "disable_end_crystal_check", directory = {"misc", "end_crystal"}, transform = false)
@@ -12,6 +12,7 @@ public class ConcurrentTable<X, Y, Z> extends AbstractConcurrentTable<X, Y, Z> {
@Override
public void put(X x, Y y, Z z) {
if (true) return; // TODO: because of some bug, we disabled it
data.add(new TableEntry<>(x, y, z));
}
@@ -12,6 +12,7 @@ public class OptimizedConcurrentTable<X, Y, Z> extends ConcurrentTable<X, Y, Z>
@Override
public void put(X x, Y y, Z z) {
if (true) return; // TODO: because of some bug, we disabled it
super.put(x, y, z);
xyIndex.computeIfAbsent(x, k -> new ConcurrentHashMap<>())
.computeIfAbsent(y, k -> ConcurrentHashMap.newKeySet()).add(z);
@@ -93,7 +93,6 @@ public class BotDataStorage implements IPlayerDataStorage {
}
}
@Override
public Optional<ValueInput> load(Player player, ProblemReporter reporter) {
return this.load(player.getScoreboardName(), player.getStringUUID()).map(nbt -> {
ValueInput valueInput = TagValueInput.create(reporter, player.registryAccess(), nbt);
@@ -21,9 +21,11 @@ import ca.spottedleaf.moonrise.common.util.TickThread;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.logging.LogUtils;
import fun.bm.lophine.config.modules.function.FakeplayerConfig;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.profile.MutablePropertyMap;
import io.papermc.paper.threadedregions.RegionizedServer;
import io.papermc.paper.threadedregions.scheduler.FoliaGlobalRegionScheduler;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -37,9 +39,9 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.AbstractVillager;
import net.minecraft.world.entity.npc.villager.AbstractVillager;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEnderpearl;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.ValueInput;
import org.bukkit.Bukkit;
@@ -92,7 +94,7 @@ public class BotList {
Location location = event.getCreateLocation();
ServerLevel world = ((CraftWorld) location.getWorld()).getHandle();
CustomGameProfile profile = new CustomGameProfile(BotUtil.getBotUUID(state), state.name(), state.skin());
GameProfile profile = setProfile(BotUtil.getBotUUID(state), state.name(), state.skin());
ServerBot bot = new ServerBot(this.server, world, profile);
bot.createState = state;
if (event.getCreator() instanceof org.bukkit.entity.Player player) {
@@ -122,11 +124,16 @@ public class BotList {
ServerBot bot = new ServerBot(this.server, this.server.getLevel(Level.OVERWORLD), new GameProfile(uuid, realName));
bot.connection = new ServerBotPacketListenerImpl(this.server, bot, new ServerBotPacketListenerImpl.BotConnection());
bot.connection.markClientLoaded();
Optional<ValueInput> optional;
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(bot.problemPath(), LOGGER)) {
optional = playerIO.load(bot, scopedCollector);
} catch (Exception e) {
throw new RuntimeException(e);
if (playerIO instanceof BotDataStorage botIO) {
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(bot.problemPath(), LOGGER)) {
optional = botIO.load(bot, scopedCollector);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
optional = Optional.empty();
}
if (optional.isEmpty()) {
@@ -155,6 +162,7 @@ public class BotList {
bot.isRealPlayer = true;
bot.loginTime = System.currentTimeMillis();
bot.connection = new ServerBotPacketListenerImpl(this.server, bot, new ServerBotPacketListenerImpl.BotConnection());
bot.connection.markClientLoaded();
bot.setServerLevel(world);
BotSpawnLocationEvent event = new BotSpawnLocationEvent(bot.getBukkitEntity(), location);
@@ -173,7 +181,7 @@ public class BotList {
this.botsByName.put(bot.getScoreboardName().toLowerCase(Locale.ROOT), bot);
this.botsByUUID.put(bot.getUUID(), bot);
bot.supressTrackerForLogin = true;
bot.suppressTrackerForLogin = true;
optional.ifPresent(nbt -> {
bot.loadAndSpawnEnderPearls(nbt);
@@ -204,7 +212,7 @@ public class BotList {
}
bot.renderInfo();
bot.supressTrackerForLogin = false;
bot.suppressTrackerForLogin = false;
bot.level().getChunkSource().chunkMap.addEntity(bot);
bot.renderData();
@@ -415,17 +423,11 @@ public class BotList {
return this.dataStorage.getSavedBotList();
}
public static class CustomGameProfile extends GameProfile {
public CustomGameProfile(UUID uuid, String name, String[] skin) {
super(uuid, name);
this.setSkin(skin);
}
public void setSkin(String[] skin) {
if (skin != null) {
this.getProperties().put("textures", new Property("textures", skin[0], skin[1]));
}
}
public GameProfile setProfile(UUID uuid, String name, String[] skin) {
GameProfile profile = new GameProfile(uuid, name);
if (skin == null) return profile;
PropertyMap profileMap = new MutablePropertyMap(profile.properties());
profileMap.put("textures", new Property("textures", skin[0], skin[1]));
return new GameProfile(uuid, name, profileMap);
}
}
@@ -17,6 +17,7 @@
package org.leavesmc.leaves.bot;
import com.google.gson.JsonElement;
import com.mojang.datafixers.DataFixer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.stats.ServerStatsCounter;
@@ -31,7 +32,7 @@ public class BotStatsCounter extends ServerStatsCounter {
private static final File UNKOWN_FILE = new File("BOT_STATS_REMOVE_THIS");
public BotStatsCounter(MinecraftServer server) {
super(server, UNKOWN_FILE);
super(server, UNKOWN_FILE.toPath());
}
@Override
@@ -43,7 +44,7 @@ public class BotStatsCounter extends ServerStatsCounter {
}
@Override
public void parseLocal(@NotNull DataFixer dataFixer, @NotNull String json) {
public void parse(@NotNull DataFixer dataFixer, @NotNull JsonElement json) {
}
@Override
@@ -17,15 +17,11 @@
package org.leavesmc.leaves.bot;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.storage.ValueInput;
import java.util.Optional;
public interface IPlayerDataStorage {
void save(Player player);
Optional<ValueInput> load(Player player, ProblemReporter reporter);
// Optional<ValueInput> load(Player player, ProblemReporter reporter);
}
@@ -53,12 +53,12 @@ import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Input;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.entity.vehicle.AbstractBoat;
import net.minecraft.world.entity.vehicle.boat.AbstractBoat;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.gamerules.GameRules;
import net.minecraft.world.level.portal.TeleportTransition;
import net.minecraft.world.level.storage.ValueInput;
import net.minecraft.world.level.storage.ValueOutput;
@@ -122,7 +122,6 @@ public class ServerBot extends ServerPlayer {
this.notSleepTicks = 0;
this.fauxSleeping = FakeplayerConfig.canSkipSleep;
this.getBukkitEntity().setSimulationDistance(FakeplayerConfig.getSimulationDistance(this));
this.setClientLoaded(true);
}
@Override
@@ -201,7 +200,7 @@ public class ServerBot extends ServerPlayer {
this.notSleepTicks = 0;
}
if (!this.level().isClientSide && this.level().isBrightOutside()) {
if (!this.level().isClientSide() && this.level().isBrightOutside()) {
this.stopSleepInBed(false, true);
}
} else if (this.sleepCounter > 0) {
@@ -351,7 +350,7 @@ public class ServerBot extends ServerPlayer {
if (FakeplayerConfig.canOpenInventory) {
if (player instanceof ServerPlayer player1 && player.getMainHandItem().isEmpty()) {
BotInventoryOpenEvent event = new BotInventoryOpenEvent(this.getBukkitEntity(), player1.getBukkitEntity());
this.getServer().server.getPluginManager().callEvent(event);
MinecraftServer.getServer().server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
player.openMenu(new SimpleMenuProvider((i, inventory, p) -> ChestMenu.sixRows(i, inventory, this.container), this.getDisplayName()));
return InteractionResult.SUCCESS;
@@ -423,7 +422,7 @@ public class ServerBot extends ServerPlayer {
createBuilder.createReason(BotCreateEvent.CreateReason.INTERNAL).creator(null);
this.createState = createBuilder.build();
this.gameProfile = new BotList.CustomGameProfile(this.getUUID(), this.createState.name(), this.createState.skin());
this.gameProfile = BotList.INSTANCE.setProfile(this.getUUID(), this.createState.name(), this.createState.skin());
if (nbt.list("actions", CompoundTag.CODEC).isPresent()) {
@@ -480,22 +479,22 @@ public class ServerBot extends ServerPlayer {
}
public void renderInfo() {
this.getServer().getPlayerList().getPlayers().forEach(this::sendPlayerInfo);
MinecraftServer.getServer().getPlayerList().getPlayers().forEach(this::sendPlayerInfo);
}
public void renderData() {
this.getServer().getPlayerList().getPlayers().forEach(
MinecraftServer.getServer().getPlayerList().getPlayers().forEach(
player -> this.sendFakeDataIfNeed(player, false)
);
}
private void sendPacket(Packet<?> packet) {
this.getServer().getPlayerList().getPlayers().forEach(player -> player.connection.send(packet));
MinecraftServer.getServer().getPlayerList().getPlayers().forEach(player -> player.connection.send(packet));
}
@Override
public void die(@NotNull DamageSource damageSource) {
boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
boolean flag = this.level().getGameRules().get(GameRules.SHOW_DEATH_MESSAGES);
Component defaultMessage = this.getCombatTracker().getDeathMessage();
BotDeathEvent event = new BotDeathEvent(this.getBukkitEntity(), PaperAdventure.asAdventure(defaultMessage), flag);
@@ -512,18 +511,18 @@ public class ServerBot extends ServerPlayer {
net.kyori.adventure.text.Component deathMessage = event.deathMessage();
if (event.isSendDeathMessage() && deathMessage != null && !deathMessage.equals(net.kyori.adventure.text.Component.empty())) {
this.getServer().getPlayerList().broadcastSystemMessage(PaperAdventure.asVanilla(deathMessage), false);
MinecraftServer.getServer().getPlayerList().broadcastSystemMessage(PaperAdventure.asVanilla(deathMessage), false);
}
this.getServer().getBotList().removeBot(this, BotRemoveEvent.RemoveReason.DEATH, null, false);
MinecraftServer.getServer().getBotList().removeBot(this, BotRemoveEvent.RemoveReason.DEATH, null, false);
}
@Override
public boolean startRiding(@NotNull Entity vehicle, boolean force) {
if (super.startRiding(vehicle, force)) {
if (vehicle.getControllingPassenger() == this) { // see net.minecraft.server.networkServerGamePacketListenerImpl#handleMoveVehicle
public boolean startRiding(Entity entity, boolean force, boolean triggerEvents) {
if (super.startRiding(entity, force, triggerEvents)) {
if (entity.getControllingPassenger() == this) { // see net.minecraft.server.networkServerGamePacketListenerImpl#handleMoveVehicle
this.setDeltaMovement(Vec3.ZERO);
this.setYRot(vehicle.yRotO);
this.setYRot(entity.yRotO);
}
return true;
} else {
@@ -46,7 +46,7 @@ public class ServerMountAction extends AbstractBotAction<ServerMountAction> {
)).toList();
for (Vehicle vehicle : vehicles) {
if (bot.startRiding(((CraftEntity) vehicle).getHandle(), false)) {
if (bot.startRiding(((CraftEntity) vehicle).getHandle(), false, true)) {
return true;
}
}
@@ -25,7 +25,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.commands.arguments.coordinates.Coordinates;
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.phys.Vec3;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -141,7 +141,7 @@ public class CreateCommand extends BotSubcommand {
}
}
private static class WorldArgument extends ArgumentNode<ResourceLocation> {
private static class WorldArgument extends ArgumentNode<Identifier> {
private WorldArgument() {
super("world", DimensionArgument.dimension());
@@ -22,7 +22,7 @@ import fun.bm.lophine.config.modules.function.FakeplayerConfig;
import io.papermc.paper.adventure.PaperAdventure;
import net.kyori.adventure.text.Component;
import net.minecraft.commands.arguments.DimensionArgument;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import org.bukkit.Bukkit;
@@ -85,7 +85,7 @@ public class ListCommand extends BotSubcommand {
.map(PaperAdventure::asAdventure)
.reduce((a, b) -> a.append(text(", ", GRAY)).append(b))
.get();
String worldLocation = ((CraftWorld) world).getHandle().dimension().location().toString();
String worldLocation = ((CraftWorld) world).getHandle().dimension().identifier().toString();
return join(noSeparators(),
text(world.getName(), AQUA).hoverEvent(showText(text(worldLocation))),
text(" (" + botsInLevel.size() + ")\n", GRAY),
@@ -93,7 +93,7 @@ public class ListCommand extends BotSubcommand {
);
}
private static class WorldArgument extends ArgumentNode<ResourceLocation> {
private static class WorldArgument extends ArgumentNode<Identifier> {
private WorldArgument() {
super("world", DimensionArgument.dimension());
@@ -18,11 +18,11 @@
package org.leavesmc.leaves.protocol;
import fun.bm.lophine.config.modules.function.protocol.AppleSkinProtocolConfig;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.food.FoodData;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.gamerules.GameRules;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.core.Context;
@@ -41,9 +41,9 @@ public class AppleSkinProtocol implements LeavesProtocol {
public static final String PROTOCOL_ID = "appleskin";
private static final ResourceLocation SATURATION_KEY = id("saturation");
private static final ResourceLocation EXHAUSTION_KEY = id("exhaustion");
private static final ResourceLocation NATURAL_REGENERATION_KEY = id("natural_regeneration");
private static final Identifier SATURATION_KEY = id("saturation");
private static final Identifier EXHAUSTION_KEY = id("exhaustion");
private static final Identifier NATURAL_REGENERATION_KEY = id("natural_regeneration");
private static final float MINIMUM_EXHAUSTION_CHANGE_THRESHOLD = 0.01F;
@@ -54,8 +54,8 @@ public class AppleSkinProtocol implements LeavesProtocol {
private static final Map<UUID, Set<String>> subscribedChannels = new ConcurrentHashMap<>();
@Contract("_ -> new")
public static ResourceLocation id(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID, path);
public static Identifier id(String path) {
return Identifier.tryBuild(PROTOCOL_ID, path);
}
@ProtocolHandler.PlayerJoin
@@ -70,8 +70,8 @@ public class AppleSkinProtocol implements LeavesProtocol {
}
@ProtocolHandler.MinecraftRegister(onlyNamespace = true)
public static void onPlayerSubscribed(@NotNull Context context, ResourceLocation id) {
subscribedChannels.computeIfAbsent(context.profile().getId(), k -> new HashSet<>()).add(id.getPath());
public static void onPlayerSubscribed(@NotNull Context context, Identifier id) {
subscribedChannels.computeIfAbsent(context.profile().id(), k -> new HashSet<>()).add(id.getPath());
}
@ProtocolHandler.Ticker
@@ -104,7 +104,7 @@ public class AppleSkinProtocol implements LeavesProtocol {
}
case "natural_regeneration" -> {
boolean regeneration = player.level().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION);
boolean regeneration = player.level().getGameRules().get(GameRules.NATURAL_HEALTH_REGENERATION);
Boolean previousRegeneration = previousNaturalRegeneration.get(player);
if (previousRegeneration == null || regeneration != previousRegeneration) {
ProtocolUtils.sendBytebufPacket(player, NATURAL_REGENERATION_KEY, buf -> buf.writeBoolean(regeneration));
@@ -22,7 +22,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -50,19 +50,19 @@ public class BBORProtocol implements LeavesProtocol {
public static final String PROTOCOL_ID = "bbor";
// send
private static final ResourceLocation INITIALIZE_CLIENT = id("initialize");
private static final ResourceLocation ADD_BOUNDING_BOX = id("add_bounding_box_v2");
private static final ResourceLocation STRUCTURE_LIST_SYNC = id("structure_list_sync_v1");
private static final Identifier INITIALIZE_CLIENT = id("initialize");
private static final Identifier ADD_BOUNDING_BOX = id("add_bounding_box_v2");
private static final Identifier STRUCTURE_LIST_SYNC = id("structure_list_sync_v1");
// call
private static final Map<Integer, ServerPlayer> players = new ConcurrentHashMap<>();
private static final Map<Integer, Set<BBoundingBox>> playerBoundingBoxesCache = new ConcurrentHashMap<>();
private static final Map<ResourceLocation, Map<BBoundingBox, Set<BBoundingBox>>> dimensionCache = new ConcurrentHashMap<>();
private static final Map<Identifier, Map<BBoundingBox, Set<BBoundingBox>>> dimensionCache = new ConcurrentHashMap<>();
private static boolean initialized = false;
@Contract("_ -> new")
public static ResourceLocation id(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID, path);
public static Identifier id(String path) {
return Identifier.tryBuild(PROTOCOL_ID, path);
}
@ProtocolHandler.Ticker
@@ -86,8 +86,8 @@ public class BBORProtocol implements LeavesProtocol {
ServerLevel overworld = MinecraftServer.getServer().overworld();
ProtocolUtils.sendBytebufPacket(player, INITIALIZE_CLIENT, buf -> {
buf.writeLong(overworld.getSeed());
buf.writeInt(overworld.levelData.getSpawnPos().getX());
buf.writeInt(overworld.levelData.getSpawnPos().getZ());
buf.writeInt(overworld.levelData.getRespawnData().pos().getX());
buf.writeInt(overworld.levelData.getRespawnData().pos().getZ());
});
sendStructureList(player);
}
@@ -114,14 +114,14 @@ public class BBORProtocol implements LeavesProtocol {
final Registry<Structure> structureFeatureRegistry = chunk.getLevel().registryAccess().lookupOrThrow(Registries.STRUCTURE);
for (var es : chunk.getAllStarts().entrySet()) {
final var optional = structureFeatureRegistry.getResourceKey(es.getKey());
optional.ifPresent(key -> structures.put(key.location().toString(), es.getValue()));
optional.ifPresent(key -> structures.put(key.identifier().toString(), es.getValue()));
}
if (!structures.isEmpty()) {
onStructuresLoaded(chunk.getLevel().dimension().location(), structures);
onStructuresLoaded(chunk.getLevel().dimension().identifier(), structures);
}
}
public static void onStructuresLoaded(@NotNull ResourceLocation dimensionID, @NotNull Map<String, StructureStart> structures) {
public static void onStructuresLoaded(@NotNull Identifier dimensionID, @NotNull Map<String, StructureStart> structures) {
Map<BBoundingBox, Set<BBoundingBox>> cache = getOrCreateCache(dimensionID);
for (var entry : structures.entrySet()) {
StructureStart structureStart = entry.getValue();
@@ -155,7 +155,7 @@ public class BBORProtocol implements LeavesProtocol {
private static void sendStructureList(@NotNull ServerPlayer player) {
final Registry<Structure> structureRegistry = MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.STRUCTURE);
final Set<String> structureIds = structureRegistry.entrySet().stream()
.map(e -> e.getKey().location().toString()).collect(Collectors.toSet());
.map(e -> e.getKey().identifier().toString()).collect(Collectors.toSet());
ProtocolUtils.sendBytebufPacket(player, STRUCTURE_LIST_SYNC, buf -> {
buf.writeVarInt(structureIds.size());
structureIds.forEach(buf::writeUtf);
@@ -177,7 +177,7 @@ public class BBORProtocol implements LeavesProtocol {
Set<BBoundingBox> boundingBoxes = boundingBoxMap.get(key);
ProtocolUtils.sendBytebufPacket(player, ADD_BOUNDING_BOX, buf -> {
buf.writeResourceLocation(entry.getKey());
buf.writeIdentifier(entry.getKey());
key.serialize(buf);
if (boundingBoxes != null && boundingBoxes.size() > 1) {
for (BBoundingBox box : boundingBoxes) {
@@ -206,7 +206,7 @@ public class BBORProtocol implements LeavesProtocol {
dimensionCache.clear();
}
private static Map<BBoundingBox, Set<BBoundingBox>> getOrCreateCache(ResourceLocation dimensionId) {
private static Map<BBoundingBox, Set<BBoundingBox>> getOrCreateCache(Identifier dimensionId) {
return dimensionCache.computeIfAbsent(dimensionId, dt -> new ConcurrentHashMap<>());
}
@@ -18,7 +18,7 @@
package org.leavesmc.leaves.protocol;
import fun.bm.lophine.config.modules.function.protocol.XaeroMapProtocolConfig;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -31,17 +31,17 @@ public class XaeroMapProtocol implements LeavesProtocol {
public static final String PROTOCOL_ID_MINI = "xaerominimap";
public static final String PROTOCOL_ID_WORLD = "xaeroworldmap";
private static final ResourceLocation MINIMAP_KEY = idMini("main");
private static final ResourceLocation WORLDMAP_KEY = idWorld("main");
private static final Identifier MINIMAP_KEY = idMini("main");
private static final Identifier WORLDMAP_KEY = idWorld("main");
@Contract("_ -> new")
public static ResourceLocation idMini(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID_MINI, path);
public static Identifier idMini(String path) {
return Identifier.tryBuild(PROTOCOL_ID_MINI, path);
}
@Contract("_ -> new")
public static ResourceLocation idWorld(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID_WORLD, path);
public static Identifier idWorld(String path) {
return Identifier.tryBuild(PROTOCOL_ID_WORLD, path);
}
public static void onSendWorldInfo(@NotNull ServerPlayer player) {
@@ -19,7 +19,7 @@
package org.leavesmc.leaves.protocol.core;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.ElementType;
@@ -29,7 +29,7 @@ import java.lang.annotation.Target;
public interface LeavesCustomPayload extends CustomPacketPayload {
Type<? extends CustomPacketPayload> LEAVES_TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath("leaves", "custom_payload"));
Type<? extends CustomPacketPayload> LEAVES_TYPE = new Type<>(Identifier.fromNamespaceAndPath("leaves", "custom_payload"));
@Override
default @NotNull Type<? extends CustomPacketPayload> type() {
@@ -23,7 +23,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import org.leavesmc.leaves.protocol.core.invoker.*;
import org.slf4j.Logger;
@@ -46,9 +46,9 @@ public class LeavesProtocolManager {
private static final Logger LOGGER = LogUtils.getClassLogger();
private static final Map<Class<? extends LeavesCustomPayload>, PayloadReceiverInvokerHolder> PAYLOAD_RECEIVERS = new HashMap<>();
private static final Map<Class<? extends LeavesCustomPayload>, ResourceLocation> IDS = new HashMap<>();
private static final Map<Class<? extends LeavesCustomPayload>, Identifier> IDS = new HashMap<>();
private static final Map<Class<? extends LeavesCustomPayload>, StreamCodec<? super RegistryFriendlyByteBuf, LeavesCustomPayload>> CODECS = new HashMap<>();
private static final Map<ResourceLocation, StreamCodec<? super RegistryFriendlyByteBuf, LeavesCustomPayload>> ID2CODEC = new HashMap<>();
private static final Map<Identifier, StreamCodec<? super RegistryFriendlyByteBuf, LeavesCustomPayload>> ID2CODEC = new HashMap<>();
private static final Map<String, BytebufReceiverInvokerHolder> STRICT_BYTEBUF_RECEIVERS = new HashMap<>();
private static final Map<String, BytebufReceiverInvokerHolder> NAMESPACED_BYTEBUF_RECEIVERS = new HashMap<>();
@@ -78,8 +78,8 @@ public class LeavesProtocolManager {
}
try {
final LeavesCustomPayload.ID id = field.getAnnotation(LeavesCustomPayload.ID.class);
if (id != null && field.getType().equals(ResourceLocation.class)) {
IDS.put((Class<? extends LeavesCustomPayload>) clazz, (ResourceLocation) field.get(null));
if (id != null && field.getType().equals(Identifier.class)) {
IDS.put((Class<? extends LeavesCustomPayload>) clazz, (Identifier) field.get(null));
}
final LeavesCustomPayload.Codec codec = field.getAnnotation(LeavesCustomPayload.Codec.class);
if (codec != null && field.getType().equals(StreamCodec.class)) {
@@ -208,7 +208,7 @@ public class LeavesProtocolManager {
}
}
public static LeavesCustomPayload decode(ResourceLocation location, FriendlyByteBuf buf) {
public static LeavesCustomPayload decode(Identifier location, FriendlyByteBuf buf) {
var codec = ID2CODEC.get(location);
if (codec == null) {
return null;
@@ -222,7 +222,7 @@ public class LeavesProtocolManager {
if (location == null || codec == null) {
throw new IllegalArgumentException("Payload " + payload.getClass() + " is not configured correctly " + location + " " + codec);
}
buf.writeResourceLocation(location);
buf.writeIdentifier(location);
codec.encode(ProtocolUtils.decorate(buf), payload);
}
@@ -233,7 +233,7 @@ public class LeavesProtocolManager {
}
}
public static boolean handleBytebuf(IdentifierSelector selector, ResourceLocation location, ByteBuf buf) {
public static boolean handleBytebuf(IdentifierSelector selector, Identifier location, ByteBuf buf) {
RegistryFriendlyByteBuf buf1 = ProtocolUtils.decorate(buf);
BytebufReceiverInvokerHolder holder;
if ((holder = STRICT_BYTEBUF_RECEIVERS.get(location.toString())) != null) {
@@ -290,7 +290,7 @@ public class LeavesProtocolManager {
}
public static void handleMinecraftRegister(String channelId, IdentifierSelector selector) {
ResourceLocation location = ResourceLocation.tryParse(channelId);
Identifier location = Identifier.tryParse(channelId);
if (location == null) {
return;
}
@@ -320,7 +320,7 @@ public class LeavesProtocolManager {
set.add(key);
}
});
ProtocolUtils.sendBytebufPacket(player, ResourceLocation.fromNamespaceAndPath("minecraft", "register"), buf -> {
ProtocolUtils.sendBytebufPacket(player, Identifier.fromNamespaceAndPath("minecraft", "register"), buf -> {
for (String channel : set) {
buf.writeBytes(channel.getBytes(StandardCharsets.US_ASCII));
buf.writeByte(0);
@@ -26,7 +26,7 @@ import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
@@ -46,11 +46,11 @@ public class ProtocolUtils {
return protocol + "-lophine-" + ServerBuildInfo.buildInfo().asString(ServerBuildInfo.StringRepresentation.VERSION_SIMPLE);
}
public static void sendEmptyPacket(ServerPlayer player, ResourceLocation id) {
public static void sendEmptyPacket(ServerPlayer player, Identifier id) {
player.connection.send(new ClientboundCustomPayloadPacket(new DiscardedPayload(id, EMPTY)));
}
public static void sendBytebufPacket(@NotNull ServerPlayer player, ResourceLocation id, Consumer<? super RegistryFriendlyByteBuf> consumer) {
public static void sendBytebufPacket(@NotNull ServerPlayer player, Identifier id, Consumer<? super RegistryFriendlyByteBuf> consumer) {
RegistryFriendlyByteBuf buf = decorate(Unpooled.buffer());
consumer.accept(buf);
player.connection.send(new ClientboundCustomPayloadPacket(new DiscardedPayload(id, ByteBufUtil.getBytes(buf))));
@@ -60,11 +60,11 @@ public class ProtocolUtils {
player.connection.send(new ClientboundCustomPayloadPacket(payload));
}
public static void sendEmptyPacket(Context context, ResourceLocation id) {
public static void sendEmptyPacket(Context context, Identifier id) {
context.connection().send(new ClientboundCustomPayloadPacket(new DiscardedPayload(id, EMPTY)));
}
public static void sendBytebufPacket(@NotNull Context context, ResourceLocation id, Consumer<? super RegistryFriendlyByteBuf> consumer) {
public static void sendBytebufPacket(@NotNull Context context, Identifier id, Consumer<? super RegistryFriendlyByteBuf> consumer) {
RegistryFriendlyByteBuf buf = decorate(Unpooled.buffer());
consumer.accept(buf);
context.connection().send(new ClientboundCustomPayloadPacket(new DiscardedPayload(id, ByteBufUtil.getBytes(buf))));
@@ -17,7 +17,7 @@
package org.leavesmc.leaves.protocol.core.invoker;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.leavesmc.leaves.protocol.core.IdentifierSelector;
import org.leavesmc.leaves.protocol.core.LeavesProtocol;
import org.leavesmc.leaves.protocol.core.ProtocolHandler;
@@ -26,10 +26,10 @@ import java.lang.reflect.Method;
public class MinecraftRegisterInvokerHolder extends AbstractInvokerHolder<ProtocolHandler.MinecraftRegister> {
public MinecraftRegisterInvokerHolder(LeavesProtocol owner, Method invoker, ProtocolHandler.MinecraftRegister handler) {
super(owner, invoker, handler, null, handler.stage().identifier(), ResourceLocation.class);
super(owner, invoker, handler, null, handler.stage().identifier(), Identifier.class);
}
public void invoke(IdentifierSelector selector, ResourceLocation id) {
public void invoke(IdentifierSelector selector, Identifier id) {
invoke0(false, selector.select(handler.stage()), id);
}
}
@@ -25,7 +25,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -35,12 +35,12 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Chicken;
import net.minecraft.world.entity.animal.allay.Allay;
import net.minecraft.world.entity.animal.armadillo.Armadillo;
import net.minecraft.world.entity.animal.chicken.Chicken;
import net.minecraft.world.entity.animal.frog.Tadpole;
import net.minecraft.world.entity.animal.sniffer.Sniffer;
import net.minecraft.world.entity.monster.ZombieVillager;
import net.minecraft.world.entity.monster.zombie.ZombieVillager;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
@@ -68,31 +68,31 @@ import java.util.Set;
@LeavesProtocol.Register(namespace = "jade")
public class JadeProtocol implements LeavesProtocol {
private static final Logger LOGGER = LogUtils.getLogger();
public static final Logger LOGGER = LogUtils.getLogger();
public static final String PROTOCOL_ID = "jade";
public static final String PROTOCOL_VERSION = "8";
public static final HierarchyLookup<IServerDataProvider<EntityAccessor>> entityDataProviders = new HierarchyLookup<>(Entity.class);
public static final PairHierarchyLookup<IServerDataProvider<BlockAccessor>> blockDataProviders = new PairHierarchyLookup<>(new HierarchyLookup<>(Block.class), new HierarchyLookup<>(BlockEntity.class));
public static final WrappedHierarchyLookup<IServerExtensionProvider<ItemStack>> itemStorageProviders = WrappedHierarchyLookup.forAccessor();
public static final String PROTOCOL_VERSION = "9";
public static final HierarchyLookup<ServerDataProvider<EntityAccessor>> entityDataProviders = new HierarchyLookup<>(Entity.class);
public static final PairHierarchyLookup<ServerDataProvider<BlockAccessor>> blockDataProviders = new PairHierarchyLookup<>(new HierarchyLookup<>(Block.class), new HierarchyLookup<>(BlockEntity.class));
public static final WrappedHierarchyLookup<ServerExtensionProvider<ItemStack>> itemStorageProviders = WrappedHierarchyLookup.forAccessor();
private static final Set<ServerPlayer> enabledPlayers = new HashSet<>();
public static PriorityStore<ResourceLocation, IJadeProvider> priorities;
public static PriorityStore<Identifier, JadeProvider> priorities;
private static List<Block> shearableBlocks = null;
@Contract("_ -> new")
public static ResourceLocation id(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID, path);
public static Identifier id(String path) {
return Identifier.fromNamespaceAndPath(PROTOCOL_ID, path);
}
@Contract("_ -> new")
public static @NotNull ResourceLocation mc_id(String path) {
return ResourceLocation.withDefaultNamespace(path);
public static @NotNull Identifier mc_id(String path) {
return Identifier.withDefaultNamespace(path);
}
@ProtocolHandler.Init
public static void init() {
priorities = new PriorityStore<>(IJadeProvider::getDefaultPriority, IJadeProvider::getUid);
priorities = new PriorityStore<>(JadeProvider::getDefaultPriority, JadeProvider::getUid);
// core plugin
blockDataProviders.register(BlockEntity.class, BlockNameProvider.INSTANCE);
@@ -178,20 +178,20 @@ public class JadeProtocol implements LeavesProtocol {
return;
}
List<IServerDataProvider<EntityAccessor>> providers = entityDataProviders.get(entity);
List<ServerDataProvider<EntityAccessor>> providers = entityDataProviders.get(entity);
if (providers.isEmpty()) {
return;
}
CompoundTag tag = new CompoundTag();
for (IServerDataProvider<EntityAccessor> provider : providers) {
for (ServerDataProvider<EntityAccessor> provider : providers) {
if (!payload.dataProviders().contains(provider)) {
continue;
}
try {
provider.appendServerData(tag, accessor);
} catch (Exception e) {
LOGGER.warn("Error while saving data for entity " + entity);
LOGGER.warn("Error while saving data for entity {}", entity);
}
}
tag.putInt("EntityId", entity.getId());
@@ -217,7 +217,7 @@ public class JadeProtocol implements LeavesProtocol {
return;
}
List<IServerDataProvider<BlockAccessor>> providers;
List<ServerDataProvider<BlockAccessor>> providers;
if (blockEntity != null) {
providers = blockDataProviders.getMerged(block, blockEntity);
} else {
@@ -229,14 +229,14 @@ public class JadeProtocol implements LeavesProtocol {
}
CompoundTag tag = new CompoundTag();
for (IServerDataProvider<BlockAccessor> provider : providers) {
for (ServerDataProvider<BlockAccessor> provider : providers) {
if (!payload.dataProviders().contains(provider)) {
continue;
}
try {
provider.appendServerData(tag, accessor);
} catch (Exception e) {
LOGGER.warn("Error while saving data for block " + accessor.getBlockState());
LOGGER.warn("Error while saving data for block {}", accessor.getBlockState());
}
}
NbtUtils.writeBlockPosToTag(pos, tag);
@@ -264,7 +264,7 @@ public class JadeProtocol implements LeavesProtocol {
));
} catch (Throwable ignore) {
shearableBlocks = List.of();
LOGGER.warn("Failed to collect shearable blocks");
LOGGER.error("Failed to collect shearable blocks");
}
}
@@ -17,23 +17,61 @@
package org.leavesmc.leaves.protocol.jade.accessor;
import io.netty.buffer.Unpooled;
import net.minecraft.nbt.ByteArrayTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamEncoder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.HitResult;
import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.Nullable;
public interface Accessor<T extends HitResult> {
ServerLevel getLevel();
import java.util.function.Supplier;
Player getPlayer();
public abstract class Accessor<T extends HitResult> {
<D> Tag encodeAsNbt(StreamEncoder<RegistryFriendlyByteBuf, D> codec, D value);
private final ServerLevel level;
private final Player player;
private final Supplier<T> hit;
protected boolean verify;
private RegistryFriendlyByteBuf buffer;
T getHitResult();
public Accessor(ServerLevel level, Player player, Supplier<T> hit) {
this.level = level;
this.player = player;
this.hit = hit;
}
public ServerLevel getLevel() {
return level;
}
public Player getPlayer() {
return player;
}
private RegistryFriendlyByteBuf buffer() {
if (buffer == null) {
buffer = new RegistryFriendlyByteBuf(Unpooled.buffer(), level.registryAccess());
}
buffer.clear();
return buffer;
}
public <D> Tag encodeAsNbt(StreamEncoder<RegistryFriendlyByteBuf, D> streamCodec, D value) {
RegistryFriendlyByteBuf buffer = buffer();
streamCodec.encode(buffer, value);
ByteArrayTag tag = new ByteArrayTag(ArrayUtils.subarray(buffer.array(), 0, buffer.readableBytes()));
buffer.clear();
return tag;
}
public T getHitResult() {
return hit.get();
}
@Nullable
Object getTarget();
public abstract Object getTarget();
}
@@ -1,77 +0,0 @@
/*
* This file is part of Leaves (https://github.com/LeavesMC/Leaves)
*
* Leaves is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Leaves is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Leaves. If not, see <https://www.gnu.org/licenses/>.
*/
package org.leavesmc.leaves.protocol.jade.accessor;
import io.netty.buffer.Unpooled;
import net.minecraft.nbt.ByteArrayTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamEncoder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.HitResult;
import org.apache.commons.lang3.ArrayUtils;
import java.util.function.Supplier;
public abstract class AccessorImpl<T extends HitResult> implements Accessor<T> {
private final ServerLevel level;
private final Player player;
private final Supplier<T> hit;
protected boolean verify;
private RegistryFriendlyByteBuf buffer;
public AccessorImpl(ServerLevel level, Player player, Supplier<T> hit) {
this.level = level;
this.player = player;
this.hit = hit;
}
@Override
public ServerLevel getLevel() {
return level;
}
@Override
public Player getPlayer() {
return player;
}
private RegistryFriendlyByteBuf buffer() {
if (buffer == null) {
buffer = new RegistryFriendlyByteBuf(Unpooled.buffer(), level.registryAccess());
}
buffer.clear();
return buffer;
}
@Override
public <D> Tag encodeAsNbt(StreamEncoder<RegistryFriendlyByteBuf, D> streamCodec, D value) {
RegistryFriendlyByteBuf buffer = buffer();
streamCodec.encode(buffer, value);
ByteArrayTag tag = new ByteArrayTag(ArrayUtils.subarray(buffer.array(), 0, buffer.readableBytes()));
buffer.clear();
return tag;
}
@Override
public T getHitResult() {
return hit.get();
}
}
@@ -17,45 +17,135 @@
package org.leavesmc.leaves.protocol.jade.accessor;
import com.google.common.base.Suppliers;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier;
public interface BlockAccessor extends Accessor<BlockHitResult> {
/**
* Class to get information of block target and context.
*/
public class BlockAccessor extends Accessor<BlockHitResult> {
Block getBlock();
private final BlockState blockState;
@Nullable
private final Supplier<BlockEntity> blockEntity;
BlockState getBlockState();
private BlockAccessor(Builder builder) {
super(builder.level, builder.player, Suppliers.ofInstance(builder.hit));
blockState = builder.blockState;
blockEntity = builder.blockEntity;
}
BlockEntity getBlockEntity();
public Block getBlock() {
return getBlockState().getBlock();
}
BlockPos getPosition();
public BlockState getBlockState() {
return blockState;
}
@ApiStatus.NonExtendable
interface Builder {
Builder level(ServerLevel level);
public BlockEntity getBlockEntity() {
return blockEntity == null ? null : blockEntity.get();
}
Builder player(Player player);
public BlockPos getPosition() {
return getHitResult().getBlockPos();
}
Builder hit(BlockHitResult hit);
@Nullable
@Override
public Object getTarget() {
return getBlockEntity();
}
Builder blockState(BlockState state);
public static class Builder {
private ServerLevel level;
private Player player;
private BlockHitResult hit;
private BlockState blockState = Blocks.AIR.defaultBlockState();
private Supplier<BlockEntity> blockEntity;
default Builder blockEntity(BlockEntity blockEntity) {
return blockEntity(() -> blockEntity);
public Builder level(ServerLevel level) {
this.level = level;
return this;
}
Builder blockEntity(Supplier<BlockEntity> blockEntity);
public Builder player(Player player) {
this.player = player;
return this;
}
Builder from(BlockAccessor accessor);
public Builder hit(BlockHitResult hit) {
this.hit = hit;
return this;
}
BlockAccessor build();
public Builder blockState(BlockState blockState) {
this.blockState = blockState;
return this;
}
public Builder blockEntity(Supplier<BlockEntity> blockEntity) {
this.blockEntity = blockEntity;
return this;
}
public Builder from(BlockAccessor accessor) {
level = accessor.getLevel();
player = accessor.getPlayer();
hit = accessor.getHitResult();
blockEntity = accessor::getBlockEntity;
blockState = accessor.getBlockState();
return this;
}
public BlockAccessor build() {
return new BlockAccessor(this);
}
}
public record SyncData(boolean showDetails, BlockHitResult hit, ItemStack serversideRep, CompoundTag data) {
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL,
SyncData::showDetails,
StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult),
SyncData::hit,
ItemStack.OPTIONAL_STREAM_CODEC,
SyncData::serversideRep,
ByteBufCodecs.COMPOUND_TAG,
SyncData::data,
SyncData::new
);
public BlockAccessor unpack(ServerPlayer player) {
Supplier<BlockEntity> blockEntity = null;
BlockState blockState = player.level().getBlockState(hit.getBlockPos());
if (blockState.hasBlockEntity()) {
blockEntity = Suppliers.memoize(() -> player.level().getBlockEntity(hit.getBlockPos()));
}
return new Builder()
.level(player.level())
.player(player)
.hit(hit)
.blockState(blockState)
.blockEntity(blockEntity)
.build();
}
}
}
@@ -1,160 +0,0 @@
/*
* This file is part of Leaves (https://github.com/LeavesMC/Leaves)
*
* Leaves is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Leaves is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Leaves. If not, see <https://www.gnu.org/licenses/>.
*/
package org.leavesmc.leaves.protocol.jade.accessor;
import com.google.common.base.Suppliers;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier;
/**
* Class to get information of block target and context.
*/
public class BlockAccessorImpl extends AccessorImpl<BlockHitResult> implements BlockAccessor {
private final BlockState blockState;
@Nullable
private final Supplier<BlockEntity> blockEntity;
private BlockAccessorImpl(Builder builder) {
super(builder.level, builder.player, Suppliers.ofInstance(builder.hit));
blockState = builder.blockState;
blockEntity = builder.blockEntity;
}
@Override
public Block getBlock() {
return getBlockState().getBlock();
}
@Override
public BlockState getBlockState() {
return blockState;
}
@Override
public BlockEntity getBlockEntity() {
return blockEntity == null ? null : blockEntity.get();
}
@Override
public BlockPos getPosition() {
return getHitResult().getBlockPos();
}
@Nullable
@Override
public Object getTarget() {
return getBlockEntity();
}
public static class Builder implements BlockAccessor.Builder {
private ServerLevel level;
private Player player;
private BlockHitResult hit;
private BlockState blockState = Blocks.AIR.defaultBlockState();
private Supplier<BlockEntity> blockEntity;
@Override
public Builder level(ServerLevel level) {
this.level = level;
return this;
}
@Override
public Builder player(Player player) {
this.player = player;
return this;
}
@Override
public Builder hit(BlockHitResult hit) {
this.hit = hit;
return this;
}
@Override
public Builder blockState(BlockState blockState) {
this.blockState = blockState;
return this;
}
@Override
public Builder blockEntity(Supplier<BlockEntity> blockEntity) {
this.blockEntity = blockEntity;
return this;
}
@Override
public Builder from(BlockAccessor accessor) {
level = accessor.getLevel();
player = accessor.getPlayer();
hit = accessor.getHitResult();
blockEntity = accessor::getBlockEntity;
blockState = accessor.getBlockState();
return this;
}
@Override
public BlockAccessor build() {
return new BlockAccessorImpl(this);
}
}
public record SyncData(boolean showDetails, BlockHitResult hit, BlockState blockState, ItemStack fakeBlock) {
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL,
SyncData::showDetails,
StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult),
SyncData::hit,
ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY),
SyncData::blockState,
ItemStack.OPTIONAL_STREAM_CODEC,
SyncData::fakeBlock,
SyncData::new
);
public BlockAccessor unpack(ServerPlayer player) {
Supplier<BlockEntity> blockEntity = null;
if (blockState.hasBlockEntity()) {
blockEntity = Suppliers.memoize(() -> player.level().getBlockEntity(hit.getBlockPos()));
}
return new Builder()
.level(player.level())
.player(player)
.hit(hit)
.blockState(blockState)
.blockEntity(blockEntity)
.build();
}
}
}
@@ -17,43 +17,107 @@
package org.leavesmc.leaves.protocol.jade.accessor;
import com.google.common.base.Suppliers;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.EntityHitResult;
import org.jetbrains.annotations.ApiStatus;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.util.CommonUtil;
import java.util.function.Supplier;
public interface EntityAccessor extends Accessor<EntityHitResult> {
public class EntityAccessor extends Accessor<EntityHitResult> {
Entity getEntity();
private final Supplier<Entity> entity;
/**
* For part entity like ender dragon's, getEntity() will return the parent entity.
*/
Entity getRawEntity();
public EntityAccessor(Builder builder) {
super(builder.level, builder.player, builder.hit);
entity = builder.entity;
}
@ApiStatus.NonExtendable
interface Builder {
Builder level(ServerLevel level);
public Entity getEntity() {
return CommonUtil.wrapPartEntityParent(getRawEntity());
}
Builder player(Player player);
public Entity getRawEntity() {
return entity.get();
}
default Builder hit(EntityHitResult hit) {
return hit(() -> hit);
@NotNull
@Override
public Object getTarget() {
return getEntity();
}
public static class Builder {
private ServerLevel level;
private Player player;
private Supplier<EntityHitResult> hit;
private Supplier<Entity> entity;
public Builder level(ServerLevel level) {
this.level = level;
return this;
}
Builder hit(Supplier<EntityHitResult> hit);
default Builder entity(Entity entity) {
return entity(() -> entity);
public Builder player(Player player) {
this.player = player;
return this;
}
Builder entity(Supplier<Entity> entity);
public Builder hit(Supplier<EntityHitResult> hit) {
this.hit = hit;
return this;
}
Builder from(EntityAccessor accessor);
public Builder entity(Supplier<Entity> entity) {
this.entity = entity;
return this;
}
EntityAccessor build();
public Builder from(EntityAccessor accessor) {
level = accessor.getLevel();
player = accessor.getPlayer();
hit = accessor::getHitResult;
entity = accessor::getEntity;
return this;
}
public EntityAccessor build() {
return new EntityAccessor(this);
}
}
public record SyncData(boolean showDetails, int id, int partIndex, Vec3 hitVec, CompoundTag data) {
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL,
SyncData::showDetails,
ByteBufCodecs.VAR_INT,
SyncData::id,
ByteBufCodecs.VAR_INT,
SyncData::partIndex,
ByteBufCodecs.VECTOR3F.map(Vec3::new, Vec3::toVector3f),
SyncData::hitVec,
ByteBufCodecs.COMPOUND_TAG,
SyncData::data,
SyncData::new
);
public EntityAccessor unpack(ServerPlayer player) {
Supplier<Entity> entity = Suppliers.memoize(() -> CommonUtil.getPartEntity(player.level().getEntity(id), partIndex));
return new Builder()
.level(player.level())
.player(player)
.entity(entity)
.hit(Suppliers.memoize(() -> new EntityHitResult(entity.get(), hitVec)))
.build();
}
}
}
@@ -1,129 +0,0 @@
/*
* This file is part of Leaves (https://github.com/LeavesMC/Leaves)
*
* Leaves is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Leaves is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Leaves. If not, see <https://www.gnu.org/licenses/>.
*/
package org.leavesmc.leaves.protocol.jade.accessor;
import com.google.common.base.Suppliers;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.util.CommonUtil;
import java.util.function.Supplier;
public class EntityAccessorImpl extends AccessorImpl<EntityHitResult> implements EntityAccessor {
private final Supplier<Entity> entity;
public EntityAccessorImpl(Builder builder) {
super(builder.level, builder.player, builder.hit);
entity = builder.entity;
}
@Override
public Entity getEntity() {
return CommonUtil.wrapPartEntityParent(getRawEntity());
}
@Override
public Entity getRawEntity() {
return entity.get();
}
@NotNull
@Override
public Object getTarget() {
return getEntity();
}
public static class Builder implements EntityAccessor.Builder {
private ServerLevel level;
private Player player;
private Supplier<EntityHitResult> hit;
private Supplier<Entity> entity;
@Override
public Builder level(ServerLevel level) {
this.level = level;
return this;
}
@Override
public Builder player(Player player) {
this.player = player;
return this;
}
@Override
public Builder hit(Supplier<EntityHitResult> hit) {
this.hit = hit;
return this;
}
@Override
public Builder entity(Supplier<Entity> entity) {
this.entity = entity;
return this;
}
@Override
public Builder from(EntityAccessor accessor) {
level = accessor.getLevel();
player = accessor.getPlayer();
hit = accessor::getHitResult;
entity = accessor::getEntity;
return this;
}
@Override
public EntityAccessor build() {
return new EntityAccessorImpl(this);
}
}
public record SyncData(boolean showDetails, int id, int partIndex, Vec3 hitVec) {
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL,
SyncData::showDetails,
ByteBufCodecs.VAR_INT,
SyncData::id,
ByteBufCodecs.VAR_INT,
SyncData::partIndex,
ByteBufCodecs.VECTOR3F.map(Vec3::new, Vec3::toVector3f),
SyncData::hitVec,
SyncData::new
);
public EntityAccessor unpack(ServerPlayer player) {
Supplier<Entity> entity = Suppliers.memoize(() -> CommonUtil.getPartEntity(player.level().getEntity(id), partIndex));
return new EntityAccessorImpl.Builder()
.level(player.level())
.player(player)
.entity(entity)
.hit(Suppliers.memoize(() -> new EntityHitResult(entity.get(), hitVec)))
.build();
}
}
}
@@ -20,14 +20,14 @@ package org.leavesmc.leaves.protocol.jade.payload;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
public record ClientHandshakePayload(String protocolVersion) implements LeavesCustomPayload {
@ID
private static final ResourceLocation PACKET_CLIENT_HANDSHAKE = JadeProtocol.id("client_handshake");
private static final Identifier PACKET_CLIENT_HANDSHAKE = JadeProtocol.id("client_handshake");
@Codec
private static final StreamCodec<RegistryFriendlyByteBuf, ClientHandshakePayload> CODEC = StreamCodec.composite(
@@ -21,14 +21,14 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
public record ReceiveDataPayload(CompoundTag tag) implements LeavesCustomPayload {
@ID
private static final ResourceLocation PACKET_RECEIVE_DATA = JadeProtocol.id("receive_data");
private static final Identifier PACKET_RECEIVE_DATA = JadeProtocol.id("receive_data");
@Codec
private static final StreamCodec<FriendlyByteBuf, ReceiveDataPayload> CODEC = StreamCodec.composite(
@@ -21,30 +21,29 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.BlockAccessor;
import org.leavesmc.leaves.protocol.jade.accessor.BlockAccessorImpl;
import org.leavesmc.leaves.protocol.jade.provider.IServerDataProvider;
import org.leavesmc.leaves.protocol.jade.provider.ServerDataProvider;
import java.util.List;
import java.util.Objects;
import static org.leavesmc.leaves.protocol.jade.JadeProtocol.blockDataProviders;
public record RequestBlockPayload(BlockAccessorImpl.SyncData data,
List<@Nullable IServerDataProvider<BlockAccessor>> dataProviders) implements LeavesCustomPayload {
public record RequestBlockPayload(BlockAccessor.SyncData data,
List<@Nullable ServerDataProvider<BlockAccessor>> dataProviders) implements LeavesCustomPayload {
@ID
private static final ResourceLocation PACKET_REQUEST_BLOCK = JadeProtocol.id("request_block");
private static final Identifier PACKET_REQUEST_BLOCK = JadeProtocol.id("request_block");
@Codec
private static final StreamCodec<RegistryFriendlyByteBuf, RequestBlockPayload> CODEC = StreamCodec.composite(
BlockAccessorImpl.SyncData.STREAM_CODEC,
BlockAccessor.SyncData.STREAM_CODEC,
RequestBlockPayload::data,
ByteBufCodecs.<ByteBuf, IServerDataProvider<BlockAccessor>>list()
ByteBufCodecs.<ByteBuf, ServerDataProvider<BlockAccessor>>list()
.apply(ByteBufCodecs.idMapper(
$ -> Objects.requireNonNull(blockDataProviders.idMapper()).byId($),
$ -> Objects.requireNonNull(blockDataProviders.idMapper()).getIdOrThrow($))),
@@ -21,30 +21,29 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.EntityAccessor;
import org.leavesmc.leaves.protocol.jade.accessor.EntityAccessorImpl;
import org.leavesmc.leaves.protocol.jade.provider.IServerDataProvider;
import org.leavesmc.leaves.protocol.jade.provider.ServerDataProvider;
import java.util.List;
import java.util.Objects;
import static org.leavesmc.leaves.protocol.jade.JadeProtocol.entityDataProviders;
public record RequestEntityPayload(EntityAccessorImpl.SyncData data,
List<@Nullable IServerDataProvider<EntityAccessor>> dataProviders) implements LeavesCustomPayload {
public record RequestEntityPayload(EntityAccessor.SyncData data,
List<@Nullable ServerDataProvider<EntityAccessor>> dataProviders) implements LeavesCustomPayload {
@ID
private static final ResourceLocation PACKET_REQUEST_ENTITY = JadeProtocol.id("request_entity");
private static final Identifier PACKET_REQUEST_ENTITY = JadeProtocol.id("request_entity");
@Codec
private static final StreamCodec<RegistryFriendlyByteBuf, RequestEntityPayload> CODEC = StreamCodec.composite(
EntityAccessorImpl.SyncData.STREAM_CODEC,
EntityAccessor.SyncData.STREAM_CODEC,
RequestEntityPayload::data,
ByteBufCodecs.<ByteBuf, IServerDataProvider<EntityAccessor>>list()
ByteBufCodecs.<ByteBuf, ServerDataProvider<EntityAccessor>>list()
.apply(ByteBufCodecs.idMapper(
$ -> Objects.requireNonNull(entityDataProviders.idMapper()).byId($),
$ -> Objects.requireNonNull(entityDataProviders.idMapper()).getIdOrThrow($)
@@ -24,7 +24,7 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.Block;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
@@ -35,24 +35,24 @@ import java.util.Map;
import static org.leavesmc.leaves.protocol.jade.util.JadeCodec.PRIMITIVE_STREAM_CODEC;
public record ServerHandshakePayload(
Map<ResourceLocation, Object> serverConfig,
Map<Identifier, Object> serverConfig,
List<Block> shearableBlocks,
List<ResourceLocation> blockProviderIds,
List<ResourceLocation> entityProviderIds
List<Identifier> blockProviderIds,
List<Identifier> entityProviderIds
) implements LeavesCustomPayload {
@ID
private static final ResourceLocation PACKET_SERVER_HANDSHAKE = JadeProtocol.id("server_handshake");
private static final Identifier PACKET_SERVER_HANDSHAKE = JadeProtocol.id("server_handshake");
@Codec
private static final StreamCodec<RegistryFriendlyByteBuf, ServerHandshakePayload> CODEC = StreamCodec.composite(
ByteBufCodecs.map(Maps::newHashMapWithExpectedSize, ResourceLocation.STREAM_CODEC, PRIMITIVE_STREAM_CODEC),
ByteBufCodecs.map(Maps::newHashMapWithExpectedSize, Identifier.STREAM_CODEC, PRIMITIVE_STREAM_CODEC),
ServerHandshakePayload::serverConfig,
ByteBufCodecs.registry(Registries.BLOCK).apply(ByteBufCodecs.list()),
ServerHandshakePayload::shearableBlocks,
ByteBufCodecs.<ByteBuf, ResourceLocation>list().apply(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.<ByteBuf, Identifier>list().apply(Identifier.STREAM_CODEC),
ServerHandshakePayload::blockProviderIds,
ByteBufCodecs.<ByteBuf, ResourceLocation>list().apply(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.<ByteBuf, Identifier>list().apply(Identifier.STREAM_CODEC),
ServerHandshakePayload::entityProviderIds,
ServerHandshakePayload::new
);
@@ -19,13 +19,12 @@ package org.leavesmc.leaves.protocol.jade.provider;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.mojang.logging.LogUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.Container;
import net.minecraft.world.LockCode;
import net.minecraft.world.RandomizableContainer;
import net.minecraft.world.WorldlyContainerHolder;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.animal.equine.AbstractHorse;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.vehicle.ContainerEntity;
import net.minecraft.world.inventory.PlayerEnderChestContainer;
@@ -42,20 +41,17 @@ import org.leavesmc.leaves.protocol.jade.accessor.BlockAccessor;
import org.leavesmc.leaves.protocol.jade.util.ItemCollector;
import org.leavesmc.leaves.protocol.jade.util.ItemIterator;
import org.leavesmc.leaves.protocol.jade.util.ViewGroup;
import org.slf4j.Logger;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public enum ItemStorageExtensionProvider implements IServerExtensionProvider<ItemStack> {
public enum ItemStorageExtensionProvider implements ServerExtensionProvider<ItemStack> {
INSTANCE;
public static final Cache<Object, ItemCollector<?>> targetCache = CacheBuilder.newBuilder().weakKeys().expireAfterAccess(60, TimeUnit.SECONDS).build();
private static final ResourceLocation UNIVERSAL_ITEM_STORAGE = JadeProtocol.mc_id("item_storage.default");
private static final Logger LOGGER = LogUtils.getLogger();
private static final Identifier UNIVERSAL_ITEM_STORAGE = JadeProtocol.mc_id("item_storage.default");
public static ItemCollector<?> createItemCollector(Accessor<?> request) {
if (request.getTarget() instanceof AbstractHorse) {
@@ -146,7 +142,7 @@ public enum ItemStorageExtensionProvider implements IServerExtensionProvider<Ite
try {
itemCollector = targetCache.get(target, () -> createItemCollector(request));
} catch (ExecutionException e) {
LOGGER.warn("Failed to get item collector for " + target);
JadeProtocol.LOGGER.error("Failed to get item collector for {}", target);
return null;
}
@@ -154,7 +150,7 @@ public enum ItemStorageExtensionProvider implements IServerExtensionProvider<Ite
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return UNIVERSAL_ITEM_STORAGE;
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.LockCode;
import net.minecraft.world.RandomizableContainer;
import net.minecraft.world.entity.player.Player;
@@ -39,11 +39,11 @@ import org.leavesmc.leaves.protocol.jade.util.ViewGroup;
import java.util.List;
import java.util.Map;
public abstract class ItemStorageProvider<T extends Accessor<?>> implements IServerDataProvider<T> {
public abstract class ItemStorageProvider<T extends Accessor<?>> implements ServerDataProvider<T> {
private static final StreamCodec<RegistryFriendlyByteBuf, Map.Entry<ResourceLocation, List<ViewGroup<ItemStack>>>> STREAM_CODEC = ViewGroup.listCodec(ItemStack.OPTIONAL_STREAM_CODEC);
private static final StreamCodec<RegistryFriendlyByteBuf, Map.Entry<Identifier, List<ViewGroup<ItemStack>>>> STREAM_CODEC = ViewGroup.listCodec(ItemStack.OPTIONAL_STREAM_CODEC);
private static final ResourceLocation UNIVERSAL_ITEM_STORAGE = JadeProtocol.mc_id("item_storage");
private static final Identifier UNIVERSAL_ITEM_STORAGE = JadeProtocol.mc_id("item_storage");
public static ForBlock getBlock() {
return ForBlock.INSTANCE;
@@ -56,7 +56,7 @@ public abstract class ItemStorageProvider<T extends Accessor<?>> implements ISer
public static void putData(CompoundTag tag, @NotNull Accessor<?> accessor) {
Object target = accessor.getTarget();
Player player = accessor.getPlayer();
Map.Entry<ResourceLocation, List<ViewGroup<ItemStack>>> entry = CommonUtil.getServerExtensionData(accessor, JadeProtocol.itemStorageProviders);
Map.Entry<Identifier, List<ViewGroup<ItemStack>>> entry = CommonUtil.getServerExtensionData(accessor, JadeProtocol.itemStorageProviders);
if (entry != null) {
List<ViewGroup<ItemStack>> groups = entry.getValue();
for (ViewGroup<ItemStack> group : groups) {
@@ -77,7 +77,7 @@ public abstract class ItemStorageProvider<T extends Accessor<?>> implements ISer
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return UNIVERSAL_ITEM_STORAGE;
}
@@ -17,11 +17,11 @@
package org.leavesmc.leaves.protocol.jade.provider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
public interface IJadeProvider {
public interface JadeProvider {
ResourceLocation getUid();
Identifier getUid();
default int getDefaultPriority() {
return 0;
@@ -20,6 +20,6 @@ package org.leavesmc.leaves.protocol.jade.provider;
import net.minecraft.nbt.CompoundTag;
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
public interface IServerDataProvider<T extends Accessor<?>> extends IJadeProvider {
public interface ServerDataProvider<T extends Accessor<?>> extends JadeProvider {
void appendServerData(CompoundTag data, T accessor);
}
@@ -22,6 +22,6 @@ import org.leavesmc.leaves.protocol.jade.util.ViewGroup;
import java.util.List;
public interface IServerExtensionProvider<T> extends IJadeProvider {
public interface ServerExtensionProvider<T> extends JadeProvider {
List<ViewGroup<T>> getGroups(Accessor<?> request);
}
@@ -23,7 +23,7 @@ import net.minecraft.network.codec.StreamCodec;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
public interface StreamServerDataProvider<T extends Accessor<?>, D> extends IServerDataProvider<T> {
public interface StreamServerDataProvider<T extends Accessor<?>, D> extends ServerDataProvider<T> {
@Override
default void appendServerData(CompoundTag data, T accessor) {
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
@@ -30,7 +30,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum BeehiveProvider implements StreamServerDataProvider<BlockAccessor, Byte> {
INSTANCE;
private static final ResourceLocation MC_BEEHIVE = JadeProtocol.mc_id("beehive");
private static final Identifier MC_BEEHIVE = JadeProtocol.mc_id("beehive");
@Override
public @NotNull StreamCodec<RegistryFriendlyByteBuf, Byte> streamCodec() {
@@ -45,7 +45,7 @@ public enum BeehiveProvider implements StreamServerDataProvider<BlockAccessor, B
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_BEEHIVE;
}
}
@@ -23,7 +23,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.Nameable;
import net.minecraft.world.level.block.ChestBlock;
@@ -38,7 +38,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum BlockNameProvider implements StreamServerDataProvider<BlockAccessor, Component> {
INSTANCE;
private static final ResourceLocation CORE_OBJECT_NAME = JadeProtocol.id("object_name");
private static final Identifier CORE_OBJECT_NAME = JadeProtocol.id("object_name");
@Override
@Nullable
@@ -66,7 +66,7 @@ public enum BlockNameProvider implements StreamServerDataProvider<BlockAccessor,
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return CORE_OBJECT_NAME;
}
@@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
@@ -31,7 +31,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum BrewingStandProvider implements StreamServerDataProvider<BlockAccessor, BrewingStandProvider.Data> {
INSTANCE;
private static final ResourceLocation MC_BREWING_STAND = JadeProtocol.mc_id("brewing_stand");
private static final Identifier MC_BREWING_STAND = JadeProtocol.mc_id("brewing_stand");
@Override
public @NotNull Data streamData(@NotNull BlockAccessor accessor) {
@@ -45,7 +45,7 @@ public enum BrewingStandProvider implements StreamServerDataProvider<BlockAccess
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_BREWING_STAND;
}
@@ -18,11 +18,8 @@
package org.leavesmc.leaves.protocol.jade.provider.block;
import com.google.common.collect.Lists;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.NbtOps;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
@@ -31,16 +28,15 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
import org.leavesmc.leaves.protocol.jade.provider.IServerExtensionProvider;
import org.leavesmc.leaves.protocol.jade.provider.ServerExtensionProvider;
import org.leavesmc.leaves.protocol.jade.util.ViewGroup;
import java.util.List;
public enum CampfireProvider implements IServerExtensionProvider<ItemStack> {
public enum CampfireProvider implements ServerExtensionProvider<ItemStack> {
INSTANCE;
private static final MapCodec<Integer> COOKING_TIME_CODEC = Codec.INT.fieldOf("jade:cooking");
private static final ResourceLocation MC_CAMPFIRE = JadeProtocol.mc_id("campfire");
private static final Identifier MC_CAMPFIRE = JadeProtocol.mc_id("campfire");
@Override
public @Nullable @Unmodifiable List<ViewGroup<ItemStack>> getGroups(@NotNull Accessor<?> request) {
@@ -53,9 +49,8 @@ public enum CampfireProvider implements IServerExtensionProvider<ItemStack> {
}
stack = stack.copy();
CustomData customData = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
.update(NbtOps.INSTANCE, COOKING_TIME_CODEC, campfire.cookingTime[i] - campfire.cookingProgress[i])
.getOrThrow();
int time = campfire.cookingTime[i] - campfire.cookingProgress[i];
CustomData customData = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).update(tag -> tag.putInt("jade:cooking", time));
stack.set(DataComponents.CUSTOM_DATA, customData);
list.add(stack);
@@ -66,7 +61,7 @@ public enum CampfireProvider implements IServerExtensionProvider<ItemStack> {
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_CAMPFIRE;
}
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.ChiseledBookShelfBlock;
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
@@ -30,14 +30,16 @@ import org.leavesmc.leaves.protocol.jade.accessor.BlockAccessor;
import org.leavesmc.leaves.protocol.jade.provider.ItemStorageProvider;
import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
import static net.minecraft.world.level.block.CampfireBlock.FACING;
public enum ChiseledBookshelfProvider implements StreamServerDataProvider<BlockAccessor, ItemStack> {
INSTANCE;
private static final ResourceLocation MC_CHISELED_BOOKSHELF = JadeProtocol.mc_id("chiseled_bookshelf");
private static final Identifier MC_CHISELED_BOOKSHELF = JadeProtocol.mc_id("shelf");
@Override
public @Nullable ItemStack streamData(@NotNull BlockAccessor accessor) {
int slot = ((ChiseledBookShelfBlock) accessor.getBlock()).getHitSlot(accessor.getHitResult(), accessor.getBlockState()).orElse(-1);
int slot = ((ChiseledBookShelfBlock) accessor.getBlock()).getHitSlot(accessor.getHitResult(), accessor.getBlockState().getValue(FACING)).orElse(-1);
if (slot == -1) {
return null;
}
@@ -50,7 +52,7 @@ public enum ChiseledBookshelfProvider implements StreamServerDataProvider<BlockA
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_CHISELED_BOOKSHELF;
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.entity.CommandBlockEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -31,7 +31,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum CommandBlockProvider implements StreamServerDataProvider<BlockAccessor, String> {
INSTANCE;
private static final ResourceLocation MC_COMMAND_BLOCK = JadeProtocol.mc_id("command_block");
private static final Identifier MC_COMMAND_BLOCK = JadeProtocol.mc_id("command_block");
@Nullable
public String streamData(@NotNull BlockAccessor accessor) {
@@ -51,7 +51,7 @@ public enum CommandBlockProvider implements StreamServerDataProvider<BlockAccess
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_COMMAND_BLOCK;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +33,7 @@ import java.util.List;
public enum FurnaceProvider implements StreamServerDataProvider<BlockAccessor, FurnaceProvider.Data> {
INSTANCE;
private static final ResourceLocation MC_FURNACE = JadeProtocol.mc_id("furnace");
private static final Identifier MC_FURNACE = JadeProtocol.mc_id("furnace");
@Override
public @NotNull Data streamData(@NotNull BlockAccessor accessor) {
@@ -51,7 +51,7 @@ public enum FurnaceProvider implements StreamServerDataProvider<BlockAccessor, F
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_FURNACE;
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
@@ -30,7 +30,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum HopperLockProvider implements StreamServerDataProvider<BlockAccessor, Boolean> {
INSTANCE;
private static final ResourceLocation MC_HOPPER_LOCK = JadeProtocol.mc_id("hopper_lock");
private static final Identifier MC_HOPPER_LOCK = JadeProtocol.mc_id("hopper_lock");
@Override
public Boolean streamData(@NotNull BlockAccessor accessor) {
@@ -43,7 +43,7 @@ public enum HopperLockProvider implements StreamServerDataProvider<BlockAccessor
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_HOPPER_LOCK;
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
import org.jetbrains.annotations.NotNull;
@@ -30,7 +30,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum JukeboxProvider implements StreamServerDataProvider<BlockAccessor, ItemStack> {
INSTANCE;
private static final ResourceLocation MC_JUKEBOX = JadeProtocol.mc_id("jukebox");
private static final Identifier MC_JUKEBOX = JadeProtocol.mc_id("jukebox");
@Override
public @NotNull ItemStack streamData(BlockAccessor accessor) {
@@ -43,7 +43,7 @@ public enum JukeboxProvider implements StreamServerDataProvider<BlockAccessor, I
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_JUKEBOX;
}
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.LecternBlockEntity;
import org.jetbrains.annotations.NotNull;
@@ -30,7 +30,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum LecternProvider implements StreamServerDataProvider<BlockAccessor, ItemStack> {
INSTANCE;
private static final ResourceLocation MC_LECTERN = JadeProtocol.mc_id("lectern");
private static final Identifier MC_LECTERN = JadeProtocol.mc_id("lectern");
@Override
public @NotNull ItemStack streamData(@NotNull BlockAccessor accessor) {
@@ -44,7 +44,7 @@ public enum LecternProvider implements StreamServerDataProvider<BlockAccessor, I
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_LECTERN;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerStateData;
@@ -33,7 +33,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum MobSpawnerCooldownProvider implements StreamServerDataProvider<BlockAccessor, Integer> {
INSTANCE;
private static final ResourceLocation MC_MOB_SPAWNER_COOLDOWN = JadeProtocol.mc_id("mob_spawner.cooldown");
private static final Identifier MC_MOB_SPAWNER_COOLDOWN = JadeProtocol.mc_id("mob_spawner.cooldown");
@Override
public @Nullable Integer streamData(@NotNull BlockAccessor accessor) {
@@ -53,7 +53,7 @@ public enum MobSpawnerCooldownProvider implements StreamServerDataProvider<Block
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_MOB_SPAWNER_COOLDOWN;
}
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.jade.provider.block;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.CalibratedSculkSensorBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity;
@@ -27,12 +27,12 @@ import net.minecraft.world.level.block.entity.ComparatorBlockEntity;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.BlockAccessor;
import org.leavesmc.leaves.protocol.jade.provider.IServerDataProvider;
import org.leavesmc.leaves.protocol.jade.provider.ServerDataProvider;
public enum RedstoneProvider implements IServerDataProvider<BlockAccessor> {
public enum RedstoneProvider implements ServerDataProvider<BlockAccessor> {
INSTANCE;
private static final ResourceLocation MC_REDSTONE = JadeProtocol.mc_id("redstone");
private static final Identifier MC_REDSTONE = JadeProtocol.mc_id("redstone");
@Override
public void appendServerData(CompoundTag data, @NotNull BlockAccessor accessor) {
@@ -47,7 +47,7 @@ public enum RedstoneProvider implements IServerDataProvider<BlockAccessor> {
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_REDSTONE;
}
}
@@ -17,26 +17,31 @@
package org.leavesmc.leaves.protocol.jade.provider.entity;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.Services;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.players.NameAndId;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityReference;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.OwnableEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.EntityAccessor;
import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
import org.leavesmc.leaves.protocol.jade.util.CommonUtil;
import java.util.UUID;
public enum AnimalOwnerProvider implements StreamServerDataProvider<EntityAccessor, String> {
public enum AnimalOwnerProvider implements StreamServerDataProvider<EntityAccessor, Component> {
INSTANCE;
private static final ResourceLocation MC_ANIMAL_OWNER = JadeProtocol.mc_id("animal_owner");
private static final Identifier MC_ANIMAL_OWNER = JadeProtocol.mc_id("animal_owner");
public static UUID getOwnerUUID(Entity entity) {
if (entity instanceof OwnableEntity ownableEntity) {
@@ -49,17 +54,37 @@ public enum AnimalOwnerProvider implements StreamServerDataProvider<EntityAccess
}
@Override
public String streamData(@NotNull EntityAccessor accessor) {
return CommonUtil.getLastKnownUsername(getOwnerUUID(accessor.getEntity()));
public Component streamData(@NotNull EntityAccessor accessor) {
ServerLevel level = accessor.getLevel();
UUID uuid = getOwnerUUID(accessor.getEntity());
Entity entity = level.getEntity(uuid);
if (entity != null) {
return entity.getName();
}
String name = lookupPlayerName(uuid, level.getServer().services());
return name == null ? null : Component.literal(name);
}
@Nullable
public static String lookupPlayerName(@Nullable UUID uuid, Services services) {
if (uuid == null) {
return null;
}
String name = services.nameToIdCache().get(uuid).map(NameAndId::name).orElse(null);
if (name != null) {
return name;
}
GameProfile profile = services.profileResolver().fetchById(uuid).orElse(null);
return profile == null ? null : profile.name();
}
@Override
public @NotNull StreamCodec<RegistryFriendlyByteBuf, String> streamCodec() {
return ByteBufCodecs.STRING_UTF8.cast();
public @NotNull StreamCodec<RegistryFriendlyByteBuf, Component> streamCodec() {
return ComponentSerialization.STREAM_CODEC;
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_ANIMAL_OWNER;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.entity;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.allay.Allay;
@@ -33,7 +33,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum MobBreedingProvider implements StreamServerDataProvider<EntityAccessor, Integer> {
INSTANCE;
private static final ResourceLocation MC_MOB_BREEDING = JadeProtocol.mc_id("mob_breeding");
private static final Identifier MC_MOB_BREEDING = JadeProtocol.mc_id("mob_breeding");
@Override
public @Nullable Integer streamData(@NotNull EntityAccessor accessor) {
@@ -55,7 +55,7 @@ public enum MobBreedingProvider implements StreamServerDataProvider<EntityAccess
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_MOB_BREEDING;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.entity;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.frog.Tadpole;
@@ -33,7 +33,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum MobGrowthProvider implements StreamServerDataProvider<EntityAccessor, Integer> {
INSTANCE;
private static final ResourceLocation MC_MOB_GROWTH = JadeProtocol.mc_id("mob_growth");
private static final Identifier MC_MOB_GROWTH = JadeProtocol.mc_id("mob_growth");
@Override
public @Nullable Integer streamData(@NotNull EntityAccessor accessor) {
@@ -54,7 +54,7 @@ public enum MobGrowthProvider implements StreamServerDataProvider<EntityAccessor
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_MOB_GROWTH;
}
}
@@ -18,20 +18,20 @@
package org.leavesmc.leaves.protocol.jade.provider.entity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.animal.Chicken;
import net.minecraft.world.entity.animal.armadillo.Armadillo;
import net.minecraft.world.entity.animal.chicken.Chicken;
import net.minecraft.world.entity.animal.sniffer.Sniffer;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.EntityAccessor;
import org.leavesmc.leaves.protocol.jade.provider.IServerDataProvider;
import org.leavesmc.leaves.protocol.jade.provider.ServerDataProvider;
public enum NextEntityDropProvider implements IServerDataProvider<EntityAccessor> {
public enum NextEntityDropProvider implements ServerDataProvider<EntityAccessor> {
INSTANCE;
private static final ResourceLocation MC_NEXT_ENTITY_DROP = JadeProtocol.mc_id("next_entity_drop");
private static final Identifier MC_NEXT_ENTITY_DROP = JadeProtocol.mc_id("next_entity_drop");
@Override
public void appendServerData(CompoundTag tag, @NotNull EntityAccessor accessor) {
@@ -53,7 +53,7 @@ public enum NextEntityDropProvider implements IServerDataProvider<EntityAccessor
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_NEXT_ENTITY_DROP;
}
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.jade.provider.entity;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -31,7 +31,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum PetArmorProvider implements StreamServerDataProvider<EntityAccessor, ItemStack> {
INSTANCE;
private static final ResourceLocation MC_PET_ARMOR = JadeProtocol.mc_id("pet_armor");
private static final Identifier MC_PET_ARMOR = JadeProtocol.mc_id("pet_armor");
@Nullable
@Override
@@ -46,7 +46,7 @@ public enum PetArmorProvider implements StreamServerDataProvider<EntityAccessor,
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_PET_ARMOR;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.jade.provider.entity;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
@@ -37,7 +37,7 @@ public enum StatusEffectsProvider implements StreamServerDataProvider<EntityAcce
private static final StreamCodec<RegistryFriendlyByteBuf, List<MobEffectInstance>> STREAM_CODEC = ByteBufCodecs.<RegistryFriendlyByteBuf, MobEffectInstance>list()
.apply(MobEffectInstance.STREAM_CODEC);
private static final ResourceLocation MC_POTION_EFFECTS = JadeProtocol.mc_id("potion_effects");
private static final Identifier MC_POTION_EFFECTS = JadeProtocol.mc_id("potion_effects");
@Override
@Nullable
@@ -56,7 +56,7 @@ public enum StatusEffectsProvider implements StreamServerDataProvider<EntityAcce
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_POTION_EFFECTS;
}
}
@@ -20,8 +20,8 @@ package org.leavesmc.leaves.protocol.jade.provider.entity;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.monster.ZombieVillager;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.monster.zombie.ZombieVillager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
@@ -31,7 +31,7 @@ import org.leavesmc.leaves.protocol.jade.provider.StreamServerDataProvider;
public enum ZombieVillagerProvider implements StreamServerDataProvider<EntityAccessor, Integer> {
INSTANCE;
private static final ResourceLocation MC_ZOMBIE_VILLAGER = JadeProtocol.mc_id("zombie_villager");
private static final Identifier MC_ZOMBIE_VILLAGER = JadeProtocol.mc_id("zombie_villager");
@Override
public @Nullable Integer streamData(@NotNull EntityAccessor accessor) {
@@ -45,7 +45,7 @@ public enum ZombieVillagerProvider implements StreamServerDataProvider<EntityAcc
}
@Override
public ResourceLocation getUid() {
public Identifier getUid() {
return MC_ZOMBIE_VILLAGER;
}
}
@@ -17,27 +17,19 @@
package org.leavesmc.leaves.protocol.jade.util;
import com.mojang.authlib.GameProfile;
import com.mojang.logging.LogUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.boss.EnderDragonPart;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import org.jetbrains.annotations.Nullable;
import net.minecraft.world.entity.boss.enderdragon.EnderDragonPart;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
import org.leavesmc.leaves.protocol.jade.provider.IServerExtensionProvider;
import org.slf4j.Logger;
import org.leavesmc.leaves.protocol.jade.provider.ServerExtensionProvider;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
public class CommonUtil {
private static final Logger LOGGER = LogUtils.getLogger();
public static Entity wrapPartEntityParent(Entity target) {
if (target instanceof EnderDragonPart part) {
return part.parentMob;
@@ -62,25 +54,15 @@ public class CommonUtil {
}
@Nullable
public static String getLastKnownUsername(@Nullable UUID uuid) {
if (uuid == null) {
return null;
}
Optional<GameProfile> optional = SkullBlockEntity.fetchGameProfile(String.valueOf(uuid)).getNow(Optional.empty());
return optional.map(GameProfile::getName).orElse(null);
}
public static <T> Map.Entry<ResourceLocation, List<ViewGroup<T>>> getServerExtensionData(
public static <T> Map.Entry<Identifier, List<ViewGroup<T>>> getServerExtensionData(
Accessor<?> accessor,
WrappedHierarchyLookup<IServerExtensionProvider<T>> lookup) {
WrappedHierarchyLookup<ServerExtensionProvider<T>> lookup) {
for (var provider : lookup.wrappedGet(accessor)) {
List<ViewGroup<T>> groups;
try {
groups = provider.getGroups(accessor);
} catch (Exception e) {
LOGGER.warn(e.toString());
JadeProtocol.LOGGER.error(e.toString());
continue;
}
if (groups != null) {
@@ -21,20 +21,17 @@ import com.google.common.base.Preconditions;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.*;
import com.mojang.logging.LogUtils;
import net.minecraft.core.IdMapper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.provider.IJadeProvider;
import org.slf4j.Logger;
import org.leavesmc.leaves.protocol.jade.provider.JadeProvider;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;
public class HierarchyLookup<T extends IJadeProvider> implements IHierarchyLookup<T> {
private static final Logger LOGGER = LogUtils.getLogger();
public class HierarchyLookup<T extends JadeProvider> implements IHierarchyLookup<T> {
private final Class<?> baseClass;
private final Cache<Class<?>, List<T>> resultCache = CacheBuilder.newBuilder().build();
private final boolean singleton;
@@ -89,7 +86,7 @@ public class HierarchyLookup<T extends IJadeProvider> implements IHierarchyLooku
return list;
});
} catch (ExecutionException e) {
LOGGER.warn("HierarchyLookup error", e);
JadeProtocol.LOGGER.warn("HierarchyLookup error", e);
}
return List.of();
}
@@ -117,12 +114,12 @@ public class HierarchyLookup<T extends IJadeProvider> implements IHierarchyLooku
}
@Override
public void loadComplete(PriorityStore<ResourceLocation, IJadeProvider> priorityStore) {
public void loadComplete(PriorityStore<Identifier, JadeProvider> priorityStore) {
objects.asMap().forEach((clazz, list) -> {
if (list.size() < 2) {
return;
}
Set<ResourceLocation> set = Sets.newHashSetWithExpectedSize(list.size());
Set<Identifier> set = Sets.newHashSetWithExpectedSize(list.size());
for (T provider : list) {
if (set.contains(provider.getUid())) {
throw new IllegalStateException("Duplicate UID: %s for %s".formatted(provider.getUid(), list.stream()
@@ -19,17 +19,17 @@ package org.leavesmc.leaves.protocol.jade.util;
import com.google.common.collect.Streams;
import net.minecraft.core.IdMapper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.provider.IJadeProvider;
import org.leavesmc.leaves.protocol.jade.provider.JadeProvider;
import java.util.*;
import java.util.stream.Stream;
public interface IHierarchyLookup<T extends IJadeProvider> {
public interface IHierarchyLookup<T extends JadeProvider> {
Comparator<IJadeProvider> COMPARATOR = Comparator.comparingInt(provider -> JadeProtocol.priorities.byValue(provider));
Comparator<JadeProvider> COMPARATOR = Comparator.comparingInt(provider -> JadeProtocol.priorities.byValue(provider));
default IHierarchyLookup<? extends T> cast() {
return this;
@@ -40,9 +40,9 @@ public interface IHierarchyLookup<T extends IJadeProvider> {
@Nullable
IdMapper<T> idMapper();
default List<ResourceLocation> mappedIds() {
default List<Identifier> mappedIds() {
return Streams.stream(Objects.requireNonNull(idMapper()))
.map(IJadeProvider::getUid)
.map(JadeProvider::getUid)
.toList();
}
@@ -65,7 +65,7 @@ public interface IHierarchyLookup<T extends IJadeProvider> {
void invalidate();
void loadComplete(PriorityStore<ResourceLocation, IJadeProvider> priorityStore);
void loadComplete(PriorityStore<Identifier, JadeProvider> priorityStore);
default IdMapper<T> createIdMapper() {
List<T> list = entries().flatMap(entry -> entry.getValue().stream()).toList();
@@ -28,13 +28,13 @@ import net.minecraft.world.item.component.TooltipDisplay;
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
public class ItemCollector<T> {
public static final int MAX_SIZE = 54;
public static final ItemCollector<?> EMPTY = new ItemCollector<>(null);
private static final CompoundTag IGNORED_TAG = new CompoundTag();
private static final Predicate<ItemStack> SHOWN = stack -> {
if (stack.isEmpty()) {
return false;
@@ -43,12 +43,8 @@ public class ItemCollector<T> {
return false;
}
if (stack.hasNonDefault(DataComponents.CUSTOM_MODEL_DATA) || stack.hasNonDefault(DataComponents.ITEM_MODEL)) {
CompoundTag tag = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).copyTag();
for (String key : tag.keySet()) {
if (key.toLowerCase(Locale.ENGLISH).endsWith("clear") && tag.getBooleanOr(key, true)) {
return false;
}
}
CustomData data = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY);
return !data.matchedBy(IGNORED_TAG);
}
return true;
};
@@ -59,6 +55,10 @@ public class ItemCollector<T> {
public boolean lastTimeIsEmpty;
public List<ViewGroup<ItemStack>> mergedResult;
static {
IGNORED_TAG.putBoolean("__JadeClear", true);
}
public ItemCollector(ItemIterator<T> iterator) {
this.iterator = iterator;
}
@@ -72,12 +72,12 @@ public class ItemCollector<T> {
return null;
}
long currentVersion = iterator.getVersion(container);
long gameTimeReforged = System.currentTimeMillis() / 50;
long gameTime = request.getLevel().getServer().getTickCount();
if (mergedResult != null && iterator.isFinished()) {
if (version == currentVersion) {
return mergedResult; // content not changed
}
if (lastTimeFinished + 5 > gameTimeReforged) {
if (lastTimeFinished + 5 > gameTime) {
return mergedResult; // avoid update too frequently
}
iterator.reset();
@@ -104,7 +104,7 @@ public class ItemCollector<T> {
mergedResult = groups;
lastTimeIsEmpty = mergedResult.getFirst().views.isEmpty();
version = currentVersion;
lastTimeFinished = gameTimeReforged;
lastTimeFinished = gameTime;
items.clear();
}
return groups;
@@ -18,7 +18,7 @@
package org.leavesmc.leaves.protocol.jade.util;
import com.google.common.collect.Lists;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.criterion.ItemPredicate;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.registries.BuiltInRegistries;
@@ -21,13 +21,12 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.mojang.logging.LogUtils;
import net.minecraft.core.IdMapper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.provider.IJadeProvider;
import org.slf4j.Logger;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
import org.leavesmc.leaves.protocol.jade.provider.JadeProvider;
import java.util.Collection;
import java.util.List;
@@ -36,8 +35,7 @@ import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;
public class PairHierarchyLookup<T extends IJadeProvider> implements IHierarchyLookup<T> {
private static final Logger LOGGER = LogUtils.getLogger();
public class PairHierarchyLookup<T extends JadeProvider> implements IHierarchyLookup<T> {
public final IHierarchyLookup<T> first;
public final IHierarchyLookup<T> second;
private final Cache<Pair<Class<?>, Class<?>>, List<T>> mergedCache = CacheBuilder.newBuilder().build();
@@ -66,7 +64,7 @@ public class PairHierarchyLookup<T extends IJadeProvider> implements IHierarchyL
return ImmutableList.sortedCopyOf(COMPARATOR, Iterables.concat(firstList, secondList));
});
} catch (ExecutionException e) {
LOGGER.warn(e.toString());
JadeProtocol.LOGGER.error(e.toString());
}
return List.of();
}
@@ -124,7 +122,7 @@ public class PairHierarchyLookup<T extends IJadeProvider> implements IHierarchyL
}
@Override
public void loadComplete(PriorityStore<ResourceLocation, IJadeProvider> priorityStore) {
public void loadComplete(PriorityStore<Identifier, JadeProvider> priorityStore) {
first.loadComplete(priorityStore);
second.loadComplete(priorityStore);
if (idMapped) {
@@ -21,7 +21,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -57,9 +57,9 @@ public class ViewGroup<T> {
ViewGroup::new);
}
public static <B extends ByteBuf, T> StreamCodec<B, Map.Entry<ResourceLocation, List<ViewGroup<T>>>> listCodec(StreamCodec<B, T> viewCodec) {
public static <B extends ByteBuf, T> StreamCodec<B, Map.Entry<Identifier, List<ViewGroup<T>>>> listCodec(StreamCodec<B, T> viewCodec) {
return StreamCodec.composite(
ResourceLocation.STREAM_CODEC,
Identifier.STREAM_CODEC,
Map.Entry::getKey,
ByteBufCodecs.<B, ViewGroup<T>>list().apply(codec(viewCodec)),
Map.Entry::getValue,
@@ -20,14 +20,14 @@ package org.leavesmc.leaves.protocol.jade.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.block.Block;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
import org.leavesmc.leaves.protocol.jade.accessor.BlockAccessor;
import org.leavesmc.leaves.protocol.jade.provider.IJadeProvider;
import org.leavesmc.leaves.protocol.jade.provider.JadeProvider;
import java.util.Collection;
import java.util.List;
@@ -36,7 +36,7 @@ import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
public class WrappedHierarchyLookup<T extends IJadeProvider> extends HierarchyLookup<T> {
public class WrappedHierarchyLookup<T extends JadeProvider> extends HierarchyLookup<T> {
public final List<Pair<IHierarchyLookup<T>, Function<Accessor<?>, @Nullable Object>>> overrides = Lists.newArrayList();
private boolean empty = true;
@@ -45,7 +45,7 @@ public class WrappedHierarchyLookup<T extends IJadeProvider> extends HierarchyLo
}
@NotNull
public static <T extends IJadeProvider> WrappedHierarchyLookup<T> forAccessor() {
public static <T extends JadeProvider> WrappedHierarchyLookup<T> forAccessor() {
WrappedHierarchyLookup<T> lookup = new WrappedHierarchyLookup<>();
lookup.overrides.add(Pair.of(
new HierarchyLookup<>(Block.class), accessor -> {
@@ -101,7 +101,7 @@ public class WrappedHierarchyLookup<T extends IJadeProvider> extends HierarchyLo
}
@Override
public void loadComplete(PriorityStore<ResourceLocation, IJadeProvider> priorityStore) {
public void loadComplete(PriorityStore<Identifier, JadeProvider> priorityStore) {
for (var override : overrides) {
override.getLeft().loadComplete(priorityStore);
}
@@ -24,7 +24,7 @@ import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import org.slf4j.Logger;
@@ -43,13 +43,13 @@ public class PacketTransformer {
private final Map<UUID, PartData> cache = Collections.synchronizedMap(new HashMap<>());
public static DiscardedPayload wrapRei(ResourceLocation location, FriendlyByteBuf buf) {
public static DiscardedPayload wrapRei(Identifier location, FriendlyByteBuf buf) {
FriendlyByteBuf newBuf = new FriendlyByteBuf(Unpooled.buffer());
newBuf.writeByteArray(ByteBufUtil.getBytes(buf));
return new DiscardedPayload(location, ByteBufUtil.getBytes(newBuf));
}
public void inbound(ResourceLocation id, RegistryFriendlyByteBuf buf, ServerPlayer player, BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer) {
public void inbound(Identifier id, RegistryFriendlyByteBuf buf, ServerPlayer player, BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer) {
UUID key = player.getUUID();
PartData data;
buf.readVarInt();
@@ -120,7 +120,7 @@ public class PacketTransformer {
}
}
public void outbound(ResourceLocation id, RegistryFriendlyByteBuf buf, BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer) {
public void outbound(Identifier id, RegistryFriendlyByteBuf buf, BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer) {
int maxSize = 1048576 - 1 - 20 - id.toString().getBytes(StandardCharsets.UTF_8).length;
if (buf.readableBytes() <= maxSize) {
ByteBuf stateBuf = Unpooled.buffer(1);
@@ -150,11 +150,11 @@ public class PacketTransformer {
}
private static class PartData {
private final ResourceLocation id;
private final Identifier id;
private final int partsNum;
private final List<RegistryFriendlyByteBuf> parts;
public PartData(ResourceLocation id, int partsNum) {
public PartData(Identifier id, int partsNum) {
this.id = id;
this.partsNum = partsNum;
this.parts = new ArrayList<>();
@@ -23,7 +23,6 @@ import com.mojang.logging.LogUtils;
import fun.bm.lophine.config.modules.function.protocol.REIServerProtocolConfig;
import io.netty.buffer.Unpooled;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
@@ -33,10 +32,11 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.util.Util;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.*;
@@ -73,17 +73,17 @@ public class REIServerProtocol implements LeavesProtocol {
public static final String PROTOCOL_ID = "roughlyenoughitems";
public static final String CHEAT_PERMISSION = "leaves.protocol.rei.cheat";
public static final ResourceLocation DELETE_ITEMS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "delete_item");
public static final ResourceLocation CREATE_ITEMS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item");
public static final ResourceLocation CREATE_ITEMS_HOTBAR_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_hotbar");
public static final ResourceLocation CREATE_ITEMS_GRAB_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_grab");
public static final ResourceLocation CREATE_ITEMS_MESSAGE_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "ci_msg");
public static final ResourceLocation MOVE_ITEMS_NEW_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "move_items_new");
public static final ResourceLocation NOT_ENOUGH_ITEMS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "og_not_enough"); // this pack is under to-do at rei-client, so we don't handle it
public static final ResourceLocation SYNC_DISPLAYS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "sync_displays");
public static final Identifier DELETE_ITEMS_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "delete_item");
public static final Identifier CREATE_ITEMS_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "create_item");
public static final Identifier CREATE_ITEMS_HOTBAR_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "create_item_hotbar");
public static final Identifier CREATE_ITEMS_GRAB_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "create_item_grab");
public static final Identifier CREATE_ITEMS_MESSAGE_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "ci_msg");
public static final Identifier MOVE_ITEMS_NEW_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "move_items_new");
public static final Identifier NOT_ENOUGH_ITEMS_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "og_not_enough"); // this pack is under to-do at rei-client, so we don't handle it
public static final Identifier SYNC_DISPLAYS_PACKET = Identifier.fromNamespaceAndPath("roughlyenoughitems", "sync_displays");
public static final Map<ResourceLocation, PacketTransformer> TRANSFORMERS = Util.make(() -> {
ImmutableMap.Builder<ResourceLocation, PacketTransformer> builder = ImmutableMap.builder();
public static final Map<Identifier, PacketTransformer> TRANSFORMERS = Util.make(() -> {
ImmutableMap.Builder<Identifier, PacketTransformer> builder = ImmutableMap.builder();
builder.put(SYNC_DISPLAYS_PACKET, new PacketTransformer());
builder.put(DELETE_ITEMS_PACKET, new PacketTransformer());
builder.put(CREATE_ITEMS_PACKET, new PacketTransformer());
@@ -108,8 +108,8 @@ public class REIServerProtocol implements LeavesProtocol {
}
@Contract("_ -> new")
public static ResourceLocation id(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID, path);
public static Identifier id(String path) {
return Identifier.tryBuild(PROTOCOL_ID, path);
}
public static void onConfigModify(boolean enabled) {
@@ -194,7 +194,7 @@ public class REIServerProtocol implements LeavesProtocol {
}
@ProtocolHandler.MinecraftRegister(onlyNamespace = true, stage = ProtocolHandler.Stage.GAME)
public static void onPlayerSubscribed(@NotNull ServerPlayer player, ResourceLocation location) {
public static void onPlayerSubscribed(@NotNull ServerPlayer player, Identifier location) {
enabledPlayers.add(player);
String channel = location.getPath();
if (channel.equals("sync_displays")) {
@@ -203,7 +203,7 @@ public class REIServerProtocol implements LeavesProtocol {
}
} else if (channel.equals("ci_msg")) {
// cheat rei-client into using "delete_item" packet
if (MinecraftServer.getServer().getProfilePermissions(player.getGameProfile()) < 1) {
if (MinecraftServer.getServer().getProfilePermissions(player.nameAndId()).level().id() < 1) {
player.getBukkitEntity().sendOpLevel((byte) 1);
}
}
@@ -229,7 +229,7 @@ public class REIServerProtocol implements LeavesProtocol {
if (!hasCheatPermission(player)) {
return;
}
BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
FriendlyByteBuf tmpBuf = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(c2sWholeBuf.readByteArray());
ItemStack itemStack = tmpBuf.readLenientJsonWithCodec(ItemStack.OPTIONAL_CODEC);
if (player.getInventory().add(itemStack.copy())) {
@@ -254,7 +254,7 @@ public class REIServerProtocol implements LeavesProtocol {
if (!hasCheatPermission(player)) {
return;
}
BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
FriendlyByteBuf tmpBuf = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(c2sWholeBuf.readByteArray());
ItemStack itemStack = tmpBuf.readLenientJsonWithCodec(ItemStack.OPTIONAL_CODEC);
ItemStack stack = itemStack.copy();
@@ -284,7 +284,7 @@ public class REIServerProtocol implements LeavesProtocol {
if (!hasCheatPermission(player)) {
return;
}
BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
FriendlyByteBuf tmpBuf = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(c2sWholeBuf.readByteArray());
ItemStack stack = tmpBuf.readLenientJsonWithCodec(ItemStack.OPTIONAL_CODEC);
int hotbarSlotId = tmpBuf.readVarInt();
@@ -310,10 +310,10 @@ public class REIServerProtocol implements LeavesProtocol {
@ProtocolHandler.BytebufReceiver(key = "move_items_new")
public static void handleMoveItem(ServerPlayer player, RegistryFriendlyByteBuf buf) {
BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer = (ignored, c2sWholeBuf) -> {
FriendlyByteBuf tmpBuf = new FriendlyByteBuf(Unpooled.buffer()).writeBytes(c2sWholeBuf.readByteArray());
AbstractContainerMenu container = player.containerMenu;
tmpBuf.readResourceLocation();
tmpBuf.readIdentifier();
try {
boolean shift = tmpBuf.readBoolean();
try {
@@ -354,7 +354,7 @@ public class REIServerProtocol implements LeavesProtocol {
inboundTransform(player, MOVE_ITEMS_NEW_PACKET, buf, consumer);
}
private static void inboundTransform(ServerPlayer player, ResourceLocation id, RegistryFriendlyByteBuf buf, BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer) {
private static void inboundTransform(ServerPlayer player, Identifier id, RegistryFriendlyByteBuf buf, BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer) {
PacketTransformer transformer = TRANSFORMERS.get(id);
if (transformer != null) {
transformer.inbound(id, buf, player, consumer);
@@ -363,7 +363,7 @@ public class REIServerProtocol implements LeavesProtocol {
}
}
private static void outboundTransform(RegistryFriendlyByteBuf buf, BiConsumer<ResourceLocation, RegistryFriendlyByteBuf> consumer) {
private static void outboundTransform(RegistryFriendlyByteBuf buf, BiConsumer<Identifier, RegistryFriendlyByteBuf> consumer) {
PacketTransformer transformer = TRANSFORMERS.get(SYNC_DISPLAYS_PACKET);
if (transformer != null) {
transformer.outbound(SYNC_DISPLAYS_PACKET, buf, consumer);
@@ -17,19 +17,19 @@
package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
public class BlastingDisplay extends CookingDisplay {
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/blasting");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/blasting");
public BlastingDisplay(RecipeHolder<? extends AbstractCookingRecipe> recipe) {
super(recipe);
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
}
@@ -17,19 +17,19 @@
package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
public class CampfireDisplay extends CookingDisplay {
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/campfire");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/campfire");
public CampfireDisplay(RecipeHolder<CampfireCookingRecipe> recipe) {
super(recipe);
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
@@ -38,7 +38,7 @@ public abstract class CookingDisplay extends Display {
CookingDisplay::getInputEntries,
EntryIngredient.CODEC.apply(ByteBufCodecs.list()),
CookingDisplay::getOutputEntries,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
CookingDisplay::getOptionalLocation,
ByteBufCodecs.FLOAT,
CookingDisplay::getXp,
@@ -49,7 +49,7 @@ public abstract class CookingDisplay extends Display {
protected float xp;
protected double cookTime;
private CookingDisplay(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull ResourceLocation id, float xp, double cookTime) {
private CookingDisplay(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Identifier id, float xp, double cookTime) {
super(inputs, outputs, id);
this.xp = xp;
this.cookTime = cookTime;
@@ -59,14 +59,14 @@ public abstract class CookingDisplay extends Display {
this(
List.of(EntryIngredient.ofIngredient(recipe.value().input())),
List.of(EntryIngredient.of(recipe.value().assemble(new SingleRecipeInput(ItemStack.EMPTY), CraftRegistry.getMinecraftRegistry()))),
recipe.id().location(),
recipe.id().identifier(),
recipe.value().experience(),
recipe.value().cookingTime()
);
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static CookingDisplay of(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Optional<ResourceLocation> id, float xp, double cookTime) {
private static CookingDisplay of(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Optional<Identifier> id, float xp, double cookTime) {
throw new UnsupportedOperationException();
}
@@ -17,7 +17,7 @@
package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.rei.ingredient.EntryIngredient;
@@ -27,7 +27,7 @@ public abstract class CraftingDisplay extends Display {
public CraftingDisplay(@NotNull List<EntryIngredient> inputs,
@NotNull List<EntryIngredient> outputs,
@NotNull ResourceLocation location) {
@NotNull Identifier location) {
super(inputs, outputs, location);
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.rei.ingredient.EntryIngredient;
@@ -34,18 +34,18 @@ public class CustomDisplay extends CraftingDisplay {
CustomDisplay::getInputEntries,
EntryIngredient.CODEC.apply(ByteBufCodecs.list()),
CustomDisplay::getOutputEntries,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
CustomDisplay::getOptionalLocation,
CustomDisplay::of
);
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/crafting/custom");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/crafting/custom");
private final int width;
private final int height;
/**
* see me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomDisplay#DefaultCustomDisplay
*/
public CustomDisplay(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull ResourceLocation location) {
public CustomDisplay(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Identifier location) {
super(inputs, outputs, location);
BitSet row = new BitSet(3);
BitSet column = new BitSet(3);
@@ -63,7 +63,7 @@ public class CustomDisplay extends CraftingDisplay {
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static CustomDisplay of(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Optional<ResourceLocation> id) {
private static CustomDisplay of(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Optional<Identifier> id) {
throw new UnsupportedOperationException();
}
@@ -78,7 +78,7 @@ public class CustomDisplay extends CraftingDisplay {
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
@@ -24,7 +24,7 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tags.TagKey;
import net.minecraft.util.context.ContextMap;
@@ -51,7 +51,7 @@ import java.util.stream.Stream;
*/
public abstract class Display {
protected ResourceLocation id;
protected Identifier id;
protected List<EntryIngredient> inputs;
@@ -59,7 +59,7 @@ public abstract class Display {
public Display(@NotNull List<EntryIngredient> inputs,
@NotNull List<EntryIngredient> outputs,
@NotNull ResourceLocation id) {
@NotNull Identifier id) {
this.inputs = inputs;
this.outputs = outputs;
this.id = id;
@@ -76,7 +76,7 @@ public abstract class Display {
@Override
public void encode(@NotNull RegistryFriendlyByteBuf buffer, @NotNull Display display) {
new FriendlyByteBuf(buffer).writeResourceLocation(display.getSerializerId());
new FriendlyByteBuf(buffer).writeIdentifier(display.getSerializerId());
((StreamCodec<RegistryFriendlyByteBuf, Display>) display.streamCodec()).encode(buffer, display);
}
};
@@ -89,9 +89,9 @@ public abstract class Display {
if (!displays.isEmpty()) {
RecipeDisplay recipeDisplay = displays.getFirst();
if (recipeDisplay instanceof ShapelessCraftingRecipeDisplay shapelessRecipeDisplay) {
displayList.add(new ShapelessDisplay(shapelessRecipeDisplay, recipeHolder.id().location()));
displayList.add(new ShapelessDisplay(shapelessRecipeDisplay, recipeHolder.id().identifier()));
} else if (recipeDisplay instanceof ShapedCraftingRecipeDisplay shapelessRecipe) {
displayList.add(new ShapedDisplay(shapelessRecipe, recipeHolder.id().location()));
displayList.add(new ShapedDisplay(shapelessRecipe, recipeHolder.id().identifier()));
}
}
return displayList;
@@ -103,7 +103,7 @@ public abstract class Display {
@NotNull
public static Collection<Display> ofTippedArrowRecipe(@NotNull RecipeHolder<TippedArrowRecipe> recipeHolder) {
EntryIngredient arrowIngredient = EntryIngredient.of(Items.ARROW);
Set<ResourceLocation> registeredPotions = new HashSet<>();
Set<Identifier> registeredPotions = new HashSet<>();
List<Display> displays = new ArrayList<>();
MinecraftServer.getServer().registryAccess().lookup(Registries.POTION).stream()
.flatMap(Registry::listElements)
@@ -113,7 +113,7 @@ public abstract class Display {
if (potion == null || potion.potion().isEmpty()) {
return;
}
if (potion.potion().get().unwrapKey().isPresent() && registeredPotions.add(potion.potion().get().unwrapKey().get().location())) {
if (potion.potion().get().unwrapKey().isPresent() && registeredPotions.add(potion.potion().get().unwrapKey().get().identifier())) {
List<EntryIngredient> input = new ArrayList<>();
for (int i = 0; i < 4; i++) {
input.add(arrowIngredient);
@@ -124,7 +124,7 @@ public abstract class Display {
}
ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8);
outputStack.set(DataComponents.POTION_CONTENTS, potion);
displays.add(new CustomDisplay(input, List.of(EntryIngredient.of(outputStack)), recipeHolder.id().location()));
displays.add(new CustomDisplay(input, List.of(EntryIngredient.of(outputStack)), recipeHolder.id().identifier()));
}
});
return displays;
@@ -145,7 +145,7 @@ public abstract class Display {
outputs[i] = new ItemStack(Items.FIREWORK_ROCKET, 3);
outputs[i].set(DataComponents.FIREWORKS, new Fireworks(i + 1, List.of()));
}
return Collections.singleton(new ShapelessDisplay(List.of(inputs), List.of(EntryIngredient.of(outputs)), recipeHolder.id().location()));
return Collections.singleton(new ShapelessDisplay(List.of(inputs), List.of(EntryIngredient.of(outputs)), recipeHolder.id().identifier()));
}
/**
@@ -157,7 +157,7 @@ public abstract class Display {
new ShapelessDisplay(
List.of(EntryIngredient.of(Items.FILLED_MAP), EntryIngredient.of(Items.MAP)),
List.of(EntryIngredient.of(new ItemStack(Items.FILLED_MAP, 2))),
recipeHolder.id().location())
recipeHolder.id().identifier())
);
}
@@ -174,7 +174,7 @@ public abstract class Display {
),
List.of(ofSlotDisplay(recipeHolder.value().getResult())),
SmithingDisplay.SmithingRecipeType.TRANSFORM,
recipeHolder.id().location()
recipeHolder.id().identifier()
);
}
@@ -198,7 +198,7 @@ public abstract class Display {
recipe.templateIngredient().map(EntryIngredient::ofIngredient).orElse(EntryIngredient.empty()),
baseIngredient,
EntryIngredient.ofItemHolder(additionStack)
), List.of(baseIngredient), SmithingDisplay.SmithingRecipeType.TRIM, recipeHolder.id().location(), recipe.pattern()));
), List.of(baseIngredient), SmithingDisplay.SmithingRecipeType.TRIM, recipeHolder.id().identifier(), recipe.pattern()));
}
return displays;
@@ -283,15 +283,15 @@ public abstract class Display {
return outputs;
}
public ResourceLocation getDisplayLocation() {
public Identifier getDisplayLocation() {
return id;
}
public Optional<ResourceLocation> getOptionalLocation() {
public Optional<Identifier> getOptionalLocation() {
return Optional.ofNullable(id);
}
public abstract ResourceLocation getSerializerId();
public abstract Identifier getSerializerId();
public abstract StreamCodec<RegistryFriendlyByteBuf, ? extends Display> streamCodec();
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.RecipeHolder;
@@ -42,7 +42,7 @@ public class ShapedDisplay extends CraftingDisplay {
CraftingDisplay::getInputEntries,
EntryIngredient.CODEC.apply(ByteBufCodecs.list()),
CraftingDisplay::getOutputEntries,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
CraftingDisplay::getOptionalLocation,
ByteBufCodecs.INT,
CraftingDisplay::getWidth,
@@ -50,7 +50,7 @@ public class ShapedDisplay extends CraftingDisplay {
CraftingDisplay::getHeight,
ShapedDisplay::of
);
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/crafting/shaped");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/crafting/shaped");
private final int width;
private final int height;
@@ -58,13 +58,13 @@ public class ShapedDisplay extends CraftingDisplay {
super(
ofIngredient(recipeHolder.value()),
List.of(EntryIngredient.of(recipeHolder.value().assemble(CraftingInput.EMPTY, CraftRegistry.getMinecraftRegistry()))),
recipeHolder.id().location()
recipeHolder.id().identifier()
);
this.width = recipeHolder.value().getWidth();
this.height = recipeHolder.value().getHeight();
}
public ShapedDisplay(@NotNull ShapedCraftingRecipeDisplay recipeDisplay, ResourceLocation id) {
public ShapedDisplay(@NotNull ShapedCraftingRecipeDisplay recipeDisplay, Identifier id) {
super(
Display.ofSlotDisplays(recipeDisplay.ingredients()),
List.of(ofSlotDisplay(recipeDisplay.result())),
@@ -75,7 +75,7 @@ public class ShapedDisplay extends CraftingDisplay {
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static CraftingDisplay of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<ResourceLocation> location, int width, int height) {
private static CraftingDisplay of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<Identifier> location, int width, int height) {
throw new UnsupportedOperationException();
}
@@ -102,7 +102,7 @@ public class ShapedDisplay extends CraftingDisplay {
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.ShapelessRecipe;
@@ -39,16 +39,16 @@ public class ShapelessDisplay extends CraftingDisplay {
CraftingDisplay::getInputEntries,
EntryIngredient.CODEC.apply(ByteBufCodecs.list()),
CraftingDisplay::getOutputEntries,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
CraftingDisplay::getOptionalLocation,
ShapelessDisplay::of
);
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/crafting/shapeless");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/crafting/shapeless");
public ShapelessDisplay(@NotNull List<EntryIngredient> inputs,
@NotNull List<EntryIngredient> outputs,
@NotNull ResourceLocation location) {
@NotNull Identifier location) {
super(inputs, outputs, location);
}
@@ -56,11 +56,11 @@ public class ShapelessDisplay extends CraftingDisplay {
this(
recipeHolder.value().placementInfo().ingredients().stream().map(EntryIngredient::ofIngredient).toList(),
List.of(EntryIngredient.of(recipeHolder.value().assemble(CraftingInput.EMPTY, CraftRegistry.getMinecraftRegistry()))),
recipeHolder.id().location()
recipeHolder.id().identifier()
);
}
public ShapelessDisplay(@NotNull ShapelessCraftingRecipeDisplay recipeDisplay, ResourceLocation id) {
public ShapelessDisplay(@NotNull ShapelessCraftingRecipeDisplay recipeDisplay, Identifier id) {
this(
ofSlotDisplays(recipeDisplay.ingredients()),
List.of(ofSlotDisplay(recipeDisplay.result())),
@@ -69,7 +69,7 @@ public class ShapelessDisplay extends CraftingDisplay {
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static CraftingDisplay of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<ResourceLocation> location) {
private static CraftingDisplay of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<Identifier> location) {
throw new NotImplementedException();
}
@@ -84,7 +84,7 @@ public class ShapelessDisplay extends CraftingDisplay {
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
@@ -17,19 +17,19 @@
package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.SmeltingRecipe;
public class SmeltingDisplay extends CookingDisplay {
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/smelting");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/smelting");
public SmeltingDisplay(RecipeHolder<SmeltingRecipe> recipe) {
super(recipe);
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
}
@@ -23,7 +23,7 @@ import net.minecraft.core.Holder;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ByIdMap;
import net.minecraft.world.item.equipment.trim.TrimPattern;
import org.jetbrains.annotations.NotNull;
@@ -41,12 +41,12 @@ public class SmithingDisplay extends Display {
SmithingDisplay::getOutputEntries,
ByteBufCodecs.optional(SmithingRecipeType.STREAM_CODEC),
SmithingDisplay::getOptionalType,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
SmithingDisplay::getOptionalLocation,
SmithingDisplay::of
);
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/smithing");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/smithing");
private final SmithingRecipeType type;
@@ -54,14 +54,14 @@ public class SmithingDisplay extends Display {
@NotNull List<EntryIngredient> inputs,
@NotNull List<EntryIngredient> outputs,
@NotNull SmithingRecipeType type,
@NotNull ResourceLocation location
@NotNull Identifier location
) {
super(inputs, outputs, location);
this.type = type;
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static SmithingDisplay of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<SmithingRecipeType> type, Optional<ResourceLocation> location) {
private static SmithingDisplay of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<SmithingRecipeType> type, Optional<Identifier> location) {
throw new UnsupportedOperationException();
}
@@ -70,7 +70,7 @@ public class SmithingDisplay extends Display {
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
@@ -97,14 +97,14 @@ public class SmithingDisplay extends Display {
SmithingDisplay.Trimming::getOutputEntries,
ByteBufCodecs.optional(SmithingRecipeType.STREAM_CODEC),
SmithingDisplay.Trimming::getOptionalType,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
SmithingDisplay.Trimming::getOptionalLocation,
TrimPattern.STREAM_CODEC,
SmithingDisplay.Trimming::pattern,
SmithingDisplay.Trimming::of
);
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/smithing/trimming");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/smithing/trimming");
private final Holder<TrimPattern> pattern;
@@ -112,7 +112,7 @@ public class SmithingDisplay extends Display {
@NotNull List<EntryIngredient> inputs,
@NotNull List<EntryIngredient> outputs,
@NotNull SmithingRecipeType type,
@NotNull ResourceLocation location,
@NotNull Identifier location,
@NotNull Holder<TrimPattern> pattern
) {
super(inputs, outputs, type, location);
@@ -120,12 +120,12 @@ public class SmithingDisplay extends Display {
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static Trimming of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<SmithingRecipeType> type, Optional<ResourceLocation> location, Holder<TrimPattern> pattern) {
public static Trimming of(List<EntryIngredient> inputs, List<EntryIngredient> outputs, Optional<SmithingRecipeType> type, Optional<Identifier> location, Holder<TrimPattern> pattern) {
throw new UnsupportedOperationException();
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
@@ -17,19 +17,19 @@
package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
public class SmokingDisplay extends CookingDisplay {
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/smoking");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/smoking");
public SmokingDisplay(RecipeHolder<? extends AbstractCookingRecipe> recipe) {
super(recipe);
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
}
@@ -20,7 +20,7 @@ package org.leavesmc.leaves.protocol.rei.display;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.SingleRecipeInput;
@@ -41,14 +41,14 @@ public class StoneCuttingDisplay extends Display {
StoneCuttingDisplay::getInputEntries,
EntryIngredient.CODEC.apply(ByteBufCodecs.list()),
StoneCuttingDisplay::getOutputEntries,
ByteBufCodecs.optional(ResourceLocation.STREAM_CODEC),
ByteBufCodecs.optional(Identifier.STREAM_CODEC),
StoneCuttingDisplay::getOptionalLocation,
StoneCuttingDisplay::of
);
private static final ResourceLocation SERIALIZER_ID = ResourceLocation.tryBuild("minecraft", "default/stone_cutting");
private static final Identifier SERIALIZER_ID = Identifier.tryBuild("minecraft", "default/stone_cutting");
public StoneCuttingDisplay(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull ResourceLocation id) {
public StoneCuttingDisplay(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Identifier id) {
super(inputs, outputs, id);
}
@@ -56,17 +56,17 @@ public class StoneCuttingDisplay extends Display {
this(
List.of(EntryIngredient.ofIngredient(recipeHolder.value().input())),
List.of(EntryIngredient.of(recipeHolder.value().assemble(new SingleRecipeInput(ItemStack.EMPTY), CraftRegistry.getMinecraftRegistry()))),
recipeHolder.id().location()
recipeHolder.id().identifier()
);
}
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static StoneCuttingDisplay of(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Optional<ResourceLocation> id) {
private static StoneCuttingDisplay of(@NotNull List<EntryIngredient> inputs, @NotNull List<EntryIngredient> outputs, @NotNull Optional<Identifier> id) {
throw new UnsupportedOperationException();
}
@Override
public ResourceLocation getSerializerId() {
public Identifier getSerializerId() {
return SERIALIZER_ID;
}
@@ -23,7 +23,7 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
@@ -36,7 +36,7 @@ import java.util.stream.Stream;
public class EntryIngredient {
private static final StreamCodec<RegistryFriendlyByteBuf, Holder<Item>> ITEM_STREAM_CODEC = ByteBufCodecs.holderRegistry(Registries.ITEM);
private static final ResourceLocation ITEM_ID = ResourceLocation.withDefaultNamespace("item");
private static final Identifier ITEM_ID = Identifier.withDefaultNamespace("item");
public static final StreamCodec<RegistryFriendlyByteBuf, EntryIngredient> CODEC = new StreamCodec<>() {
@NotNull
@Override
@@ -48,7 +48,7 @@ public class EntryIngredient {
public void encode(@NotNull RegistryFriendlyByteBuf buffer, @NotNull EntryIngredient value) {
ByteBufCodecs.writeCount(buffer, value.size(), Integer.MAX_VALUE);
value.stream().forEach(itemStack -> {
buffer.writeResourceLocation(ITEM_ID);
buffer.writeIdentifier(ITEM_ID);
if (itemStack.isEmpty()) {
buffer.writeVarInt(0);
} else {
@@ -21,14 +21,14 @@ import ca.spottedleaf.moonrise.common.util.TickThread;
import com.mojang.logging.LogUtils;
import fun.bm.lophine.config.modules.function.protocol.ServuxProtocolConfig;
import io.netty.buffer.Unpooled;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Util;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
@@ -186,7 +186,7 @@ public class ServuxEntityDataProtocol implements LeavesProtocol {
public static class EntityDataPayload implements LeavesCustomPayload {
@ID
public static final ResourceLocation CHANNEL = ServuxProtocol.id("entity_data");
public static final Identifier CHANNEL = ServuxProtocol.id("entity_data");
@Codec
public static final StreamCodec<FriendlyByteBuf, EntityDataPayload> CODEC = StreamCodec.of(
@@ -30,13 +30,13 @@ import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.gamerules.GameRules;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.core.LeavesProtocol;
@@ -137,7 +137,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
if (dr.result().isPresent()) {
CompoundTag entry = new CompoundTag();
entry.putString("id_reg", recipeEntry.id().registry().toString());
entry.putString("id_value", recipeEntry.id().location().toString());
entry.putString("id_value", recipeEntry.id().identifier().toString());
entry.put("recipe", dr.result().get());
list.add(entry);
}
@@ -149,7 +149,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
public static void refreshWeatherData(ServerPlayer player) {
ServerLevel level = MinecraftServer.getServer().overworld();
if (!level.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE)) {
if (!level.getGameRules().get(GameRules.ADVANCE_WEATHER)) {
return;
}
@@ -180,11 +180,11 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
private static void putWorldData(@NotNull CompoundTag metadata) {
ServerLevel level = MinecraftServer.getServer().overworld();
BlockPos spawnPos = level.levelData.getSpawnPos();
BlockPos spawnPos = level.serverLevelData.getRespawnData().pos();
metadata.putInt("spawnPosX", spawnPos.getX());
metadata.putInt("spawnPosY", spawnPos.getY());
metadata.putInt("spawnPosZ", spawnPos.getZ());
metadata.putInt("spawnChunkRadius", level.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
metadata.putInt("spawnChunkRadius", level.getGameRules().get(GameRules.RESPAWN_RADIUS));
if (ServuxProtocolConfig.hudMetadataShareSeed) {
metadata.putLong("worldSeed", level.getSeed());
@@ -331,7 +331,7 @@ public class ServuxHudDataProtocol implements LeavesProtocol {
FriendlyByteBuf buffer) implements LeavesCustomPayload {
@ID
public static final ResourceLocation CHANNEL = ServuxProtocol.id("hud_metadata");
public static final Identifier CHANNEL = ServuxProtocol.id("hud_metadata");
@Codec
public static final StreamCodec<FriendlyByteBuf, HudDataPayload> CODEC = StreamCodec.of(
@@ -17,7 +17,7 @@
package org.leavesmc.leaves.protocol.servux;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.Contract;
import org.leavesmc.leaves.protocol.core.ProtocolUtils;
import org.slf4j.Logger;
@@ -30,7 +30,7 @@ public class ServuxProtocol {
public static final String SERVUX_STRING = ProtocolUtils.buildProtocolVersion(PROTOCOL_ID);
@Contract("_ -> new")
public static ResourceLocation id(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID, path);
public static Identifier id(String path) {
return Identifier.tryBuild(PROTOCOL_ID, path);
}
}
@@ -27,7 +27,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -93,7 +93,7 @@ public class ServuxStructuresProtocol implements LeavesProtocol {
}
public static void onStartedWatchingChunk(ServerPlayer player, LevelChunk chunk) {
MinecraftServer server = player.getServer();
MinecraftServer server = MinecraftServer.getServer();
if (players.containsKey(player.getId()) && server != null) {
addChunkTimeoutIfHasReferences(player.getUUID(), chunk, System.currentTimeMillis() / 50);
}
@@ -367,7 +367,7 @@ public class ServuxStructuresProtocol implements LeavesProtocol {
FriendlyByteBuf buffer) implements LeavesCustomPayload {
@ID
public static final ResourceLocation CHANNEL = ServuxProtocol.id("structures");
public static final Identifier CHANNEL = ServuxProtocol.id("structures");
@Codec
public static final StreamCodec<FriendlyByteBuf, StructuresPayload> CODEC = StreamCodec.of(
@@ -27,7 +27,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.LongArrayTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -198,7 +198,7 @@ public record LitematicaSchematic(Map<String, SubRegion> subRegions, SchematicMe
continue;
}
T target;
ResourceLocation resourceLocation = ResourceLocation.tryParse(tag.getStringOr(tagName, ""));
Identifier resourceLocation = Identifier.tryParse(tag.getStringOr(tagName, ""));
if (resourceLocation == null) {
continue;
}
@@ -28,7 +28,7 @@ import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -180,7 +180,7 @@ public class ServuxLitematicsProtocol implements LeavesProtocol {
ServuxLitematicaPayload payload = new ServuxLitematicaPayload(ServuxLitematicaPayloadType.PACKET_S2C_ENTITY_NBT_RESPONSE_SIMPLE);
payload.entityId = entityId;
if (entity instanceof net.minecraft.world.entity.player.Player) {
ResourceLocation loc = EntityType.getKey(entity.getType());
Identifier loc = EntityType.getKey(entity.getType());
tag = TagUtil.saveEntity(entity);
tag.putString("id", loc.toString());
payload.nbt = tag;
@@ -313,7 +313,7 @@ public class ServuxLitematicsProtocol implements LeavesProtocol {
public static class ServuxLitematicaPayload implements LeavesCustomPayload {
@ID
public static final ResourceLocation CHANNEL = ServuxProtocol.id("litematics");
public static final Identifier CHANNEL = ServuxProtocol.id("litematics");
@Codec
public static final StreamCodec<FriendlyByteBuf, ServuxLitematicaPayload> CODEC = StreamCodec.of(
@@ -70,7 +70,7 @@ public class EntityUtils {
Entity passenger = createEntityAndPassengersFromNBT(tagList.getCompoundOrEmpty(i), world);
if (passenger != null) {
passenger.startRiding(entity, true);
passenger.startRiding(entity, true, true);
}
}
}
@@ -28,7 +28,7 @@ import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.decoration.Painting;
import net.minecraft.world.entity.decoration.painting.Painting;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
@@ -119,7 +119,7 @@ public abstract class DataLogger<T extends Tag> {
ServerTickRateManager tickManager = server.tickRateManager();
boolean frozen = tickManager.isFrozen();
boolean sprinting = tickManager.isSprinting();
io.papermc.paper.threadedregions.TickData.TickReportData tickData = TickRegionScheduler.getCurrentRegion().getData().getRegionSchedulingHandle().getTickReport5s(System.nanoTime());
ca.spottedleaf.moonrise.common.time.TickData.TickReportData tickData = TickRegionScheduler.getCurrentRegion().getData().getRegionSchedulingHandle().getTickReport5s(System.nanoTime());
final double tps = tickData.tpsData().segmentAll().average();
final double mspt = tickData.timePerTickData().segmentAll().average() / 1.0E6;
@@ -163,7 +163,7 @@ public abstract class DataLogger<T extends Tag> {
}
try {
nbt.put(nmsEntity.level().dimension().location().toString(), MobCapData.CODEC.encodeStart(player.level().registryAccess().createSerializationContext(NbtOps.INSTANCE), mobCapData).getPartialOrThrow());
nbt.put(nmsEntity.level().dimension().identifier().toString(), MobCapData.CODEC.encodeStart(player.level().registryAccess().createSerializationContext(NbtOps.INSTANCE), mobCapData).getPartialOrThrow());
protocol.applyData(Type.MOB_CAPS, (ServerPlayer) nmsEntity, nbt);
} catch (Exception ignored) {
}
@@ -23,7 +23,7 @@ import io.netty.buffer.Unpooled;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
@@ -63,7 +63,7 @@ public class CommunicationManager implements LeavesProtocol {
final VersionHandshakeServer hi = new VersionHandshakeServer(newPlayer);
playerMap.put(newPlayer, player);
final GameProfile profile = player.getGameProfile();
SyncmaticaProtocol.getPlayerIdentifierProvider().updateName(profile.getId(), profile.getName());
SyncmaticaProtocol.getPlayerIdentifierProvider().updateName(profile.id(), profile.name());
startExchangeUnchecked(hi);
}
@@ -86,7 +86,7 @@ public class CommunicationManager implements LeavesProtocol {
onPacket(player.connection.exchangeTarget, payload.packetType(), payload.data());
}
public static void onPacket(final @NotNull ExchangeTarget source, final ResourceLocation id, final FriendlyByteBuf packetBuf) {
public static void onPacket(final @NotNull ExchangeTarget source, final Identifier id, final FriendlyByteBuf packetBuf) {
Exchange handler = null;
final Collection<Exchange> potentialMessageTarget = source.getExchanges();
if (potentialMessageTarget != null) {
@@ -105,7 +105,7 @@ public class CommunicationManager implements LeavesProtocol {
}
}
protected static void handle(ExchangeTarget source, @NotNull ResourceLocation id, FriendlyByteBuf packetBuf) {
protected static void handle(ExchangeTarget source, @NotNull Identifier id, FriendlyByteBuf packetBuf) {
if (id.equals(PacketType.REQUEST_LITEMATIC.identifier)) {
final UUID syncmaticaId = packetBuf.readUUID();
final ServerPlacement placement = SyncmaticaProtocol.getSyncmaticManager().getPlacement(syncmaticaId);
@@ -157,7 +157,7 @@ public class CommunicationManager implements LeavesProtocol {
final UUID placementId = packetBuf.readUUID();
final ServerPlacement placement = SyncmaticaProtocol.getSyncmaticManager().getPlacement(placementId);
if (placement != null) {
if (!getGameProfile(source).getId().equals(placement.getOwner().uuid)) {
if (!getGameProfile(source).id().equals(placement.getOwner().uuid)) {
return;
}
@@ -17,7 +17,7 @@
package org.leavesmc.leaves.protocol.syncmatica;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
public enum PacketType {
REGISTER_METADATA("register_metadata"),
@@ -39,9 +39,9 @@ public enum PacketType {
MODIFY_FINISH("modify_finish"),
MESSAGE("mesage");
public final ResourceLocation identifier;
public final Identifier identifier;
PacketType(final String id) {
identifier = ResourceLocation.tryBuild(SyncmaticaProtocol.PROTOCOL_ID, id);
identifier = Identifier.tryBuild(SyncmaticaProtocol.PROTOCOL_ID, id);
}
}
@@ -39,7 +39,7 @@ public class PlayerIdentifierProvider {
}
public PlayerIdentifier createOrGet(final @NotNull GameProfile gameProfile) {
return createOrGet(gameProfile.getId(), gameProfile.getName());
return createOrGet(gameProfile.id(), gameProfile.name());
}
public PlayerIdentifier createOrGet(final UUID uuid, final String playerName) {
@@ -19,17 +19,17 @@ package org.leavesmc.leaves.protocol.syncmatica;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
public record SyncmaticaPayload(ResourceLocation packetType, FriendlyByteBuf data) implements LeavesCustomPayload {
public record SyncmaticaPayload(Identifier packetType, FriendlyByteBuf data) implements LeavesCustomPayload {
@ID
private static final ResourceLocation NETWORK_ID = ResourceLocation.tryBuild(SyncmaticaProtocol.PROTOCOL_ID, "main");
private static final Identifier NETWORK_ID = Identifier.tryBuild(SyncmaticaProtocol.PROTOCOL_ID, "main");
@Codec
private static final StreamCodec<FriendlyByteBuf, SyncmaticaPayload> CODEC = StreamCodec.of(
(buf, payload) -> buf.writeResourceLocation(payload.packetType()).writeBytes(payload.data()),
buf -> new SyncmaticaPayload(buf.readResourceLocation(), new FriendlyByteBuf(buf.readBytes(buf.readableBytes())))
(buf, payload) -> buf.writeIdentifier(payload.packetType()).writeBytes(payload.data()),
buf -> new SyncmaticaPayload(buf.readIdentifier(), new FriendlyByteBuf(buf.readBytes(buf.readableBytes())))
);
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.syncmatica.exchange;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.syncmatica.*;
@@ -50,7 +50,7 @@ public class DownloadExchange extends AbstractExchange {
}
@Override
public boolean checkPacket(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public boolean checkPacket(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
if (id.equals(PacketType.SEND_LITEMATIC.identifier)
|| id.equals(PacketType.FINISHED_LITEMATIC.identifier)
|| id.equals(PacketType.CANCEL_LITEMATIC.identifier)) {
@@ -60,7 +60,7 @@ public class DownloadExchange extends AbstractExchange {
}
@Override
public void handle(final @NotNull ResourceLocation id, final @NotNull FriendlyByteBuf packetBuf) {
public void handle(final @NotNull Identifier id, final @NotNull FriendlyByteBuf packetBuf) {
packetBuf.readUUID();
if (id.equals(PacketType.SEND_LITEMATIC.identifier)) {
final int size = packetBuf.readInt();
@@ -18,14 +18,14 @@
package org.leavesmc.leaves.protocol.syncmatica.exchange;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
public interface Exchange {
ExchangeTarget getPartner();
boolean checkPacket(ResourceLocation id, FriendlyByteBuf packetBuf);
boolean checkPacket(Identifier id, FriendlyByteBuf packetBuf);
void handle(ResourceLocation id, FriendlyByteBuf packetBuf);
void handle(Identifier id, FriendlyByteBuf packetBuf);
boolean isFinished();
@@ -18,7 +18,7 @@
package org.leavesmc.leaves.protocol.syncmatica.exchange;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import org.leavesmc.leaves.protocol.core.ProtocolUtils;
import org.leavesmc.leaves.protocol.syncmatica.FeatureSet;
@@ -38,7 +38,7 @@ public class ExchangeTarget {
this.client = client;
}
public void sendPacket(final ResourceLocation id, final FriendlyByteBuf packetBuf) {
public void sendPacket(final Identifier id, final FriendlyByteBuf packetBuf) {
ProtocolUtils.sendPayloadPacket(client.player, new SyncmaticaPayload(id, packetBuf));
}
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.syncmatica.exchange;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.syncmatica.FeatureSet;
import org.leavesmc.leaves.protocol.syncmatica.PacketType;
@@ -32,13 +32,13 @@ public abstract class FeatureExchange extends AbstractExchange {
}
@Override
public boolean checkPacket(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public boolean checkPacket(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
return id.equals(PacketType.FEATURE_REQUEST.identifier)
|| id.equals(PacketType.FEATURE.identifier);
}
@Override
public void handle(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public void handle(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
if (id.equals(PacketType.FEATURE_REQUEST.identifier)) {
sendFeatures();
} else if (id.equals(PacketType.FEATURE.identifier)) {
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.syncmatica.exchange;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.syncmatica.*;
@@ -37,12 +37,12 @@ public class ModifyExchangeServer extends AbstractExchange {
}
@Override
public boolean checkPacket(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public boolean checkPacket(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
return id.equals(PacketType.MODIFY_FINISH.identifier) && checkUUID(packetBuf, placement.getId());
}
@Override
public void handle(final @NotNull ResourceLocation id, final @NotNull FriendlyByteBuf packetBuf) {
public void handle(final @NotNull Identifier id, final @NotNull FriendlyByteBuf packetBuf) {
packetBuf.readUUID();
if (id.equals(PacketType.MODIFY_FINISH.identifier)) {
CommunicationManager.receivePositionData(placement, packetBuf, getPartner());
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.syncmatica.exchange;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.syncmatica.PacketType;
import org.leavesmc.leaves.protocol.syncmatica.ServerPlacement;
@@ -41,7 +41,7 @@ public class UploadExchange extends AbstractExchange {
}
@Override
public boolean checkPacket(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public boolean checkPacket(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
if (id.equals(PacketType.RECEIVED_LITEMATIC.identifier)
|| id.equals(PacketType.CANCEL_LITEMATIC.identifier)) {
return checkUUID(packetBuf, toUpload.getId());
@@ -50,7 +50,7 @@ public class UploadExchange extends AbstractExchange {
}
@Override
public void handle(final @NotNull ResourceLocation id, final @NotNull FriendlyByteBuf packetBuf) {
public void handle(final @NotNull Identifier id, final @NotNull FriendlyByteBuf packetBuf) {
packetBuf.readUUID();
if (id.equals(PacketType.RECEIVED_LITEMATIC.identifier)) {
send();
@@ -19,7 +19,7 @@ package org.leavesmc.leaves.protocol.syncmatica.exchange;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.resources.Identifier;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.syncmatica.*;
@@ -32,13 +32,13 @@ public class VersionHandshakeServer extends FeatureExchange {
}
@Override
public boolean checkPacket(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public boolean checkPacket(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
return id.equals(PacketType.REGISTER_VERSION.identifier)
|| super.checkPacket(id, packetBuf);
}
@Override
public void handle(final @NotNull ResourceLocation id, final FriendlyByteBuf packetBuf) {
public void handle(final @NotNull Identifier id, final FriendlyByteBuf packetBuf) {
if (id.equals(PacketType.REGISTER_VERSION.identifier)) {
String partnerVersion = packetBuf.readUtf();
if (partnerVersion.equals("0.0.1")) {
@@ -31,8 +31,8 @@ import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.context.ContextMap;
import net.minecraft.world.item.*;
@@ -251,7 +251,7 @@ public class HopperCounter {
return direct;
}
ResourceLocation id = registryAccess.lookupOrThrow(Registries.ITEM).getKey(item);
Identifier id = registryAccess.lookupOrThrow(Registries.ITEM).getKey(item);
if (id == null) {
return null;
}
@@ -269,13 +269,13 @@ public class HopperCounter {
}
@NotNull
public static List<Recipe<?>> getRecipesForOutput(@NotNull RecipeManager recipeManager, ResourceLocation id, Level level) {
public static List<Recipe<?>> getRecipesForOutput(@NotNull RecipeManager recipeManager, Identifier id, Level level) {
List<Recipe<?>> results = new ArrayList<>();
ContextMap context = SlotDisplayContext.fromLevel(level);
recipeManager.getRecipes().forEach(recipe -> {
for (RecipeDisplay recipeDisplay : recipe.value().display()) {
recipeDisplay.result().resolveForStacks(context).forEach(stack -> {
if (BuiltInRegistries.ITEM.wrapAsHolder(stack.getItem()).unwrapKey().map(ResourceKey::location).orElseThrow(IllegalStateException::new).equals(id)) {
if (BuiltInRegistries.ITEM.wrapAsHolder(stack.getItem()).unwrapKey().map(ResourceKey::identifier).orElseThrow(IllegalStateException::new).equals(id)) {
results.add(recipe.value());
}
});
@@ -296,7 +296,7 @@ public class HopperCounter {
Block block = null;
final Registry<Item> itemRegistry = registryAccess.lookupOrThrow(Registries.ITEM);
final Registry<Block> blockRegistry = registryAccess.lookupOrThrow(Registries.BLOCK);
ResourceLocation id = itemRegistry.getKey(item);
Identifier id = itemRegistry.getKey(item);
if (item instanceof BlockItem blockItem) {
block = blockItem.getBlock();
} else if (blockRegistry.getOptional(id).isPresent()) {

Some files were not shown because too many files have changed in this diff Show More