Skip to content

Commit

Permalink
Fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Jul 1, 2024
1 parent 884ab80 commit 31447cb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public interface EnchantmentType extends MappedEntity, CopyableEntity<EnchantmentType> {

Component getDescription();
Expand All @@ -46,17 +48,20 @@ static EnchantmentType decode(NBT nbt, ClientVersion version, @Nullable TypesBui
NBTCompound compound = (NBTCompound) nbt;
Component description = AdventureSerializer.fromNbt(compound.getTagOrThrow("description"));
EnchantmentDefinition definition = EnchantmentDefinition.decode(compound, version, data);
MappedEntitySet<EnchantmentType> exclusiveSet = MappedEntitySet.decode(
compound.getTagOrThrow("exclusive_set"), version, EnchantmentTypes.getRegistry());
IComponentMap effects = StaticComponentMap.EMPTY;//IComponentMap.decode(compound.getTagOrThrow("effects"), version, ); FIXME
MappedEntitySet<EnchantmentType> exclusiveSet = Optional.ofNullable(compound.getTagOrNull("exclusive_set"))
.map(tag -> MappedEntitySet.decode(tag, version, EnchantmentTypes.getRegistry())) // TODO use user registry
.orElseGet(MappedEntitySet::createEmpty);
IComponentMap effects = StaticComponentMap.EMPTY;//IComponentMap.decode(compound.getTagOrThrow("effects"), version, ); FIXME (OPTIONAL)
return new StaticEnchantmentType(data, description, definition, exclusiveSet, effects);
}

static NBT encode(EnchantmentType type, ClientVersion version) {
NBTCompound compound = (NBTCompound) EnchantmentDefinition.encode(type.getDefinition(), version);
compound.setTag("description", AdventureSerializer.toNbt(type.getDescription()));
compound.setTag("exclusive_set", MappedEntitySet.encode(type.getExclusiveSet(), version));
// compound.setTag("effects", IComponentMap.encode(type.getEffects(), version)); FIXME
if (!type.getExclusiveSet().isEmpty()) {
compound.setTag("exclusive_set", MappedEntitySet.encode(type.getExclusiveSet(), version));
}
// compound.setTag("effects", IComponentMap.encode(type.getEffects(), version)); FIXME (OPTIONAL)
return compound;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ public final class EnchantmentTypes {

static {
ENCHANTMENT_DATA = new HashMap<>();
NBTCompound dataTag = MappingHelper.decompress("mappings/enchantment_type_data.json");
NBTCompound dataTag = MappingHelper.decompress("mappings/enchantment/enchantment_type_data");
for (Map.Entry<String, NBT> entry : dataTag.getTags().entrySet()) {
if (entry.getKey().equals("version")) {
continue; // skip version field
}
ResourceLocation enchantKey = new ResourceLocation(entry.getKey());
ENCHANTMENT_DATA.put(enchantKey, (NBTCompound) entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public MappedEntitySet(
this.entities = entities;
}

public static <Z extends MappedEntity> MappedEntitySet<Z> createEmpty() {
return new MappedEntitySet<>(new ArrayList<>(0));
}

public static <Z extends MappedEntity> MappedEntitySet<Z> read(
PacketWrapper<?> wrapper, BiFunction<ClientVersion, Integer, Z> getter) {
int count = wrapper.readVarInt() - 1;
Expand Down Expand Up @@ -117,4 +121,16 @@ public static <Z extends MappedEntity> NBT encode(MappedEntitySet<Z> set, Client
}
return listTag;
}

public boolean isEmpty() {
return this.entities != null && this.entities.isEmpty();
}

public @Nullable ResourceLocation getTagKey() {
return this.tagKey;
}

public @Nullable List<T> getEntities() {
return this.entities;
}
}

0 comments on commit 31447cb

Please sign in to comment.