mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-10 12:50:28 +01:00
SPIGOT-4230: Improve legacy block types
This commit is contained in:
parent
ec2095d9c6
commit
5e3082c7d8
@ -45,7 +45,7 @@ public class CraftBlock implements Block {
|
||||
return getNMS().getBlock();
|
||||
}
|
||||
|
||||
protected net.minecraft.server.IBlockData getNMS() {
|
||||
public net.minecraft.server.IBlockData getNMS() {
|
||||
return world.getType(position);
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,8 @@ public class Commodore
|
||||
|
||||
if ( EVIL.contains( owner + " " + desc + " " + name )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "()I getTypeId" ) )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "(I)Z setTypeId" ) ) )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "(I)Z setTypeId" ) )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "()Lorg/bukkit/Material; getType" ) ) )
|
||||
{
|
||||
Type[] args = Type.getArgumentTypes( desc );
|
||||
Type[] newArgs = new Type[ args.length + 1 ];
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -34,6 +35,14 @@ public class CraftEvil {
|
||||
return getId(world.getBlockAt(location).getType());
|
||||
}
|
||||
|
||||
public static Material getType(Block block) {
|
||||
return CraftLegacy.toLegacyMaterial(((CraftBlock) block).getNMS());
|
||||
}
|
||||
|
||||
public static Material getType(BlockState block) {
|
||||
return CraftLegacy.toLegacyMaterial(((CraftBlockState) block).getHandle());
|
||||
}
|
||||
|
||||
public static int getTypeId(Block block) {
|
||||
return getId(block.getType());
|
||||
}
|
||||
|
@ -134,6 +134,14 @@ public class CraftLegacy {
|
||||
}
|
||||
|
||||
public static byte toLegacyData(IBlockData blockData) {
|
||||
return toLegacy(blockData).getData();
|
||||
}
|
||||
|
||||
public static Material toLegacyMaterial(IBlockData blockData) {
|
||||
return toLegacy(blockData).getItemType();
|
||||
}
|
||||
|
||||
public static MaterialData toLegacy(IBlockData blockData) {
|
||||
MaterialData mappedData;
|
||||
|
||||
// Try exact match first
|
||||
@ -143,7 +151,7 @@ public class CraftLegacy {
|
||||
mappedData = blockToMaterial.get(blockData.getBlock());
|
||||
}
|
||||
|
||||
return (mappedData == null) ? 0 : mappedData.getData();
|
||||
return (mappedData == null) ? new MaterialData(Material.LEGACY_AIR) : mappedData;
|
||||
}
|
||||
|
||||
public static Material fromLegacy(Material material) {
|
||||
|
Loading…
Reference in New Issue
Block a user