mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 09:23:42 +01:00
113 lines
5.3 KiB
Diff
113 lines
5.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MeFisto94 <MeFisto94@users.noreply.github.com>
|
|
Date: Tue, 11 Aug 2020 19:16:09 +0200
|
|
Subject: [PATCH] Add a way to get translation keys for blocks, entities and
|
|
materials
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/EntityTypes.java b/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
|
index 9d2955f05aadd4bbc6dcfec068a55d7fe6950ba0..f2cf33d42839710a3bbdf0c8ea0be28af6fcb19d 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityTypes.java
|
|
@@ -278,6 +278,7 @@ public class EntityTypes<T extends Entity> {
|
|
return IRegistry.ENTITY_TYPE.getKey(entitytypes);
|
|
}
|
|
|
|
+ public static Optional<EntityTypes<?>> getByName(String name) { return a(name); } // Paper - OBFHELPER
|
|
public static Optional<EntityTypes<?>> a(String s) {
|
|
return IRegistry.ENTITY_TYPE.getOptional(MinecraftKey.a(s));
|
|
}
|
|
@@ -431,6 +432,7 @@ public class EntityTypes<T extends Entity> {
|
|
return this.bg;
|
|
}
|
|
|
|
+ public String getDescriptionId() { return f(); } // Paper - OBFHELPER
|
|
public String f() {
|
|
if (this.bo == null) {
|
|
this.bo = SystemUtils.a("entity", IRegistry.ENTITY_TYPE.getKey(this));
|
|
diff --git a/src/main/java/net/minecraft/world/item/Item.java b/src/main/java/net/minecraft/world/item/Item.java
|
|
index ca513e7b0a416860aba89e41de6a7c5ff42baa69..5d7c44a53fb98532057b09176677ce0d719b055b 100644
|
|
--- a/src/main/java/net/minecraft/world/item/Item.java
|
|
+++ b/src/main/java/net/minecraft/world/item/Item.java
|
|
@@ -56,7 +56,7 @@ public class Item implements IMaterial {
|
|
private final FoodInfo foodInfo;
|
|
|
|
public static int getId(Item item) {
|
|
- return item == null ? 0 : IRegistry.ITEM.a((Object) item);
|
|
+ return item == null ? 0 : IRegistry.ITEM.a(item); // Paper - Fix Decompiler Issue
|
|
}
|
|
|
|
public static Item getById(int i) {
|
|
@@ -152,6 +152,7 @@ public class Item implements IMaterial {
|
|
return IRegistry.ITEM.getKey(this).getKey();
|
|
}
|
|
|
|
+ public String getOrCreateDescriptionId() { return m(); } // Paper - OBFHELPER
|
|
protected String m() {
|
|
if (this.name == null) {
|
|
this.name = SystemUtils.a("item", IRegistry.ITEM.getKey(this));
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
|
|
index cc512bd2e89382e7fdbc59b41640e95ccafbbfe9..768934fa4158a9773d06f5b23bfb19db75f6d179 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/Block.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
|
|
@@ -318,6 +318,7 @@ public class Block extends BlockBase implements IMaterial {
|
|
return !this.material.isBuildable() && !this.material.isLiquid();
|
|
}
|
|
|
|
+ public String getDescriptionId() { return i(); } // Paper - OBFHELPER
|
|
public String i() {
|
|
if (this.name == null) {
|
|
this.name = SystemUtils.a("block", IRegistry.BLOCK.getKey(this));
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
index e3ab0b76e5003553b29215a43bc5a762f2663648..ee8977a1e4a83598ba7873c4c482fea828c6b26c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
@@ -764,5 +764,10 @@ public class CraftBlock implements Block {
|
|
public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() {
|
|
return new com.destroystokyo.paper.block.CraftBlockSoundGroup(getNMSBlock().getBlockData().getStepSound());
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public String getTranslationKey() {
|
|
+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
|
|
+ }
|
|
// Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 2519dbce9717ff647d50c31aed6aca68b9f4e3af..6c59816bb9246f22d518aa9f87ec382ae3d3a014 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -45,6 +45,7 @@ import org.bukkit.Registry;
|
|
import org.bukkit.UnsafeValues;
|
|
import org.bukkit.advancement.Advancement;
|
|
import org.bukkit.block.data.BlockData;
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
|
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
import org.bukkit.craftbukkit.legacy.CraftLegacy;
|
|
@@ -420,6 +421,25 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
throw new RuntimeException();
|
|
}
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public String getTranslationKey(Material mat) {
|
|
+ if (mat.isBlock()) {
|
|
+ return getBlock(mat).getDescriptionId();
|
|
+ }
|
|
+ return getItem(mat).getOrCreateDescriptionId();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getTranslationKey(org.bukkit.block.Block block) {
|
|
+ return ((org.bukkit.craftbukkit.block.CraftBlock)block).getNMS().getBlock().getDescriptionId();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getTranslationKey(org.bukkit.entity.EntityType type) {
|
|
+ return net.minecraft.world.entity.EntityTypes.getByName(type.getName()).map(net.minecraft.world.entity.EntityTypes::getDescriptionId).orElse(null);
|
|
+ }
|
|
+
|
|
// Paper end
|
|
|
|
/**
|