mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-20 15:29:35 +00:00
feat: finish jade protocol
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package org.leavesmc.leaves.protocol.jade.accessor;
|
package org.leavesmc.leaves.protocol.jade.accessor;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.player.Player;
|
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.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
@@ -35,6 +37,12 @@ public interface BlockAccessor extends Accessor<BlockHitResult> {
|
|||||||
return blockEntity(() -> blockEntity);
|
return blockEntity(() -> blockEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder serverData(CompoundTag serverData);
|
||||||
|
|
||||||
|
Builder showDetails(boolean showDetails);
|
||||||
|
|
||||||
|
Builder serversideRep(ItemStack stack);
|
||||||
|
|
||||||
Builder blockEntity(Supplier<BlockEntity> blockEntity);
|
Builder blockEntity(Supplier<BlockEntity> blockEntity);
|
||||||
|
|
||||||
Builder from(BlockAccessor accessor);
|
Builder from(BlockAccessor accessor);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.leavesmc.leaves.protocol.jade.accessor;
|
|||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.ByteBufCodecs;
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
@@ -91,6 +92,21 @@ public class BlockAccessorImpl extends AccessorImpl<BlockHitResult> implements B
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder serverData(CompoundTag serverData) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder showDetails(boolean showDetails) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder serversideRep(ItemStack stack) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder blockEntity(Supplier<BlockEntity> blockEntity) {
|
public Builder blockEntity(Supplier<BlockEntity> blockEntity) {
|
||||||
this.blockEntity = blockEntity;
|
this.blockEntity = blockEntity;
|
||||||
@@ -113,30 +129,34 @@ public class BlockAccessorImpl extends AccessorImpl<BlockHitResult> implements B
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record SyncData(boolean showDetails, BlockHitResult hit, BlockState blockState, ItemStack fakeBlock) {
|
public record SyncData(boolean showDetails, BlockHitResult hit, ItemStack serversideRep, CompoundTag data) {
|
||||||
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
|
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
|
||||||
ByteBufCodecs.BOOL,
|
ByteBufCodecs.BOOL,
|
||||||
SyncData::showDetails,
|
SyncData::showDetails,
|
||||||
StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult),
|
StreamCodec.of(FriendlyByteBuf::writeBlockHitResult, FriendlyByteBuf::readBlockHitResult),
|
||||||
SyncData::hit,
|
SyncData::hit,
|
||||||
ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY),
|
|
||||||
SyncData::blockState,
|
|
||||||
ItemStack.OPTIONAL_STREAM_CODEC,
|
ItemStack.OPTIONAL_STREAM_CODEC,
|
||||||
SyncData::fakeBlock,
|
SyncData::serversideRep,
|
||||||
|
ByteBufCodecs.COMPOUND_TAG,
|
||||||
|
SyncData::data,
|
||||||
SyncData::new
|
SyncData::new
|
||||||
);
|
);
|
||||||
|
|
||||||
public BlockAccessor unpack(ServerPlayer player) {
|
public BlockAccessor unpack(ServerPlayer player) {
|
||||||
Supplier<BlockEntity> blockEntity = null;
|
Supplier<BlockEntity> blockEntity = null;
|
||||||
|
BlockState blockState = player.level().getBlockState(hit.getBlockPos());
|
||||||
if (blockState.hasBlockEntity()) {
|
if (blockState.hasBlockEntity()) {
|
||||||
blockEntity = Suppliers.memoize(() -> player.level().getBlockEntity(hit.getBlockPos()));
|
blockEntity = Suppliers.memoize(() -> player.level().getBlockEntity(hit.getBlockPos()));
|
||||||
}
|
}
|
||||||
return new Builder()
|
return new Builder()
|
||||||
.level(player.level())
|
.level(player.level())
|
||||||
.player(player)
|
.player(player)
|
||||||
|
.showDetails(showDetails)
|
||||||
.hit(hit)
|
.hit(hit)
|
||||||
.blockState(blockState)
|
.blockState(blockState)
|
||||||
.blockEntity(blockEntity)
|
.blockEntity(blockEntity)
|
||||||
|
.serversideRep(serversideRep)
|
||||||
|
.serverData(data)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.leavesmc.leaves.protocol.jade.accessor;
|
package org.leavesmc.leaves.protocol.jade.accessor;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@@ -29,6 +30,10 @@ public interface EntityAccessor extends Accessor<EntityHitResult> {
|
|||||||
|
|
||||||
Builder hit(Supplier<EntityHitResult> hit);
|
Builder hit(Supplier<EntityHitResult> hit);
|
||||||
|
|
||||||
|
Builder serverData(CompoundTag serverData);
|
||||||
|
|
||||||
|
Builder showDetails(boolean showDetails);
|
||||||
|
|
||||||
default Builder entity(Entity entity) {
|
default Builder entity(Entity entity) {
|
||||||
return entity(() -> entity);
|
return entity(() -> entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.leavesmc.leaves.protocol.jade.accessor;
|
package org.leavesmc.leaves.protocol.jade.accessor;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.ByteBufCodecs;
|
import net.minecraft.network.codec.ByteBufCodecs;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
@@ -65,6 +66,16 @@ public class EntityAccessorImpl extends AccessorImpl<EntityHitResult> implements
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder serverData(CompoundTag serverData) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder showDetails(boolean showDetails) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder entity(Supplier<Entity> entity) {
|
public Builder entity(Supplier<Entity> entity) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
@@ -86,7 +97,7 @@ public class EntityAccessorImpl extends AccessorImpl<EntityHitResult> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record SyncData(boolean showDetails, int id, int partIndex, Vec3 hitVec) {
|
public record SyncData(boolean showDetails, int id, int partIndex, Vec3 hitVec, CompoundTag data) {
|
||||||
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
|
public static final StreamCodec<RegistryFriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
|
||||||
ByteBufCodecs.BOOL,
|
ByteBufCodecs.BOOL,
|
||||||
SyncData::showDetails,
|
SyncData::showDetails,
|
||||||
@@ -96,6 +107,8 @@ public class EntityAccessorImpl extends AccessorImpl<EntityHitResult> implements
|
|||||||
SyncData::partIndex,
|
SyncData::partIndex,
|
||||||
ByteBufCodecs.VECTOR3F.map(Vec3::new, Vec3::toVector3f),
|
ByteBufCodecs.VECTOR3F.map(Vec3::new, Vec3::toVector3f),
|
||||||
SyncData::hitVec,
|
SyncData::hitVec,
|
||||||
|
ByteBufCodecs.COMPOUND_TAG,
|
||||||
|
SyncData::data,
|
||||||
SyncData::new
|
SyncData::new
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -104,8 +117,10 @@ public class EntityAccessorImpl extends AccessorImpl<EntityHitResult> implements
|
|||||||
return new EntityAccessorImpl.Builder()
|
return new EntityAccessorImpl.Builder()
|
||||||
.level(player.level())
|
.level(player.level())
|
||||||
.player(player)
|
.player(player)
|
||||||
|
.showDetails(showDetails)
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
.hit(Suppliers.memoize(() -> new EntityHitResult(entity.get(), hitVec)))
|
.hit(Suppliers.memoize(() -> new EntityHitResult(entity.get(), hitVec)))
|
||||||
|
.serverData(data)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
package org.leavesmc.leaves.protocol.jade.util;
|
package org.leavesmc.leaves.protocol.jade.util;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.boss.EnderDragonPart;
|
import net.minecraft.world.entity.boss.EnderDragonPart;
|
||||||
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.leavesmc.leaves.LeavesLogger;
|
import org.leavesmc.leaves.LeavesLogger;
|
||||||
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
|
import org.leavesmc.leaves.protocol.jade.accessor.Accessor;
|
||||||
import org.leavesmc.leaves.protocol.jade.provider.IServerExtensionProvider;
|
import org.leavesmc.leaves.protocol.jade.provider.IServerExtensionProvider;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class CommonUtil {
|
public class CommonUtil {
|
||||||
|
|
||||||
@@ -42,16 +37,6 @@ public class CommonUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static String getLastKnownUsername(@Nullable UUID uuid) {
|
|
||||||
if (uuid == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Optional<GameProfile> optional = MinecraftServer.getServer().services.profileResolver().fetchById(uuid);
|
|
||||||
return optional.map(GameProfile::name).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static <T> Map.Entry<ResourceLocation, List<ViewGroup<T>>> getServerExtensionData(
|
public static <T> Map.Entry<ResourceLocation, List<ViewGroup<T>>> getServerExtensionData(
|
||||||
Accessor<?> accessor,
|
Accessor<?> accessor,
|
||||||
WrappedHierarchyLookup<IServerExtensionProvider<T>> lookup) {
|
WrappedHierarchyLookup<IServerExtensionProvider<T>> lookup) {
|
||||||
|
|||||||
Reference in New Issue
Block a user