3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-19 09:20:08 +01:00

Names via Translation (#1268)

* Deprecate BiomeRegistry, etc.

* Update some libraries, e.g. text

* Move to new translation renderer

* Revert "Deprecate BiomeRegistry, etc."

This reverts commit 59a5d6c92aec52739a8dc68ac3d23898af7593dd.

This was not a good idea for potential mod shenanigans.

* Move BiomeData#getName to BiomeRegistry, use i18n

* Use getRichName instead of getName

* Implement getRichName for NullBiomeRegistry

* Add getRichName for blocks

* Relocate net.kyori.minecraft

* Update adapters for getRichBlockName

* Add getRichName for items

* Update adapters for getRichItemName

* Update adapters JAR for merge

(cherry picked from commit cfd26253b6fb59ff6c65a0157a6780be7db4ea5a)
Dieser Commit ist enthalten in:
Octavia Togami 2020-03-23 23:47:27 +01:00 committet von Hannes Greule
Ursprung 008238c686
Commit 92f8776796
28 geänderte Dateien mit 317 neuen und 176 gelöschten Zeilen

Datei anzeigen

@ -25,6 +25,11 @@ fun Project.applyLibrariesConfiguration() {
group = "${rootProject.group}.worldedit-libs"
val relocations = mapOf(
"net.kyori.text" to "com.sk89q.worldedit.util.formatting.text",
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori"
)
tasks.register<ShadowJar>("jar") {
configurations = listOf(project.configurations["shade"])
archiveClassifier.set("")
@ -36,13 +41,15 @@ fun Project.applyLibrariesConfiguration() {
exclude(dependency("org.slf4j:slf4j-api"))
}
relocate("net.kyori.text", "com.sk89q.worldedit.util.formatting.text")
relocations.forEach { (from, to) ->
relocate(from, to)
}
}
val altConfigFiles = { artifactType: String ->
val deps = configurations["shade"].incoming.dependencies
.filterIsInstance<ModuleDependency>()
.map { it.copy() }
.map { dependency: ModuleDependency ->
.map { dependency ->
dependency.artifact {
name = dependency.name
type = artifactType
@ -61,13 +68,15 @@ fun Project.applyLibrariesConfiguration() {
from({
altConfigFiles("sources")
})
val filePattern = Regex("(.*)net/kyori/text((?:/|$).*)")
val textPattern = Regex("net\\.kyori\\.text")
eachFile {
filter {
it.replaceFirst(textPattern, "com.sk89q.worldedit.util.formatting.text")
relocations.forEach { (from, to) ->
val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)")
val textPattern = Regex.fromLiteral(from)
eachFile {
filter {
it.replaceFirst(textPattern, to)
}
path = path.replaceFirst(filePattern, "$1${to.replace('.', '/')}$2")
}
path = path.replaceFirst(filePattern, "$1com/sk89q/worldedit/util/formatting/text$2")
}
archiveClassifier.set("sources")
}

Datei anzeigen

@ -19,6 +19,9 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.translation.TranslationManager;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
@ -34,6 +37,14 @@ class BukkitBiomeRegistry implements BiomeRegistry {
BukkitBiomeRegistry() {
}
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(
TranslationManager.makeTranslationKey("biome", biomeType.getId())
);
}
@Deprecated
@Nullable
@Override
public BiomeData getData(BiomeType biome) {

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
@ -39,6 +40,14 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
private BukkitBlockMaterial[] materialMap;
@Override
public Component getRichName(BlockType blockType) {
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichBlockName(blockType);
}
return super.getRichName(blockType);
}
@Nullable
@Override
public BlockMaterial getMaterial(BlockType blockType) {

Datei anzeigen

@ -19,13 +19,32 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.Collection;
public class BukkitItemRegistry extends BundledItemRegistry {
class BukkitItemRegistry extends BundledItemRegistry {
@Override
public Component getRichName(ItemType itemType) {
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichItemName(itemType);
}
return super.getRichName(itemType);
}
@Override
public Component getRichName(BaseItemStack itemStack) {
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichItemName(itemStack);
}
return super.getRichName(itemStack);
}
@Override
public Collection<String> values() {
ArrayList<String> values = new ArrayList<>();

Datei anzeigen

@ -22,7 +22,6 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
import com.sk89q.worldedit.world.registry.BundledRegistries;
import com.sk89q.worldedit.world.registry.EntityRegistry;
import com.sk89q.worldedit.world.registry.ItemCategoryRegistry;
@ -35,8 +34,8 @@ class BukkitRegistries extends BundledRegistries {
private static final BukkitRegistries INSTANCE = new BukkitRegistries();
private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
private final ItemRegistry itemRegistry = new BukkitItemRegistry();
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
private final ItemRegistry itemRegistry = new BukkitItemRegistry();
private final EntityRegistry entityRegistry = new BukkitEntityRegistry();
private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry();
private final ItemCategoryRegistry itemCategoryRegistry = new BukkitItemCategoryRegistry();
@ -57,6 +56,11 @@ class BukkitRegistries extends BundledRegistries {
return biomeRegistry;
}
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
@Override
public BlockCategoryRegistry getBlockCategoryRegistry() {
return blockCategoryRegistry;
@ -81,8 +85,4 @@ class BukkitRegistries extends BundledRegistries {
return INSTANCE;
}
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
}

Datei anzeigen

@ -36,12 +36,14 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import org.bukkit.Location;
import org.bukkit.World;
@ -52,10 +54,10 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.OptionalInt;
import java.util.Set;
import javax.annotation.Nullable;
/**
* An interface for adapters of various Bukkit implementations.
@ -127,6 +129,30 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
@Nullable
Entity createEntity(Location location, BaseEntity state);
/**
* Gets the name for the given block.
*
* @param blockType the block
* @return The name
*/
Component getRichBlockName(BlockType blockType);
/**
* Gets the name for the given item.
*
* @param itemType the item
* @return The name
*/
Component getRichItemName(ItemType itemType);
/**
* Gets the name for the given item stack.
*
* @param itemStack the item stack
* @return The name
*/
Component getRichItemName(BaseItemStack itemStack);
/**
* Get a map of {@code string -> property}.
*

Datei anzeigen

@ -591,15 +591,17 @@ public final class WorldEdit {
Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks();
if (!missingBlocks.isEmpty()) {
StringBuilder str = new StringBuilder();
TextComponent.Builder str = TextComponent.builder();
str.append("Missing these blocks: ");
int size = missingBlocks.size();
int i = 0;
for (Map.Entry<BlockType, Integer> blockTypeIntegerEntry : missingBlocks.entrySet()) {
str.append((blockTypeIntegerEntry.getKey()).getName());
str.append((blockTypeIntegerEntry.getKey()).getRichName());
str.append(" [Amt: ").append(blockTypeIntegerEntry.getValue()).append("]");
str.append(" [Amt: ")
.append(String.valueOf(blockTypeIntegerEntry.getValue()))
.append("]");
++i;
@ -608,7 +610,7 @@ public final class WorldEdit {
}
}
actor.printError(str.toString());
actor.printError(str.build());
}
}

Datei anzeigen

@ -20,6 +20,9 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.item.ItemType;
/**
@ -65,7 +68,7 @@ public class BaseItemStack extends BaseItem {
/**
* Get the number of items in the stack.
*
*
* @return the amount
*/
public int getAmount() {
@ -74,10 +77,15 @@ public class BaseItemStack extends BaseItem {
/**
* Set the amount of items in the stack.
*
*
* @param amount the amount to set
*/
public void setAmount(int amount) {
this.amount = amount;
}
public Component getRichName() {
return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getItemRegistry().getRichName(this);
}
}

Datei anzeigen

@ -49,7 +49,6 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.enginehub.piston.annotation.Command;
@ -87,23 +86,19 @@ public class BiomeCommands {
@ArgFlag(name = 'p', desc = "Page number.", def = "1")
int page) {
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
BiomeRegistry biomeRegistry =
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getBiomeRegistry();
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
PaginationBox paginationBox = PaginationBox
.fromStrings("Available Biomes", "/biomelist -p %page%",
BiomeType.REGISTRY.values().stream().map(biomeType -> {
String id = biomeType.getId();
final BiomeData data = biomeRegistry.getData(biomeType);
if (data != null) {
String name = data.getName();
return id + " (" + name + ")";
} else {
return id;
}
}).collect(Collectors.toList()));
return paginationBox.create(page);
PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%",
BiomeType.REGISTRY.values().stream()
.map(biomeType -> TextComponent.builder()
.append(biomeType.getId())
.append(" (")
.append(biomeRegistry.getRichName(biomeType))
.append(")")
.build())
.collect(Collectors.toList()));
return paginationBox.create(page);
}, (Component) null);
}
@ -150,14 +145,11 @@ public class BiomeCommands {
messageKey = "worldedit.biomeinfo.selection";
}
List<Component> components = biomes.stream().map(biome -> {
BiomeData data = biomeRegistry.getData(biome);
if (data != null) {
return TextComponent.of(data.getName()).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId())));
} else {
return TextComponent.of(biome.getId());
}
}).collect(Collectors.toList());
List<Component> components = biomes.stream().map(biome ->
biomeRegistry.getRichName(biome).hoverEvent(
HoverEvent.showText(TextComponent.of(biome.getId()))
)
).collect(Collectors.toList());
player.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
}

Datei anzeigen

@ -715,7 +715,7 @@ public class SelectionCommands {
final BlockState state = c.getID();
final BlockType blockType = state.getBlockType();
TextComponent blockName = TextComponent.of(blockType.getName(), TextColor.LIGHT_PURPLE);
Component blockName = blockType.getRichName().color(TextColor.LIGHT_PURPLE);
TextComponent toolTip;
if (separateStates && state != blockType.getDefaultState()) {
toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY);

Datei anzeigen

@ -78,7 +78,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
if (targetBlock != null) {
pattern = targetBlock;
player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", TextComponent.of(targetBlock.getBlockType().getName())));
player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", targetBlock.getBlockType().getRichName()));
}
return true;

Datei anzeigen

@ -59,7 +59,7 @@ public class QueryTool implements BlockTool {
TextComponent.Builder builder = TextComponent.builder();
builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE));
builder.append(TextComponent.of(block.getBlockType().getName(), TextColor.YELLOW));
builder.append(block.getBlockType().getRichName().color(TextColor.YELLOW));
builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.blockstate.hover"))));
final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState());

Datei anzeigen

@ -36,6 +36,7 @@ import com.sk89q.worldedit.command.InsufficientArgumentsException;
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
@ -62,7 +63,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
}
private CommandException newCommandException(String message, Throwable cause) {
return new CommandException(TextComponent.of(String.valueOf(message)), cause, ImmutableList.of());
return newCommandException(TextComponent.of(String.valueOf(message)), cause);
}
private CommandException newCommandException(Component message, Throwable cause) {
return new CommandException(message, cause, ImmutableList.of());
}
@ExceptionMatch
@ -158,7 +163,13 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
@ExceptionMatch
public void convert(InvalidToolBindException e) throws CommandException {
throw newCommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage(), e);
throw newCommandException(
TextComponent.builder("Can't bind tool to ")
.append(e.getItemType().getRichName())
.append(": " + e.getMessage())
.build(),
e
);
}
@ExceptionMatch

Datei anzeigen

@ -21,17 +21,19 @@ package com.sk89q.worldedit.util.formatting.component;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.history.changeset.ChangeSet;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import java.util.stream.Collectors;
public abstract class PaginationBox extends MessageBox {
@ -145,46 +147,27 @@ public abstract class PaginationBox extends MessageBox {
return new ListPaginationBox(header, pageCommand, lines);
}
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, List<String> lines) {
return fromStrings(header, pageCommand, (Collection) lines);
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection<String> lines) {
return fromComponents(header, pageCommand, lines.stream()
.map(TextComponent::of)
.collect(Collectors.toList()));
}
public static class ListPaginationBox extends PaginationBox {
private final Collection lines;
private int iterIndex;
private Iterator iterator;
public static PaginationBox fromComponents(String header, @Nullable String pageCommand, Collection<Component> lines) {
return new ListPaginationBox(header, pageCommand, lines);
}
public ListPaginationBox(String header, String pageCommand, List<String> lines) {
this(header, pageCommand, (Collection) lines);
}
private static class ListPaginationBox extends PaginationBox {
private final List<Component> lines;
public ListPaginationBox(String header, String pageCommand, Collection lines) {
ListPaginationBox(String header, String pageCommand, Collection<Component> lines) {
super(header, pageCommand);
this.lines = lines;
}
@Override
public Component getComponent(int number) {
Object obj;
if (lines instanceof List) {
obj = ((List) lines).get(number);
} else {
if (iterator == null || iterIndex > number) {
iterator = lines.iterator();
iterIndex = 0;
}
do {
obj = iterator.next();
iterIndex++;
} while (iterIndex < number);
}
if (obj instanceof Supplier) {
obj = ((Supplier) obj).get();
}
if (obj instanceof Component) {
return (Component) obj;
}
return TextComponent.of(obj + "");
return lines.get(number);
}
@Override

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.biome;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
/**
* Provides information about a biome.
*
@ -32,6 +34,8 @@ public interface BiomeData {
* particular convention.
*
* @return the biome's name
* @deprecated This method does not work on the server.
* Use {@link BiomeRegistry#getRichName(BiomeType)}.
*/
@Deprecated
String getName();

Datei anzeigen

@ -33,6 +33,7 @@ import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
@ -96,6 +97,11 @@ public class BlockType implements Keyed, Pattern {
return this.id;
}
public Component getRichName() {
return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getBlockRegistry().getRichName(this);
}
public String getNamespace() {
String id = getId();
int i = id.indexOf(':');
@ -111,15 +117,11 @@ public class BlockType implements Keyed, Pattern {
* Gets the name of this block, or the ID if the name cannot be found.
*
* @return The name, or ID
* @deprecated The name is now translatable, use {@link #getRichName()}.
*/
@Deprecated
public String getName() {
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this);
if (name == null) {
return getId();
} else {
return name;
}
return getRichName().toString();
}
/*
@ -274,9 +276,7 @@ public class BlockType implements Keyed, Pattern {
/**
* Gets the legacy ID. Needed for legacy reasons.
*
* <p>
* DO NOT USE THIS.
* </p>
*
* @return legacy id or 0, if unknown
*/
@ -286,11 +286,39 @@ public class BlockType implements Keyed, Pattern {
return combinedId == null ? 0 : combinedId;
}
/**
* Gets the legacy data. Needed for legacy reasons.
*
* DO NOT USE THIS.
*
* @return legacy data or 0, if unknown
*/
@Deprecated
public int getLegacyId() {
return computeLegacy(0);
}
/**
* Gets the legacy data. Needed for legacy reasons.
*
* <p>
* DO NOT USE THIS.
* </p>
*
* @return legacy data or 0, if unknown
*/
@Deprecated
public int getLegacyData() {
return computeLegacy(1);
}
private int computeLegacy(int index) {
if (this.legacyCombinedId == null) {
this.legacyCombinedId = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
}
return index == 0 ? legacyCombinedId >> 4 : legacyCombinedId & 15;
}
/**
* The internal index of this type.
*
@ -336,25 +364,4 @@ public class BlockType implements Keyed, Pattern {
public SingleBlockTypeMask toMask(Extent extent) {
return new SingleBlockTypeMask(extent, this);
}
/**
* Gets the legacy data. Needed for legacy reasons.
*
* <p>
* DO NOT USE THIS.
* </p>
*
* @return legacy data or 0, if unknown
*/
@Deprecated
public int getLegacyData() {
return computeLegacy(1);
}
private int computeLegacy(int index) {
if (this.legacyCombinedId == null) {
this.legacyCombinedId = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
}
return index == 0 ? legacyCombinedId >> 4 : legacyCombinedId & 15;
}
}

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -29,11 +30,21 @@ import javax.annotation.Nullable;
*/
public interface BiomeRegistry {
/**
* Get the name of the biome, usually as a translatable component.
*
* @param biomeType the biome type
* @return the name of the biome
*/
Component getRichName(BiomeType biomeType);
/**
* Get data about a biome.
*
* @param biome the biome
* @return a data object or null if information is not known
* @deprecated This method no longer returns any useful information.
* Use {@link #getRichName(BiomeType)} for the name of the biome.
*/
@Deprecated
@Nullable

Datei anzeigen

@ -20,29 +20,41 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.OptionalInt;
import javax.annotation.Nullable;
/**
* Provides information on blocks and provides methods to create them.
*/
public interface BlockRegistry {
/**
* Gets the name for the given block.
*
* @param blockType the block
* @return The name
*/
Component getRichName(BlockType blockType);
/**
* Gets the name for the given block.
*
* @param blockType the block
* @return The name, or null if it's unknown
* @deprecated Names are now translatable, use {@link #getRichName(BlockType)}.
*/
@Deprecated
@Nullable
String getName(BlockType blockType);
default String getName(BlockType blockType) {
return getRichName(blockType).toString();
}
/**
* Get the material for the given block.

Datei anzeigen

@ -20,6 +20,10 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.translation.TranslationManager;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
@ -34,11 +38,19 @@ import javax.annotation.Nullable;
*/
public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override
public String getName(BlockType blockType) {
public Component getRichName(BlockType blockType) {
BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId());
return blockEntry != null ? blockEntry.localizedName : null;
if (blockEntry != null) {
// This is more likely to be "right", but not translated
// Some vanilla MC blocks have overrides so we need this name here
// Most platforms should be overriding this anyways, so it likely doesn't matter
// too much!
return TextComponent.of(blockEntry.localizedName);
}
return TranslatableComponent.of(
TranslationManager.makeTranslationKey("block", blockType.getId())
);
}
@Nullable

Datei anzeigen

@ -23,9 +23,9 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import javax.annotation.Nullable;
public interface ItemRegistry {

Datei anzeigen

@ -19,6 +19,9 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.translation.TranslationManager;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -35,6 +38,14 @@ public class NullBiomeRegistry implements BiomeRegistry {
public NullBiomeRegistry() {
}
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(
TranslationManager.makeTranslationKey("biome", biomeType.getId())
);
}
@Deprecated
@Nullable
@Override
public BiomeData getData(BiomeType biome) {

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.fabric;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome;
*/
class FabricBiomeRegistry implements BiomeRegistry {
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(FabricAdapter.adapt(biomeType).getTranslationKey());
}
@Deprecated
@Override
public BiomeData getData(BiomeType biome) {
return new FabricBiomeData(FabricAdapter.adapt(biome));
@ -37,6 +45,7 @@ class FabricBiomeRegistry implements BiomeRegistry {
/**
* Cached biome data information.
*/
@Deprecated
private static class FabricBiomeData implements BiomeData {
private final Biome biome;
@ -49,6 +58,7 @@ class FabricBiomeRegistry implements BiomeRegistry {
this.biome = biome;
}
@SuppressWarnings("deprecation")
@Override
public String getName() {
return biome.getName().asFormattedString();

Datei anzeigen

@ -20,17 +20,15 @@
package com.sk89q.worldedit.fabric;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -41,15 +39,9 @@ public class FabricBlockRegistry extends BundledBlockRegistry {
private Map<Material, FabricBlockMaterial> materialMap = new HashMap<>();
@Nullable
@Override
public String getName(BlockType blockType) {
Block block = FabricAdapter.adapt(blockType);
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return block.getName().asFormattedString();
} else {
return super.getName(blockType);
}
public Component getRichName(BlockType blockType) {
return TranslatableComponent.of(FabricAdapter.adapt(blockType).getTranslationKey());
}
@Override

Datei anzeigen

@ -19,24 +19,26 @@
package com.sk89q.worldedit.fabric;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.item.Item;
import javax.annotation.Nullable;
public class FabricItemRegistry extends BundledItemRegistry {
@Nullable
@Override
public String getName(ItemType itemType) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
final Item item = FabricAdapter.adapt(itemType);
return I18n.translate(item.getTranslationKey());
}
return super.getName(itemType);
public Component getRichName(ItemType itemType) {
return TranslatableComponent.of(
FabricAdapter.adapt(itemType).getTranslationKey()
);
}
@Override
public Component getRichName(BaseItemStack itemStack) {
return TranslatableComponent.of(
FabricAdapter.adapt(itemStack).getTranslationKey()
);
}
}

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome;
*/
class ForgeBiomeRegistry implements BiomeRegistry {
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(ForgeAdapter.adapt(biomeType).getTranslationKey());
}
@Deprecated
@Override
public BiomeData getData(BiomeType biome) {
return new ForgeBiomeData(ForgeAdapter.adapt(biome));
@ -37,6 +45,7 @@ class ForgeBiomeRegistry implements BiomeRegistry {
/**
* Cached biome data information.
*/
@Deprecated
private static class ForgeBiomeData implements BiomeData {
private final Biome biome;
@ -49,6 +58,7 @@ class ForgeBiomeRegistry implements BiomeRegistry {
this.biome = biome;
}
@SuppressWarnings("deprecation")
@Override
public String getName() {
return biome.getDisplayName().getString();

Datei anzeigen

@ -20,6 +20,8 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
@ -27,9 +29,7 @@ import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.state.IProperty;
import net.minecraftforge.fml.loading.FMLLoader;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -40,15 +40,9 @@ public class ForgeBlockRegistry extends BundledBlockRegistry {
private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>();
@Nullable
@Override
public String getName(BlockType blockType) {
Block block = ForgeAdapter.adapt(blockType);
if (block != null && FMLLoader.getDist().isClient()) {
return block.getNameTextComponent().getFormattedText();
} else {
return super.getName(blockType);
}
public Component getRichName(BlockType blockType) {
return TranslatableComponent.of(ForgeAdapter.adapt(blockType).getTranslationKey());
}
@Override

Datei anzeigen

@ -19,33 +19,26 @@
package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.ItemRegistry;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
import javax.annotation.Nullable;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.RegistryManager;
public class ForgeItemRegistry extends BundledItemRegistry {
@Nullable
@Override
public String getName(ItemType itemType) {
if (FMLLoader.getDist().isClient()) {
final Item item = RegistryManager.ACTIVE.getRegistry(Item.class)
.getValue(ResourceLocation.tryCreate(itemType.getId()));
if (item != null) {
return I18n.format(item.getTranslationKey());
}
}
return super.getName(itemType);
public Component getRichName(ItemType itemType) {
return TranslatableComponent.of(
ForgeAdapter.adapt(itemType).getTranslationKey()
);
}
@Override
public Component getRichName(BaseItemStack itemStack) {
return TranslatableComponent.of(
ForgeAdapter.adapt(itemStack).getTranslationKey()
);
}
}

Datei anzeigen

@ -19,6 +19,9 @@
package com.sk89q.worldedit.sponge;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.translation.TranslationManager;
import com.sk89q.worldedit.world.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.spongepowered.api.world.biome.BiomeType;
@ -30,12 +33,21 @@ import javax.annotation.Nullable;
*/
class SpongeBiomeRegistry implements BiomeRegistry {
@Override
public Component getRichName(com.sk89q.worldedit.world.biome.BiomeType biomeType) {
return TranslatableComponent.of(
TranslationManager.makeTranslationKey("biome", biomeType.getId())
);
}
@Deprecated
@Nullable
@Override
public BiomeData getData(com.sk89q.worldedit.world.biome.BiomeType biome) {
return new SpongeBiomeData(SpongeAdapter.adapt(biome));
}
@Deprecated
private static class SpongeBiomeData implements BiomeData {
private final BiomeType biome;
@ -48,6 +60,7 @@ class SpongeBiomeRegistry implements BiomeRegistry {
this.biome = biome;
}
@SuppressWarnings("deprecation")
@Override
public String getName() {
return biome.getName();