22w16b with massive Component changes

This commit is contained in:
gnembon committed 2022-04-21 00:26:39 +02:00
1 parent 8101abb431
commit 746c8548e9
31 files changed
+153 -162

No files matched your search

@@ -42,9 +42,7 @@ import net.fabricmc.loader.api.metadata.version.VersionPredicate;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
@@ -156,7 +154,7 @@ public class CarpetScriptHost extends ScriptHost
CarpetScriptHost cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(ctx.getSource());
List<String> argNames = funcSpec.function.getArguments();
if ((argNames.size()-funcSpec.args.size()) != paramNames.size())
throw new SimpleCommandExceptionType(new TextComponent("Target function "+funcSpec.function.getPrettyString()+" as wrong number of arguments, required "+paramNames.size()+", found "+argNames.size()+" with "+funcSpec.args.size()+" provided")).create();
throw new SimpleCommandExceptionType(Component.literal("Target function "+funcSpec.function.getPrettyString()+" as wrong number of arguments, required "+paramNames.size()+", found "+argNames.size()+" with "+funcSpec.args.size()+" provided")).create();
List<Value> args = new ArrayList<>(argNames.size());
for (String s : paramNames)
{
@@ -630,7 +628,7 @@ public class CarpetScriptHost extends ScriptHost
}
catch (CommandSyntaxException ignored)
{
throw new SimpleCommandExceptionType(new TextComponent("Cannot run player based apps without the player context")).create();
throw new SimpleCommandExceptionType(Component.literal("Cannot run player based apps without the player context")).create();
}
CarpetScriptHost userHost = (CarpetScriptHost)retrieveForExecution(player.getScoreboardName());
if (userHost.errorSnooper == null) userHost.setChatErrorSnooper(source);
@@ -1022,7 +1020,7 @@ public class CarpetScriptHost extends ScriptHost
}
/**
* <p>Creates a {@link BaseComponent} using {@link Messenger} that has the locals in the {@code line} snippet with a hover over
* <p>Creates a {@link Component} using {@link Messenger} that has the locals in the {@code line} snippet with a hover over
* tooltip with the value of the local at that location</p>
* @param line The line to find references to locals on
* @param context The {@link Context} to extract the locals from
@@ -1032,7 +1030,7 @@ public class CarpetScriptHost extends ScriptHost
* @implNote The implementation of this method is far from perfect, and won't detect actual references to variables, but try to find the strings
* and add the hover effect to anything that equals to any variable name, so short variable names may appear on random positions
*/
private static BaseComponent withLocals(String format, String line, Context context)
private static Component withLocals(String format, String line, Context context)
{
format += " ";
List<String> stringsToFormat = new ArrayList<>();
@@ -47,13 +47,11 @@ import net.minecraft.core.Rotations;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
import net.minecraft.network.protocol.game.ClientboundCustomSoundPacket;
@@ -551,7 +549,7 @@ public class Auxiliary {
else title = null; // Will never happen, just to make lambda happy
if (packetGetter == null)
{
Map<String, BaseComponent> map;
Map<String, Component> map;
if (actionString.equals("player_list_header"))
map = HUDController.scarpet_headers;
else
@@ -566,7 +564,7 @@ public class Auxiliary {
});
else
targetList.forEach(target -> {
map.put(target.getScoreboardName(), (BaseComponent) title);
map.put(target.getScoreboardName(), (MutableComponent) title);
total.getAndIncrement();
});
HUDController.update_hud(((CarpetContext)c).s.getServer(), targetList);
@@ -621,7 +619,7 @@ public class Auxiliary {
}
catch (Exception exc)
{
return ListValue.of(Value.NULL, ListValue.of(), new FormattedTextValue(new TextComponent(exc.getMessage())));
return ListValue.of(Value.NULL, ListValue.of(), new FormattedTextValue(Component.literal(exc.getMessage())));
}
});
@@ -22,7 +22,6 @@ import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.server.bossevents.CustomBossEvent;
@@ -152,7 +151,7 @@ public class Scoreboards {
return Value.FALSE;
}
scoreboard.addObjective(objectiveName, criterion, new TextComponent(objectiveName), criterion.getDefaultRenderType());
scoreboard.addObjective(objectiveName, criterion, Component.literal(objectiveName), criterion.getDefaultRenderType());
return Value.TRUE;
});
@@ -409,7 +408,7 @@ public class Scoreboards {
if(lv.size() == 1)
{
if(bossBarManager.get(identifier) != null) return Value.FALSE;
return StringValue.of(bossBarManager.create(identifier,new TextComponent(id)).getTextId().toString());
return StringValue.of(bossBarManager.create(identifier,Component.literal(id)).getTextId().toString());
}
String property = lv.get(1).getString();
@@ -95,7 +95,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.commands.BossBarCommands;
@@ -111,7 +111,7 @@ public abstract class CommandArgument
{
public static CommandSyntaxException error(String text)
{
return new SimpleCommandExceptionType(new TextComponent(text)).create();
return new SimpleCommandExceptionType(Component.literal(text)).create();
}
private static final List<? extends CommandArgument> baseTypes = Lists.newArrayList(
@@ -459,7 +459,7 @@ public abstract class CommandArgument
if (!caseSensitive) choseValue = choseValue.toLowerCase(Locale.ROOT);
if (!validOptions.isEmpty() && !validOptions.contains(choseValue))
{
throw new SimpleCommandExceptionType(new TextComponent("Incorrect value for "+param+": "+choseValue+" for custom type "+suffix)).create();
throw new SimpleCommandExceptionType(Component.literal("Incorrect value for "+param+": "+choseValue+" for custom type "+suffix)).create();
}
return StringValue.of(choseValue);
}
@@ -610,7 +610,7 @@ public abstract class CommandArgument
if (!single) return ListValue.wrap(founds.stream().map(EntityValue::new).collect(Collectors.toList()));
if (founds.size() == 0) return Value.NULL;
if (founds.size() == 1) return new EntityValue(founds.iterator().next());
throw new SimpleCommandExceptionType(new TextComponent("Multiple entities returned while only one was requested"+" for custom type "+suffix)).create();
throw new SimpleCommandExceptionType(Component.literal("Multiple entities returned while only one was requested"+" for custom type "+suffix)).create();
}
@Override
@@ -651,7 +651,7 @@ public abstract class CommandArgument
int size = profiles.size();
if (size == 0) return Value.NULL;
if (size == 1) return StringValue.of(profiles.iterator().next().getName());
throw new SimpleCommandExceptionType(new TextComponent("Multiple game profiles returned while only one was requested"+" for custom type "+suffix)).create();
throw new SimpleCommandExceptionType(Component.literal("Multiple game profiles returned while only one was requested"+" for custom type "+suffix)).create();
}
@Override
@@ -692,7 +692,7 @@ public abstract class CommandArgument
int size = holders.size();
if (size == 0) return Value.NULL;
if (size == 1) return StringValue.of(holders.iterator().next());
throw new SimpleCommandExceptionType(new TextComponent("Multiple score holders returned while only one was requested"+" for custom type "+suffix)).create();
throw new SimpleCommandExceptionType(Component.literal("Multiple score holders returned while only one was requested"+" for custom type "+suffix)).create();
}
@Override
@@ -767,7 +767,7 @@ public abstract class CommandArgument
ResourceLocation choseValue = ResourceLocationArgument.getId(context, param);
if (!validOptions.isEmpty() && !validOptions.contains(choseValue))
{
throw new SimpleCommandExceptionType(new TextComponent("Incorrect value for "+param+": "+choseValue+" for custom type "+suffix)).create();
throw new SimpleCommandExceptionType(Component.literal("Incorrect value for "+param+": "+choseValue+" for custom type "+suffix)).create();
}
return ValueConversions.of(choseValue);
}
@@ -957,7 +957,7 @@ public abstract class CommandArgument
int slot = net.minecraft.commands.arguments.SlotArgument.getSlot(context, param);
if (restrict != null && !RESTRICTED_CONTAINERS.get(restrict).numericalIds().contains(slot))
{
throw new SimpleCommandExceptionType(new TextComponent("Incorrect slot restricted to "+restrict+" for custom type "+suffix)).create();
throw new SimpleCommandExceptionType(Component.literal("Incorrect slot restricted to "+restrict+" for custom type "+suffix)).create();
}
return ValueConversions.ofVanillaSlotResult(slot);
}
@@ -32,7 +32,6 @@ import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
@@ -937,7 +936,7 @@ public class ShapeDispatcher
public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
{
if (!(value instanceof FormattedTextValue))
value = new FormattedTextValue(new TextComponent(value.getString()));
value = new FormattedTextValue(Component.literal(value.getString()));
return value;
}
@@ -945,7 +944,7 @@ public class ShapeDispatcher
public Tag toTag(Value value)
{
if (!(value instanceof FormattedTextValue))
value = new FormattedTextValue(new TextComponent(value.getString()));
value = new FormattedTextValue(Component.literal(value.getString()));
return StringTag.valueOf(((FormattedTextValue)value).serialize());
}
@@ -3,9 +3,8 @@ package carpet.script.value;
import com.google.gson.JsonElement;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.BaseComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.MutableComponent;
public class FormattedTextValue extends StringValue
{
@@ -17,16 +16,16 @@ public class FormattedTextValue extends StringValue
}
public static Value combine(Value left, Value right) {
BaseComponent text;
MutableComponent text;
if (left instanceof FormattedTextValue)
{
text = (BaseComponent) ((FormattedTextValue) left).getText().copy();
text = ((FormattedTextValue) left).getText().copy();
}
else
{
if (left.isNull())
return right;
text = new TextComponent(left.getString());
text = Component.literal(left.getString());
}
if (right instanceof FormattedTextValue)
@@ -103,7 +102,7 @@ public class FormattedTextValue extends StringValue
}
public static Component getTextByValue(Value value) {
return (value instanceof FormattedTextValue) ? ((FormattedTextValue) value).getText() : new TextComponent(value.getString());
return (value instanceof FormattedTextValue) ? ((FormattedTextValue) value).getText() : Component.literal(value.getString());
}
}