Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-16 04:50:07 +01:00
Ursprung
e994d6e1d6
Commit
663e3af7c8
@ -28,6 +28,9 @@ package org.geysermc.geyser.item.type;
|
|||||||
import org.geysermc.geyser.level.block.type.Block;
|
import org.geysermc.geyser.level.block.type.Block;
|
||||||
|
|
||||||
public class BlockItem extends Item {
|
public class BlockItem extends Item {
|
||||||
|
// If item is instanceof ItemNameBlockItem
|
||||||
|
private final boolean treatLikeBlock;
|
||||||
|
|
||||||
public BlockItem(Builder builder, Block block, Block... otherBlocks) {
|
public BlockItem(Builder builder, Block block, Block... otherBlocks) {
|
||||||
super(block.javaIdentifier().value(), builder);
|
super(block.javaIdentifier().value(), builder);
|
||||||
|
|
||||||
@ -36,6 +39,7 @@ public class BlockItem extends Item {
|
|||||||
for (Block otherBlock : otherBlocks) {
|
for (Block otherBlock : otherBlocks) {
|
||||||
registerBlock(otherBlock, this);
|
registerBlock(otherBlock, this);
|
||||||
}
|
}
|
||||||
|
treatLikeBlock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use this constructor if the item name is not the same as its primary block
|
// Use this constructor if the item name is not the same as its primary block
|
||||||
@ -46,5 +50,14 @@ public class BlockItem extends Item {
|
|||||||
for (Block otherBlock : otherBlocks) {
|
for (Block otherBlock : otherBlocks) {
|
||||||
registerBlock(otherBlock, this);
|
registerBlock(otherBlock, this);
|
||||||
}
|
}
|
||||||
|
treatLikeBlock = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String translationKey() {
|
||||||
|
if (!treatLikeBlock) {
|
||||||
|
return super.translationKey();
|
||||||
|
}
|
||||||
|
return "block." + this.javaIdentifier.namespace() + "." + this.javaIdentifier.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@ -59,7 +60,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
private static final Map<Block, Item> BLOCK_TO_ITEM = new HashMap<>();
|
private static final Map<Block, Item> BLOCK_TO_ITEM = new HashMap<>();
|
||||||
private final String javaIdentifier;
|
protected final Key javaIdentifier;
|
||||||
private int javaId = -1;
|
private int javaId = -1;
|
||||||
private final int stackSize;
|
private final int stackSize;
|
||||||
private final int attackDamage;
|
private final int attackDamage;
|
||||||
@ -68,7 +69,7 @@ public class Item {
|
|||||||
private final boolean glint;
|
private final boolean glint;
|
||||||
|
|
||||||
public Item(String javaIdentifier, Builder builder) {
|
public Item(String javaIdentifier, Builder builder) {
|
||||||
this.javaIdentifier = MinecraftKey.key(javaIdentifier).asString().intern();
|
this.javaIdentifier = MinecraftKey.key(javaIdentifier);
|
||||||
this.stackSize = builder.stackSize;
|
this.stackSize = builder.stackSize;
|
||||||
this.maxDamage = builder.maxDamage;
|
this.maxDamage = builder.maxDamage;
|
||||||
this.attackDamage = builder.attackDamage;
|
this.attackDamage = builder.attackDamage;
|
||||||
@ -77,7 +78,7 @@ public class Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String javaIdentifier() {
|
public String javaIdentifier() {
|
||||||
return javaIdentifier;
|
return javaIdentifier.asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int javaId() {
|
public int javaId() {
|
||||||
@ -108,6 +109,10 @@ public class Item {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String translationKey() {
|
||||||
|
return "item." + javaIdentifier.namespace() + "." + javaIdentifier.value();
|
||||||
|
}
|
||||||
|
|
||||||
/* Translation methods to Bedrock and back */
|
/* Translation methods to Bedrock and back */
|
||||||
|
|
||||||
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
|
@ -253,7 +253,8 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
// We can get the correct order for button pressing
|
// We can get the correct order for button pressing
|
||||||
data.getValue().sort(Comparator.comparing((stoneCuttingRecipeData ->
|
data.getValue().sort(Comparator.comparing((stoneCuttingRecipeData ->
|
||||||
Registries.JAVA_ITEMS.get().get(stoneCuttingRecipeData.getResult().getId())
|
Registries.JAVA_ITEMS.get().get(stoneCuttingRecipeData.getResult().getId())
|
||||||
.javaIdentifier())));
|
// See RecipeManager#getRecipesFor as of 1.21
|
||||||
|
.translationKey())));
|
||||||
|
|
||||||
// Now that it's sorted, let's translate these recipes
|
// Now that it's sorted, let's translate these recipes
|
||||||
int buttonId = 0;
|
int buttonId = 0;
|
||||||
|
@ -107,7 +107,7 @@ public class StatisticsUtils {
|
|||||||
|
|
||||||
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
||||||
if (entry.getKey() instanceof BreakItemStatistic statistic) {
|
if (entry.getKey() instanceof BreakItemStatistic statistic) {
|
||||||
String item = itemRegistry.get(statistic.getId()).javaIdentifier();
|
Item item = itemRegistry.get(statistic.getId());
|
||||||
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public class StatisticsUtils {
|
|||||||
|
|
||||||
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
||||||
if (entry.getKey() instanceof CraftItemStatistic statistic) {
|
if (entry.getKey() instanceof CraftItemStatistic statistic) {
|
||||||
String item = itemRegistry.get(statistic.getId()).javaIdentifier();
|
Item item = itemRegistry.get(statistic.getId());
|
||||||
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ public class StatisticsUtils {
|
|||||||
|
|
||||||
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
||||||
if (entry.getKey() instanceof UseItemStatistic statistic) {
|
if (entry.getKey() instanceof UseItemStatistic statistic) {
|
||||||
String item = itemRegistry.get(statistic.getId()).javaIdentifier();
|
Item item = itemRegistry.get(statistic.getId());
|
||||||
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ public class StatisticsUtils {
|
|||||||
|
|
||||||
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
||||||
if (entry.getKey() instanceof PickupItemStatistic statistic) {
|
if (entry.getKey() instanceof PickupItemStatistic statistic) {
|
||||||
String item = itemRegistry.get(statistic.getId()).javaIdentifier();
|
Item item = itemRegistry.get(statistic.getId());
|
||||||
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ public class StatisticsUtils {
|
|||||||
|
|
||||||
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
for (Object2IntMap.Entry<Statistic> entry : session.getStatistics().object2IntEntrySet()) {
|
||||||
if (entry.getKey() instanceof DropItemStatistic statistic) {
|
if (entry.getKey() instanceof DropItemStatistic statistic) {
|
||||||
String item = itemRegistry.get(statistic.getId()).javaIdentifier();
|
Item item = itemRegistry.get(statistic.getId());
|
||||||
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
content.add(getItemTranslateKey(item, language) + ": " + entry.getIntValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,14 +208,8 @@ public class StatisticsUtils {
|
|||||||
* @param language the language to search in
|
* @param language the language to search in
|
||||||
* @return the full name of the item
|
* @return the full name of the item
|
||||||
*/
|
*/
|
||||||
private static String getItemTranslateKey(String item, String language) {
|
private static String getItemTranslateKey(Item item, String language) {
|
||||||
item = item.replace("minecraft:", "item.minecraft.");
|
return MinecraftLocale.getLocaleString(item.translationKey(), language);
|
||||||
String translatedItem = MinecraftLocale.getLocaleString(item, language);
|
|
||||||
if (translatedItem.equals(item)) {
|
|
||||||
// Didn't translate; must be a block
|
|
||||||
translatedItem = MinecraftLocale.getLocaleString(item.replace("item.", "block."), language);
|
|
||||||
}
|
|
||||||
return translatedItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String translate(String keys, String locale) {
|
private static String translate(String keys, String locale) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren