mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 12:05:53 +01:00
SPIGOT-6033: Bukkit.getUnsafe().getMaterial() won't match renamed block materials
This commit is contained in:
parent
29cce6714a
commit
52fd29c0dc
@ -33,6 +33,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.MojangsonParser;
|
||||
import net.minecraft.server.NBTBase;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
import net.minecraft.server.NBTTagString;
|
||||
import net.minecraft.server.SavedFile;
|
||||
import net.minecraft.server.SharedConstants;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -169,6 +170,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
||||
@Override
|
||||
public Material getMaterial(String material, int version) {
|
||||
Preconditions.checkArgument(material != null, "material == null");
|
||||
Preconditions.checkArgument(version <= this.getDataVersion(), "Newer version! Server downgrades are not supported!");
|
||||
|
||||
// Fastpath up to date materials
|
||||
@ -176,13 +178,14 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return Material.getMaterial(material);
|
||||
}
|
||||
|
||||
NBTTagCompound stack = new NBTTagCompound();
|
||||
stack.setString("id", "minecraft:" + material.toLowerCase(Locale.ROOT));
|
||||
Dynamic<NBTBase> name = new Dynamic<>(DynamicOpsNBT.a, NBTTagString.a("minecraft:" + material.toLowerCase(Locale.ROOT)));
|
||||
Dynamic<NBTBase> converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_NAME, name, version, this.getDataVersion());
|
||||
|
||||
Dynamic<NBTBase> converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_STACK, new Dynamic<>(DynamicOpsNBT.a, stack), version, this.getDataVersion());
|
||||
String newId = converted.get("id").asString("");
|
||||
if (name.equals(converted)) {
|
||||
converted = DataConverterRegistry.a().update(DataConverterTypes.BLOCK_NAME, name, version, this.getDataVersion());
|
||||
}
|
||||
|
||||
return Material.matchMaterial(newId);
|
||||
return Material.matchMaterial(converted.asString(""));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.support.AbstractTestingBase;
|
||||
import org.junit.Assert;
|
||||
@ -116,4 +117,10 @@ public class LegacyTest extends AbstractTestingBase {
|
||||
Assert.assertFalse("Must iterate only modern materials", material.isLegacy());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManual() {
|
||||
Assert.assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631));
|
||||
Assert.assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user