SPIGOT-4230: Improve legacy block types

Dieser Commit ist enthalten in:
md_5 2018-08-05 10:04:19 +10:00
Ursprung ec2095d9c6
Commit 5e3082c7d8
4 geänderte Dateien mit 21 neuen und 3 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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