use of net.minecraft.server.v1_16_R1.Item in project SilkSpawners by timbru31.
the class NMSHandler method setNBTEntityID.
@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
if (item == null || StringUtils.isBlank(entity)) {
Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
return null;
}
String prefixedEntity;
if (!entity.startsWith("minecraft:")) {
prefixedEntity = "minecraft:" + entity;
} else {
prefixedEntity = entity;
}
net.minecraft.server.v1_16_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getOrCreateTag();
// Check for SilkSpawners key
if (!tag.hasKey("SilkSpawners")) {
tag.set("SilkSpawners", new NBTTagCompound());
}
tag.getCompound("SilkSpawners").setString("entity", entity);
// Check for Vanilla keys
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag = tag.getCompound("BlockEntityTag");
// EntityId - Deprecated in 1.9
tag.setString("EntityId", entity);
tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
// SpawnData
if (!tag.hasKey("SpawnData")) {
tag.set("SpawnData", new NBTTagCompound());
}
tag.getCompound("SpawnData").setString("id", prefixedEntity);
if (!tag.hasKey("SpawnPotentials")) {
tag.set("SpawnPotentials", new NBTTagCompound());
}
// SpawnEgg data
if (!tag.hasKey("EntityTag")) {
tag.set("EntityTag", new NBTTagCompound());
}
tag.getCompound("EntityTag").setString("id", prefixedEntity);
return CraftItemStack.asCraftMirror(itemStack);
}
use of net.minecraft.server.v1_16_R1.Item in project SilkSpawners by timbru31.
the class NMSHandler method getSilkSpawnersNBTEntityID.
@Override
@Nullable
public String getSilkSpawnersNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_16_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("SilkSpawners")) {
return null;
}
return tag.getCompound("SilkSpawners").getString("entity");
}
use of net.minecraft.server.v1_16_R1.Item in project PGM by PGMDev.
the class NMSHacks method canMineBlock.
/**
* Test if the given tool is capable of "efficiently" mining the given block.
*
* <p>Derived from CraftBlock.itemCausesDrops()
*/
static boolean canMineBlock(MaterialData blockMaterial, ItemStack tool) {
if (!blockMaterial.getItemType().isBlock()) {
throw new IllegalArgumentException("Material '" + blockMaterial + "' is not a block");
}
net.minecraft.server.v1_8_R3.Block nmsBlock = CraftMagicNumbers.getBlock(blockMaterial.getItemType());
net.minecraft.server.v1_8_R3.Item nmsTool = tool == null ? null : CraftMagicNumbers.getItem(tool.getType());
return nmsBlock != null && (nmsBlock.getMaterial().isAlwaysDestroyable() || (nmsTool != null && nmsTool.canDestroySpecialBlock(nmsBlock)));
}
use of net.minecraft.server.v1_16_R1.Item in project PaperDev by Kamillaova.
the class CraftItemStack method asNMSCopy.
public static net.minecraft.server.v1_12_R1.ItemStack asNMSCopy(ItemStack original) {
if (original instanceof CraftItemStack) {
CraftItemStack stack = (CraftItemStack) original;
return stack.handle == null ? net.minecraft.server.v1_12_R1.ItemStack.a : stack.handle.cloneItemStack();
}
if (original == null || original.getTypeId() <= 0) {
return net.minecraft.server.v1_12_R1.ItemStack.a;
}
Item item = CraftMagicNumbers.getItem(original.getType());
if (item == null) {
return net.minecraft.server.v1_12_R1.ItemStack.a;
}
net.minecraft.server.v1_12_R1.ItemStack stack = new net.minecraft.server.v1_12_R1.ItemStack(item, original.getAmount(), original.getDurability(), false);
if (original.hasItemMeta()) {
setItemMeta(stack, original.getItemMeta());
} else {
// Converted after setItemMeta
stack.convertStack();
}
return stack;
}
use of net.minecraft.server.v1_16_R1.Item in project PaperDev by Kamillaova.
the class ItemMetaTest method testBlockStateMeta.
@Test
public void testBlockStateMeta() {
for (Item item : (Iterable<Item>) Item.REGISTRY) {
Block block = null;
if (item instanceof ItemBlock) {
block = ((ItemBlock) item).getBlock();
} else if (item instanceof ItemReed) {
block = ((ItemReed) item).a;
}
if (block != null) {
if (block instanceof ITileEntity) {
ItemStack stack = CraftItemStack.asNewCraftStack(Item.getItemOf(block));
// Command blocks aren't unit testable atm
if (stack.getType() == Material.AIR || stack.getType() == Material.COMMAND || stack.getType() == Material.COMMAND_CHAIN || stack.getType() == Material.COMMAND_REPEATING) {
return;
}
ItemMeta meta = stack.getItemMeta();
assertTrue(stack + " has meta of type " + meta + " expected BlockStateMeta", meta instanceof BlockStateMeta);
BlockStateMeta blockState = (BlockStateMeta) meta;
assertNotNull(stack + " has null block state", blockState.getBlockState());
blockState.setBlockState(blockState.getBlockState());
}
}
}
}
Aggregations