Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entity conversion #1

Merged
merged 4 commits into from
May 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add logging and remove id from upgraded data
jpenilla committed May 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 03ebea00e1f9774068fcb4dc7f19390ee843cbc1
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import ca.spottedleaf.dataconverter.util.CommandArgumentUpgrader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.ArrayList;
import net.minecraft.ResourceLocationException;
import net.minecraft.SharedConstants;
import net.minecraft.commands.arguments.ComponentArgument;
import net.minecraft.commands.arguments.item.ItemArgument;
@@ -60,21 +61,28 @@ public String upgradeComponentArgument(final String input) {

@Override
public String upgradeEntity(final String entityType, final String nbt) {
LOGGER.debug("Upgrading entity; type: '{}', nbt: '{}'", entityType, nbt);
final ResourceLocation id;
final CompoundTag tag;
try {
id = new ResourceLocation(entityType);
tag = TagParser.parseTag(nbt);
} catch (final CommandSyntaxException e) {
id = new ResourceLocation(entityType);
tag = TagParser.parseTag(nbt);
} catch (final CommandSyntaxException | ResourceLocationException e) {
LOGGER.debug("Exception upgrading entity; type: '{}', nbt: '{}'", entityType, nbt, e);
return e.getMessage();
}

tag.putString("id", id.toString());
return new SnbtPrinterTagVisitor("", 0, new ArrayList<>()).visit(
MCDataConverter.convertTag(
MCTypeRegistry.ENTITY,
tag,
3700, SharedConstants.getCurrentVersion().getDataVersion().getVersion()
)
final CompoundTag convertedTag = MCDataConverter.convertTag(
MCTypeRegistry.ENTITY,
tag,
3700, SharedConstants.getCurrentVersion().getDataVersion().getVersion()
);
convertedTag.remove("id");

final SnbtPrinterTagVisitor visitor = new SnbtPrinterTagVisitor("", 0, new ArrayList<>());
final String upgradedNbt = visitor.visit(convertedTag);
LOGGER.debug("Upgraded entity; type: '{}', nbt: '{}' -> '{}'", entityType, nbt, upgradedNbt);
return upgradedNbt;
}
}