Skip to content

Commit

Permalink
feat!: update for 25w04a
Browse files Browse the repository at this point in the history
Notable changes:
- Several client related resources now are built as ClientAssets
- SmithingRecipes now require a base ingredient
- Hidden attributes for items is now in a separated component so Data
  needs to be fixed in several places
- GameProfile lookups seems to have changed, need to fix our cache
- Attack Events need to handle capturing the BlockDamage component
- Hidden Flags are a new component that uses component keys to hide
  tooltips.
  • Loading branch information
gabizou committed Jan 31, 2025
1 parent c64cb90 commit bdfd8fc
Show file tree
Hide file tree
Showing 39 changed files with 420 additions and 413 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mixinConfigs=mixins.sponge.accessors.json,mixins.sponge.api.json,mixins.sponge.c
mixins.sponge.tracker.json,mixins.sponge.ipforward.json,mixins.sponge.optimization.json
superClassChanges=common.superclasschange

minecraftVersion=25w03a
minecraftVersion=25w04a
recommendedVersion=0-SNAPSHOT

org.gradle.dependency.verification.console=verbose
Expand Down
8 changes: 8 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,14 @@
<sha256 value="4ec0ac4b4c9adeecccaa3af70d87234c6bdcaa1eb4c009f7c94c0bc8a08c32b0" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.mojang" name="authlib" version="6.0.58">
<artifact name="authlib-6.0.58.jar">
<sha256 value="7bea5444e83c8d343e11fb9e45939721f0db4321c5056ac846072e4a0bbe1321" origin="Generated by Gradle"/>
</artifact>
<artifact name="authlib-6.0.58.module">
<sha256 value="883f331c6fd4ef86ed78d7d8c5a1e6c479327dfc9ae23f0e491c15ac8359fc15" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.mojang" name="blocklist" version="1.0.10">
<artifact name="blocklist-1.0.10.jar">
<sha256 value="830bfd639c8db49236bbd8e45d3a2b8c96c56ff654a10118654958a6235d4c44" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
package org.spongepowered.common.accessor.entity.animal.frog;

