Upstream changes (#717)

* Perform part of the move of //fast to //perf (#1377)

This re-adds a deprecated `//fast` and moves the current logic to
`//perf`. Later `//perf` will have its syntax reworked, when Piston
finally supports sub-commands properly!

* 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)

* Follow-up fixes for 92f877679622a27b16b9e5cd61cfec1a6545be33

* Don't send deprecation warning and improve info message

* Fix click command for perf box

(cherry picked from commit 7ee60060c31df2f8b41212b430a0875312189339)

* update R3 adapter§

Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com>
Co-authored-by: Aurora <aurora@relanet.eu>
This commit is contained in:
Hannes Greule
2020-11-09 10:38:10 +01:00
committed by GitHub
parent 49052d73ce
commit 428f8e201d
42 changed files with 660 additions and 303 deletions

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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 {

View File

@ -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) {