mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -10,8 +10,8 @@ import java.util.Queue;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
@@ -67,9 +67,9 @@ public class ChunkGenWorker implements IWorker
|
||||
return ret;
|
||||
}
|
||||
|
||||
public BaseComponent getStartMessage(CommandSourceStack sender)
|
||||
public MutableComponent getStartMessage(CommandSourceStack sender)
|
||||
{
|
||||
return new TranslatableComponent("commands.forge.gen.start", total, start.getX(), start.getZ(), dim);
|
||||
return Component.translatable("commands.forge.gen.start", total, start.getX(), start.getZ(), dim);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +107,7 @@ public class ChunkGenWorker implements IWorker
|
||||
|
||||
if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60*1000)
|
||||
{
|
||||
listener.sendSuccess(new TranslatableComponent("commands.forge.gen.progress", total - queue.size(), total), true);
|
||||
listener.sendSuccess(Component.translatable("commands.forge.gen.progress", total - queue.size(), total), true);
|
||||
lastNotification = 0;
|
||||
lastNotifcationTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class ChunkGenWorker implements IWorker
|
||||
|
||||
if (queue.size() == 0)
|
||||
{
|
||||
listener.sendSuccess(new TranslatableComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
|
||||
listener.sendSuccess(Component.translatable("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
|
||||
/* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
|
||||
if (keepingLoaded != null && !keepingLoaded)
|
||||
DimensionManager.keepLoaded(dim, false);
|
||||
|
||||
@@ -10,10 +10,9 @@ import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
|
||||
@@ -44,13 +43,13 @@ public class ConfigCommand {
|
||||
final String configFileName = ConfigTracker.INSTANCE.getConfigFileName(modId, type);
|
||||
if (configFileName != null) {
|
||||
File f = new File(configFileName);
|
||||
context.getSource().sendSuccess(new TranslatableComponent("commands.config.getwithtype",
|
||||
context.getSource().sendSuccess(Component.translatable("commands.config.getwithtype",
|
||||
modId, type,
|
||||
new TextComponent(f.getName()).withStyle(ChatFormatting.UNDERLINE).
|
||||
withStyle((style) -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, f.getAbsolutePath())))
|
||||
Component.literal(f.getName()).withStyle(ChatFormatting.UNDERLINE).
|
||||
withStyle((style) -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, f.getAbsolutePath())))
|
||||
), true);
|
||||
} else {
|
||||
context.getSource().sendSuccess(new TranslatableComponent("commands.config.noconfig", modId, type),
|
||||
context.getSource().sendSuccess(Component.translatable("commands.config.noconfig", modId, type),
|
||||
true);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -7,10 +7,9 @@ package net.minecraftforge.server.command;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@@ -29,7 +28,7 @@ class DimensionsCommand
|
||||
return Commands.literal("dimensions")
|
||||
.requires(cs->cs.hasPermission(0)) //permission
|
||||
.executes(ctx -> {
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.dimensions.list"), true);
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.dimensions.list"), true);
|
||||
final Registry<DimensionType> reg = ctx.getSource().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
|
||||
Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
|
||||
@@ -38,7 +37,7 @@ class DimensionsCommand
|
||||
}
|
||||
|
||||
types.keySet().stream().sorted().forEach(key -> {
|
||||
ctx.getSource().sendSuccess(new TextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
|
||||
ctx.getSource().sendSuccess(Component.literal(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
|
||||
@@ -23,11 +23,10 @@ import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
@@ -45,9 +44,9 @@ class EntityCommand
|
||||
|
||||
private static class EntityListCommand
|
||||
{
|
||||
private static final SimpleCommandExceptionType INVALID_FILTER = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.entity.list.invalid"));
|
||||
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> new TranslatableComponent("commands.forge.entity.list.invalidworld", dim));
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.entity.list.none"));
|
||||
private static final SimpleCommandExceptionType INVALID_FILTER = new SimpleCommandExceptionType(Component.translatable("commands.forge.entity.list.invalid"));
|
||||
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> Component.translatable("commands.forge.entity.list.invalidworld", dim));
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(Component.translatable("commands.forge.entity.list.none"));
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("list")
|
||||
@@ -77,7 +76,7 @@ class EntityCommand
|
||||
|
||||
Map<ResourceLocation, MutablePair<Integer, Map<ChunkPos, Integer>>> list = Maps.newHashMap();
|
||||
level.getEntities().getAll().forEach(e -> {
|
||||
MutablePair<Integer, Map<ChunkPos, Integer>> info = list.computeIfAbsent(e.getType().getRegistryName(), k -> MutablePair.of(0, Maps.newHashMap()));
|
||||
MutablePair<Integer, Map<ChunkPos, Integer>> info = list.computeIfAbsent(ForgeRegistries.ENTITIES.getKey(e.getType()), k -> MutablePair.of(0, Maps.newHashMap()));
|
||||
ChunkPos chunk = new ChunkPos(e.blockPosition());
|
||||
info.left++;
|
||||
info.right.put(chunk, info.right.getOrDefault(chunk, 0) + 1);
|
||||
@@ -90,7 +89,7 @@ class EntityCommand
|
||||
if (info == null)
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
sender.sendSuccess(new TranslatableComponent("commands.forge.entity.list.single.header", name, info.getLeft()), false);
|
||||
sender.sendSuccess(Component.translatable("commands.forge.entity.list.single.header", name, info.getLeft()), false);
|
||||
List<Map.Entry<ChunkPos, Integer>> toSort = new ArrayList<>();
|
||||
toSort.addAll(info.getRight().entrySet());
|
||||
toSort.sort((a, b) -> {
|
||||
@@ -104,7 +103,7 @@ class EntityCommand
|
||||
for (Map.Entry<ChunkPos, Integer> e : toSort)
|
||||
{
|
||||
if (limit-- == 0) break;
|
||||
sender.sendSuccess(new TextComponent(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z), false);
|
||||
sender.sendSuccess(Component.literal(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z), false);
|
||||
}
|
||||
return toSort.size();
|
||||
}
|
||||
@@ -130,8 +129,8 @@ class EntityCommand
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
int count = info.stream().mapToInt(Pair::getRight).sum();
|
||||
sender.sendSuccess(new TranslatableComponent("commands.forge.entity.list.multiple.header", count), false);
|
||||
info.forEach(e -> sender.sendSuccess(new TextComponent(" " + e.getValue() + ": " + e.getKey()), false));
|
||||
sender.sendSuccess(Component.translatable("commands.forge.entity.list.multiple.header", count), false);
|
||||
info.forEach(e -> sender.sendSuccess(Component.literal(" " + e.getValue() + ": " + e.getKey()), false));
|
||||
return info.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.ArgumentSerializer;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -26,7 +27,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
private static final Dynamic2CommandExceptionType INVALID_ENUM = new Dynamic2CommandExceptionType(
|
||||
(found, constants) -> new TranslatableComponent("commands.forge.arguments.enum.invalid", constants, found));
|
||||
(found, constants) -> Component.translatable("commands.forge.arguments.enum.invalid", constants, found));
|
||||
private final Class<T> enumClass;
|
||||
|
||||
public static <R extends Enum<R>> EnumArgument<R> enumArgument(Class<R> enumClass) {
|
||||
@@ -56,22 +57,22 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
return Stream.of(enumClass.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static class Serializer implements ArgumentSerializer<EnumArgument<?>>
|
||||
public static class Info<T extends Enum<T>> implements ArgumentTypeInfo<EnumArgument<T>, Info<T>.Template>
|
||||
{
|
||||
@Override
|
||||
public void serializeToNetwork(EnumArgument<?> argument, FriendlyByteBuf buffer)
|
||||
public void serializeToNetwork(Template template, FriendlyByteBuf buffer)
|
||||
{
|
||||
buffer.writeUtf(argument.enumClass.getName());
|
||||
buffer.writeUtf(template.enumClass.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public EnumArgument<?> deserializeFromNetwork(FriendlyByteBuf buffer)
|
||||
public Template deserializeFromNetwork(FriendlyByteBuf buffer)
|
||||
{
|
||||
try
|
||||
{
|
||||
String name = buffer.readUtf();
|
||||
return new EnumArgument(Class.forName(name));
|
||||
return new Template((Class<T>) Class.forName(name));
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
@@ -80,9 +81,37 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeToJson(EnumArgument<?> argument, JsonObject json)
|
||||
public void serializeToJson(Template template, JsonObject json)
|
||||
{
|
||||
json.addProperty("enum", argument.enumClass.getName());
|
||||
json.addProperty("enum", template.enumClass.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Template unpack(EnumArgument<T> argument)
|
||||
{
|
||||
return new Template(argument.enumClass);
|
||||
}
|
||||
|
||||
public class Template implements ArgumentTypeInfo.Template<EnumArgument<T>>
|
||||
{
|
||||
final Class<T> enumClass;
|
||||
|
||||
Template(Class<T> enumClass)
|
||||
{
|
||||
this.enumClass = enumClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumArgument<T> instantiate(CommandBuildContext p_223435_)
|
||||
{
|
||||
return new EnumArgument<>(this.enumClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentTypeInfo<EnumArgument<T>, ?> type()
|
||||
{
|
||||
return Info.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ package net.minecraftforge.server.command;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -20,7 +20,7 @@ class ModListCommand {
|
||||
return Commands.literal("mods")
|
||||
.requires(cs->cs.hasPermission(0)) //permission
|
||||
.executes(ctx -> {
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.mods.list",
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.mods.list",
|
||||
ModList.get().applyForEachModFile(modFile ->
|
||||
// locator - filename : firstmod (version) - numberofmods\n
|
||||
String.format(Locale.ROOT, "%s %s : %s (%s) - %d",
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@@ -35,7 +35,7 @@ class TPSCommand
|
||||
@SuppressWarnings("resource")
|
||||
double meanTickTime = mean(ctx.getSource().getServer().tickTimes) * 1.0E-6D;
|
||||
double meanTPS = Math.min(1000.0/meanTickTime, 20);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class TPSCommand
|
||||
final Registry<DimensionType> reg = cs.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
double worldTickTime = mean(times) * 1.0E-6D;
|
||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||
cs.sendSuccess(new TranslatableComponent("commands.forge.tps.summary.named", dim.dimension().location().toString(), reg.getKey(dim.dimensionType()), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
|
||||
cs.sendSuccess(Component.translatable("commands.forge.tps.summary.named", dim.dimension().location().toString(), reg.getKey(dim.dimensionType()), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -25,12 +25,7 @@ import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -67,11 +62,11 @@ class TagsCommand
|
||||
ResourceKey.createRegistryKey(new ResourceLocation("root"));
|
||||
|
||||
private static final DynamicCommandExceptionType UNKNOWN_REGISTRY = new DynamicCommandExceptionType(key ->
|
||||
new TranslatableComponent("commands.forge.tags.error.unknown_registry", key));
|
||||
Component.translatable("commands.forge.tags.error.unknown_registry", key));
|
||||
private static final Dynamic2CommandExceptionType UNKNOWN_TAG = new Dynamic2CommandExceptionType((tag, registry) ->
|
||||
new TranslatableComponent("commands.forge.tags.error.unknown_tag", tag, registry));
|
||||
Component.translatable("commands.forge.tags.error.unknown_tag", tag, registry));
|
||||
private static final Dynamic2CommandExceptionType UNKNOWN_ELEMENT = new Dynamic2CommandExceptionType((tag, registry) ->
|
||||
new TranslatableComponent("commands.forge.tags.error.unknown_element", tag, registry));
|
||||
Component.translatable("commands.forge.tags.error.unknown_element", tag, registry));
|
||||
|
||||
public static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
@@ -121,7 +116,7 @@ class TagsCommand
|
||||
final long tagCount = registry.getTags().count();
|
||||
|
||||
ctx.getSource().sendSuccess(createMessage(
|
||||
new TranslatableComponent("commands.forge.tags.registry_key", new TextComponent(registryKey.location().toString()).withStyle(ChatFormatting.GOLD)),
|
||||
Component.translatable("commands.forge.tags.registry_key", Component.literal(registryKey.location().toString()).withStyle(ChatFormatting.GOLD)),
|
||||
"commands.forge.tags.tag_count",
|
||||
"commands.forge.tags.copy_tag_names",
|
||||
tagCount,
|
||||
@@ -149,9 +144,9 @@ class TagsCommand
|
||||
.orElseThrow(() -> UNKNOWN_TAG.create(tagKey.location(), registryKey.location()));
|
||||
|
||||
ctx.getSource().sendSuccess(createMessage(
|
||||
new TranslatableComponent("commands.forge.tags.tag_key",
|
||||
new TextComponent(tagKey.registry().location().toString()).withStyle(ChatFormatting.GOLD),
|
||||
new TextComponent(tagKey.location().toString()).withStyle(ChatFormatting.DARK_GREEN)),
|
||||
Component.translatable("commands.forge.tags.tag_key",
|
||||
Component.literal(tagKey.registry().location().toString()).withStyle(ChatFormatting.GOLD),
|
||||
Component.literal(tagKey.location().toString()).withStyle(ChatFormatting.DARK_GREEN)),
|
||||
"commands.forge.tags.element_count",
|
||||
"commands.forge.tags.copy_element_names",
|
||||
tag.size(),
|
||||
@@ -179,9 +174,9 @@ class TagsCommand
|
||||
final long containingTagsCount = elementHolder.tags().count();
|
||||
|
||||
ctx.getSource().sendSuccess(createMessage(
|
||||
new TranslatableComponent("commands.forge.tags.element",
|
||||
new TextComponent(registryKey.location().toString()).withStyle(ChatFormatting.GOLD),
|
||||
new TextComponent(elementLocation.toString()).withStyle(ChatFormatting.YELLOW)),
|
||||
Component.translatable("commands.forge.tags.element",
|
||||
Component.literal(registryKey.location().toString()).withStyle(ChatFormatting.GOLD),
|
||||
Component.literal(elementLocation.toString()).withStyle(ChatFormatting.YELLOW)),
|
||||
"commands.forge.tags.containing_tag_count",
|
||||
"commands.forge.tags.copy_tag_names",
|
||||
containingTagsCount,
|
||||
@@ -193,7 +188,7 @@ class TagsCommand
|
||||
return (int) containingTagsCount;
|
||||
}
|
||||
|
||||
private static MutableComponent createMessage(final TranslatableComponent header,
|
||||
private static MutableComponent createMessage(final MutableComponent header,
|
||||
final String containsText,
|
||||
final String copyHoverText,
|
||||
final long count,
|
||||
@@ -205,26 +200,26 @@ class TagsCommand
|
||||
final long totalPages = (count - 1) / PAGE_SIZE + 1;
|
||||
final long actualPage = Mth.clamp(currentPage, 1, totalPages);
|
||||
|
||||
MutableComponent containsComponent = new TranslatableComponent(containsText, count);
|
||||
MutableComponent containsComponent = Component.translatable(containsText, count);
|
||||
if (count > 0) // Highlight the count text, make it clickable, and append page counters
|
||||
{
|
||||
containsComponent = ComponentUtils.wrapInSquareBrackets(containsComponent.withStyle(s -> s
|
||||
.withColor(ChatFormatting.GREEN)
|
||||
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, allElementNames))
|
||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new TranslatableComponent(copyHoverText)))));
|
||||
containsComponent = new TranslatableComponent("commands.forge.tags.page_info",
|
||||
Component.translatable(copyHoverText)))));
|
||||
containsComponent = Component.translatable("commands.forge.tags.page_info",
|
||||
containsComponent, actualPage, totalPages);
|
||||
}
|
||||
|
||||
final MutableComponent tagElements = new TextComponent("").append(containsComponent);
|
||||
final MutableComponent tagElements = Component.literal("").append(containsComponent);
|
||||
names.get()
|
||||
.sorted()
|
||||
.skip(PAGE_SIZE * (actualPage - 1))
|
||||
.limit(PAGE_SIZE)
|
||||
.map(TextComponent::new)
|
||||
.map(Component::literal)
|
||||
.map(t -> t.withStyle(elementColor))
|
||||
.map(t -> new TextComponent("\n - ").append(t))
|
||||
.map(t -> Component.translatable("\n - ").append(t))
|
||||
.forEach(tagElements::append);
|
||||
|
||||
return header.append("\n").append(tagElements);
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.network.ConnectionType;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -25,13 +25,13 @@ public class TextComponentHelper
|
||||
* Detects when sending to a vanilla client and falls back to sending english,
|
||||
* since they don't have the lang data necessary to translate on the client.
|
||||
*/
|
||||
public static BaseComponent createComponentTranslation(CommandSource source, final String translation, final Object... args)
|
||||
public static MutableComponent createComponentTranslation(CommandSource source, final String translation, final Object... args)
|
||||
{
|
||||
if (isVanillaClient(source))
|
||||
{
|
||||
return new TextComponent(String.format(Locale.ENGLISH, Language.getInstance().getOrDefault(translation), args));
|
||||
return Component.literal(String.format(Locale.ENGLISH, Language.getInstance().getOrDefault(translation), args));
|
||||
}
|
||||
return new TranslatableComponent(translation, args);
|
||||
return Component.translatable(translation, args);
|
||||
}
|
||||
|
||||
private static boolean isVanillaClient(CommandSource sender)
|
||||
|
||||
@@ -21,7 +21,7 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.server.timings.ForgeTimings;
|
||||
import net.minecraftforge.server.timings.TimeTracker;
|
||||
|
||||
@@ -51,7 +51,7 @@ class TrackCommand
|
||||
int duration = IntegerArgumentType.getInteger(ctx, "duration");
|
||||
TimeTracker.BLOCK_ENTITY_UPDATE.reset();
|
||||
TimeTracker.BLOCK_ENTITY_UPDATE.enable(duration);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.be.enabled", duration), true);
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.tracking.be.enabled", duration), true);
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
@@ -62,7 +62,7 @@ class TrackCommand
|
||||
int duration = IntegerArgumentType.getInteger(ctx, "duration");
|
||||
TimeTracker.ENTITY_UPDATE.reset();
|
||||
TimeTracker.ENTITY_UPDATE.enable(duration);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.entity.enabled", duration), true);
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.tracking.entity.enabled", duration), true);
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
@@ -79,14 +79,14 @@ class TrackCommand
|
||||
.then(Commands.literal("te")
|
||||
.executes(ctx -> {
|
||||
TimeTracker.BLOCK_ENTITY_UPDATE.reset();
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.be.reset"), true);
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.tracking.be.reset"), true);
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
.then(Commands.literal("entity")
|
||||
.executes(ctx -> {
|
||||
TimeTracker.ENTITY_UPDATE.reset();
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.entity.reset"), true);
|
||||
ctx.getSource().sendSuccess(Component.translatable("commands.forge.tracking.entity.reset"), true);
|
||||
return 0;
|
||||
})
|
||||
);
|
||||
@@ -116,7 +116,7 @@ class TrackCommand
|
||||
List<ForgeTimings<T>> timingsList = getSortedTimings(tracker);
|
||||
if (timingsList.isEmpty())
|
||||
{
|
||||
source.sendSuccess(new TranslatableComponent("commands.forge.tracking.no_data"), true);
|
||||
source.sendSuccess(Component.translatable("commands.forge.tracking.no_data"), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -137,13 +137,13 @@ class TrackCommand
|
||||
{
|
||||
Entity entity = data.getObject().get();
|
||||
if (entity == null)
|
||||
return new TranslatableComponent("commands.forge.tracking.invalid");
|
||||
return Component.translatable("commands.forge.tracking.invalid");
|
||||
|
||||
BlockPos pos = entity.blockPosition();
|
||||
double averageTimings = data.getAverageTimings();
|
||||
String tickTime = (averageTimings > 1000 ? TIME_FORMAT.format(averageTimings / 1000) : TIME_FORMAT.format(averageTimings)) + (averageTimings < 1000 ? "\u03bcs" : "ms");
|
||||
|
||||
return new TranslatableComponent("commands.forge.tracking.timing_entry", entity.getType().getRegistryName(), entity.level.dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
return Component.translatable("commands.forge.tracking.timing_entry", ForgeRegistries.ENTITIES.getKey(entity.getType()), entity.level.dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -155,15 +155,15 @@ class TrackCommand
|
||||
{
|
||||
return Commands.literal("te").executes(ctx -> TrackResults.execute(ctx.getSource(), TimeTracker.BLOCK_ENTITY_UPDATE, data ->
|
||||
{
|
||||
BlockEntity te = data.getObject().get();
|
||||
if (te == null)
|
||||
return new TranslatableComponent("commands.forge.tracking.invalid");
|
||||
BlockEntity be = data.getObject().get();
|
||||
if (be == null)
|
||||
return Component.translatable("commands.forge.tracking.invalid");
|
||||
|
||||
BlockPos pos = te.getBlockPos();
|
||||
BlockPos pos = be.getBlockPos();
|
||||
|
||||
double averageTimings = data.getAverageTimings();
|
||||
String tickTime = (averageTimings > 1000 ? TIME_FORMAT.format(averageTimings / 1000) : TIME_FORMAT.format(averageTimings)) + (averageTimings < 1000 ? "\u03bcs" : "ms");
|
||||
return new TranslatableComponent("commands.forge.tracking.timing_entry", te.getType().getRegistryName(), te.getLevel().dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
return Component.translatable("commands.forge.tracking.timing_entry", ForgeRegistries.BLOCK_ENTITIES.getKey(be.getType()), be.getLevel().dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user