import net.minecraft.core.Holder;
import net.minecraft.world.entity.animal.FrogVariant;
import net.minecraft.world.entity.animal.frog.Frog;
import net.minecraft.world.entity.animal.frog.FrogVariant;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
@Mixin(ItemEnchantments.class)
public interface ItemEnchantmentsAccessor {

@Accessor("showInTooltip") boolean accessor$showInTooltip();

@Accessor("enchantments") Object2IntOpenHashMap<Holder<Enchantment>> accessor$enchantments();

@Invoker("<init>") static ItemEnchantments invoker$new(Object2IntOpenHashMap<Holder<Enchantment>> $$0, boolean $$1) {
@Invoker("<init>") static ItemEnchantments invoker$new(Object2IntOpenHashMap<Holder<Enchantment>> $$0) {
throw new UntransformedInvokerError();
}

Expand Down
442 changes: 221 additions & 221 deletions src/accessors/resources/mixins.sponge.accessors.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public AdvancementTemplate build0() {
ItemStackUtil.fromSnapshotToNative(di.icon()),
SpongeAdventure.asVanilla(di.title()),
SpongeAdventure.asVanilla(di.description()),
Optional.ofNullable(this.backgroundPath),
// TODO - Define how we want to expose ClientResource that is a combo of resource location and asset location
// Optional.ofNullable(this.backgroundPath),
Optional.empty(),
(net.minecraft.advancements.AdvancementType) (Object) di.type(),
di.doesShowToast(),
di.doesAnnounceToChat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import net.kyori.adventure.nbt.api.BinaryTagHolder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.serializer.gson.LegacyHoverEventSerializer;
import net.kyori.adventure.text.serializer.json.LegacyHoverEventSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import net.kyori.adventure.util.Codec;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -43,7 +43,7 @@
@SuppressWarnings({"PatternValidation","deprecation"})
public final class NbtLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
public static final NbtLegacyHoverEventSerializer INSTANCE = new NbtLegacyHoverEventSerializer();
private static final Codec<CompoundTag, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.of(TagParser::parseTag, Tag::toString);
private static final Codec<CompoundTag, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.codec(TagParser::parseCompoundFully, Tag::toString);

static final String ITEM_TYPE = "id";
static final String ITEM_COUNT = "Count";
Expand All @@ -62,7 +62,7 @@ public HoverEvent.ShowItem deserializeShowItem(final Component input) throws IOE
try {
final CompoundTag contents = NbtLegacyHoverEventSerializer.SNBT_CODEC.decode(rawContent);
final CompoundTag tag = contents.getCompound(NbtLegacyHoverEventSerializer.ITEM_TAG);
return HoverEvent.ShowItem.of(
return HoverEvent.ShowItem.showItem(
Key.key(contents.getString(NbtLegacyHoverEventSerializer.ITEM_TYPE)),
contents.contains(NbtLegacyHoverEventSerializer.ITEM_COUNT) ? contents.getByte(NbtLegacyHoverEventSerializer.ITEM_COUNT) : 1,
tag.isEmpty() ? null : BinaryTagHolder.encode(tag, NbtLegacyHoverEventSerializer.SNBT_CODEC)
Expand All @@ -77,7 +77,7 @@ public HoverEvent.ShowItem deserializeShowItem(final Component input) throws IOE
final String raw = PlainTextComponentSerializer.plainText().serialize(input);
try {
final CompoundTag contents = NbtLegacyHoverEventSerializer.SNBT_CODEC.decode(raw);
return HoverEvent.ShowEntity.of(
return HoverEvent.ShowEntity.showEntity(
Key.key(contents.getString(NbtLegacyHoverEventSerializer.ENTITY_TYPE)),
UUID.fromString(contents.getString(NbtLegacyHoverEventSerializer.ENTITY_ID)),
componentCodec.decode(contents.getString(NbtLegacyHoverEventSerializer.ENTITY_NAME))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package org.spongepowered.common.adventure;

import com.mojang.brigadier.Message;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.PrimitiveCodec;
Expand Down Expand Up @@ -60,7 +59,6 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.translation.GlobalTranslator;
import net.kyori.adventure.util.Codec;
import net.kyori.adventure.util.TriState;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.arguments.selector.SelectorPattern;
Expand All @@ -71,8 +69,6 @@
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.HoverEvent.Action;
Expand Down Expand Up @@ -110,7 +106,6 @@
import org.spongepowered.common.bridge.world.BossEventBridge;
import org.spongepowered.common.launch.Launch;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -131,21 +126,6 @@
public final class SpongeAdventure {

public static final AttributeKey<Locale> CHANNEL_LOCALE = AttributeKey.newInstance("sponge:locale");
public static final Codec<CompoundTag, String, IOException, IOException> NBT_CODEC = new Codec<CompoundTag, String, IOException, IOException>() {
@Override
public @NonNull CompoundTag decode(final @NonNull String encoded) throws IOException {
try {
return TagParser.parseTag(encoded);
} catch (final CommandSyntaxException e) {
throw new IOException(e);
}
}

@Override
public @NonNull String encode(final @NonNull CompoundTag decoded) {
return decoded.toString();
}
};

public static final PrimitiveCodec<Component> STRING_CODEC = new PrimitiveCodec<Component>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public BlockSnapshot withLocation(final ServerLocation location) {
return SpongeBlockSnapshot.BuilderImpl.pooled().from(this).position(location.blockPosition()).world(location.worldKey()).build();
}

@SuppressWarnings("deprecation")
@Override
public boolean restore(final boolean force, final BlockChangeFlag flag) {
// TODO - rewrite with the PhaseTracker being the hook or use SpongeImplHooks to do the restore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public interface SmithingRecipeBridge extends RecipeResultBridge {

Optional<Ingredient> bridge$template();
Optional<Ingredient> bridge$base();
Ingredient bridge$base();
Optional<Ingredient> bridge$addition();

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.kyori.adventure.text.Component;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.TagParser;
import net.minecraft.resources.ResourceLocation;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down Expand Up @@ -192,7 +193,7 @@ public boolean parseBoolean() throws ArgumentParseException {
public String parseNBTString() throws ArgumentParseException {
final int startCursor = this.getCursor();
try {
new TagParser(this).readStruct();
TagParser.parseAsArgument(NbtOps.INSTANCE, this);
} catch (final CommandSyntaxException ex) {
this.setCursor(startCursor);
throw new ArgumentParseException(
Expand All @@ -208,7 +209,7 @@ public String parseNBTString() throws ArgumentParseException {
@Override
public DataContainer parseDataContainer() throws ArgumentParseException {
try {
return NBTTranslator.INSTANCE.translate(new TagParser(this).readStruct());
return NBTTranslator.INSTANCE.translate(TagParser.parseCompoundAsArgument(this));
} catch (final CommandSyntaxException e) {
throw this.createException(SpongeAdventure.asAdventure(e.getRawMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static BufferedReader createBufferedReader(final Reader reader) {
@Override
public DataContainer read(final String input) throws InvalidDataException, IOException {
try {
return NBTTranslator.INSTANCE.translate(TagParser.parseTag(input));
return NBTTranslator.INSTANCE.translate(TagParser.parseCompoundFully(input));
} catch (final CommandSyntaxException e) {
throw new InvalidDataException(e);
}
Expand All @@ -65,7 +65,7 @@ public DataContainer read(final String input) throws InvalidDataException, IOExc
public DataContainer readFrom(final Reader input) throws InvalidDataException {
try {
return NBTTranslator.INSTANCE.translate(
TagParser.parseTag(SNBTDataFormat.createBufferedReader(input).lines().collect(Collectors.joining("\n"))));
TagParser.parseCompoundFully(SNBTDataFormat.createBufferedReader(input).lines().collect(Collectors.joining("\n"))));
} catch (final CommandSyntaxException e) {
throw new InvalidDataException(e);
}
Expand All @@ -74,7 +74,7 @@ public DataContainer readFrom(final Reader input) throws InvalidDataException {
@Override
public DataContainer readFrom(final InputStream input) throws InvalidDataFormatException {
try {
return NBTTranslator.INSTANCE.translate(TagParser.parseTag(
return NBTTranslator.INSTANCE.translate(TagParser.parseCompoundFully(
new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"))));
} catch (final CommandSyntaxException e) {
throw new InvalidDataException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public static void register(final DataProviderRegistrator registrator) {
.get(Cat::isLying)
.set(Cat::setLying)
.create(Keys.IS_PURRING)
.get(h -> {
throw new MissingImplementationException("CatData", "IS_PURRING::getter");
})
.get(h -> h.isLying() || ((CatAccessor) h).invoker$isRelaxStateOne())
.set((h, v) -> {
throw new MissingImplementationException("CatData", "IS_PURRING::setter");
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*/
package org.spongepowered.common.data.provider.entity;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.animal.FrogVariant;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.frog.Frog;
import net.minecraft.world.entity.animal.frog.FrogVariant;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.FrogType;
import org.spongepowered.common.accessor.entity.animal.frog.FrogAccessor;
Expand All @@ -43,7 +43,12 @@ public static void register(final DataProviderRegistrator registrator) {
.asMutable(Frog.class)
.create(Keys.FROG_TYPE)
.get(h -> (FrogType) (Object) h.getVariant().value())
.set((h, v) -> ((FrogAccessor) h).invoker$setVariant(BuiltInRegistries.FROG_VARIANT.wrapAsHolder((FrogVariant) (Object) v)));
.set((h, v) -> {
final var holder = h.level().registryAccess().lookup(Registries.FROG_VARIANT)
.orElseThrow()
.wrapAsHolder(((FrogVariant) (Object) v));
((FrogAccessor) h).invoker$setVariant(holder);
});
}
// @formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void register(final DataProviderRegistrator registrator) {
}
})
.create(Keys.PIG_TYPE)
.get(p -> (PigType) p.getVariant().value())
.get(p -> (PigType) (Object) p.getVariant().value())
.setAnd((h, v) -> h.level().registryAccess().lookup(Registries.PIG_VARIANT)
.map(r -> {
var newPigType = r.wrapAsHolder((PigVariant) (Object) v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.entity.projectile.AbstractThrownPotion;
import net.minecraft.world.item.alchemy.PotionContents;
import org.apache.commons.lang3.stream.Streams;
import org.spongepowered.api.data.Keys;
Expand All @@ -41,7 +41,7 @@ private PotionData() {
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator
.asMutable(ThrownPotion.class)
.asMutable(AbstractThrownPotion.class)
.create(Keys.POTION_EFFECTS)
.get(h -> Streams.of(h.getItem().getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).getAllEffects()).map(PotionEffect.class::cast).toList())
.set((h, v) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.world.item.AdventureModePredicate;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.data.Keys;
import org.spongepowered.common.accessor.world.item.AdventureModePredicateAccessor;
Expand All @@ -53,14 +54,14 @@ public static void register(final DataProviderRegistrator registrator) {
.asMutable(ItemStack.class)
.create(Keys.BREAKABLE_BLOCK_TYPES)
.get(h -> BlockTypeItemStackData.get(h, DataComponents.CAN_BREAK))
.set((h, v) -> BlockTypeItemStackData.set(h, DataComponents.CAN_BREAK, v))
.setAnd((h, v) -> BlockTypeItemStackData.set(h, DataComponents.CAN_BREAK, v))
.create(Keys.PLACEABLE_BLOCK_TYPES)
.get(h -> BlockTypeItemStackData.get(h, DataComponents.CAN_PLACE_ON))
.set((h, v) -> BlockTypeItemStackData.set(h, DataComponents.CAN_PLACE_ON, v));
.setAnd((h, v) -> BlockTypeItemStackData.set(h, DataComponents.CAN_PLACE_ON, v));
}
// @formatter:on

private static Set<BlockType> get(final ItemStack stack, final DataComponentType<AdventureModePredicate> component) {
private static @Nullable Set<BlockType> get(final ItemStack stack, final DataComponentType<AdventureModePredicate> component) {
// TODO change API type to predicates
final AdventureModePredicate predicate = stack.get(component);
if (predicate != null) {
Expand All @@ -81,7 +82,7 @@ private static boolean set(final ItemStack stack, final DataComponentType<Advent
final AdventureModePredicate prev = stack.get(component);
final var holderGetter = BuiltInRegistries.BLOCK;
final BlockPredicate blockPredicate = BlockPredicate.Builder.block().of(holderGetter, value.stream().map(Block.class::cast).toList()).build();
final AdventureModePredicate predicate = new AdventureModePredicate(List.of(blockPredicate), prev == null || prev.showInTooltip());
final AdventureModePredicate predicate = new AdventureModePredicate(List.of(blockPredicate));
stack.set(component, predicate);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.LodestoneTracker;
import net.minecraft.world.level.Level;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.server.ServerWorld;
Expand All @@ -51,7 +52,7 @@ static void register(final DataProviderRegistrator registrator) {
.asMutable(ItemStack.class)
.create(Keys.LODESTONE)
.get(stack -> {
final LodestoneTracker component = stack.get(DataComponents.LODESTONE_TRACKER);
final @Nullable LodestoneTracker component = stack.get(DataComponents.LODESTONE_TRACKER);
if (component == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void register(final DataProviderRegistrator registrator) {
.asMutable(ItemStack.class)
.create(Keys.COLOR)
.get(h -> h.has(DataComponents.DYED_COLOR) ? Color.ofRgb(h.get(DataComponents.DYED_COLOR).rgb()) : null)
.set((h, v) -> h.update(DataComponents.DYED_COLOR, new DyedItemColor(0, true), prev -> new DyedItemColor(v.rgb(), prev.showInTooltip())))
.set((h, v) -> h.update(DataComponents.DYED_COLOR, new DyedItemColor(0), prev -> new DyedItemColor(v.rgb())))
.delete(h -> h.set(DataComponents.DYED_COLOR, null))
.supports(h -> h.is(ItemTags.DYEABLE));
}
Expand Down
Loading

0 comments on commit bdfd8fc

Please sign in to comment.