mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
feat: try to implement jade v9 (WIP)
This commit is contained in:
@@ -70,7 +70,7 @@ import java.util.Set;
|
||||
public class JadeProtocol implements LeavesProtocol {
|
||||
|
||||
public static final String PROTOCOL_ID = "jade";
|
||||
public static final String PROTOCOL_VERSION = "8";
|
||||
public static final String PROTOCOL_VERSION = "9";
|
||||
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();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
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.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -21,7 +19,6 @@ import java.util.List;
|
||||
public enum CampfireProvider implements IServerExtensionProvider<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");
|
||||
|
||||
@Override
|
||||
@@ -35,9 +32,8 @@ public enum CampfireProvider implements IServerExtensionProvider<ItemStack> {
|
||||
}
|
||||
stack = stack.copy();
|
||||
|
||||
int finalI = i;
|
||||
CustomData customData = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.update(tag -> tag.store(COOKING_TIME_CODEC, campfire.cookingTime[finalI] - campfire.cookingProgress[finalI]));
|
||||
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);
|
||||
|
||||
@@ -18,7 +18,7 @@ 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 ResourceLocation MC_CHISELED_BOOKSHELF = JadeProtocol.mc_id("shelf");
|
||||
|
||||
@Override
|
||||
public @Nullable ItemStack streamData(@NotNull BlockAccessor accessor) {
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
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.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");
|
||||
@@ -32,13 +37,34 @@ 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();
|
||||
// return getEntityName(entity, false); // TODO WTF THIS IS
|
||||
}
|
||||
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
|
||||
|
||||
@@ -11,13 +11,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;
|
||||
@@ -26,12 +26,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;
|
||||
};
|
||||
@@ -42,6 +38,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user