use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaEggNBTEntityID.
@Override
public String getVanillaEggNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_16_R2.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("EntityTag")) {
final MinecraftKey vanillaKey = IRegistry.ITEM.getKey(itemStack.getItem());
if (vanillaKey != null) {
return vanillaKey.getKey().replace("minecraft:", "").replace("_spawn_egg", "");
}
} else {
tag = tag.getCompound("EntityTag");
if (tag.hasKey("id")) {
return tag.getString("id").replace("minecraft:", "");
}
}
return null;
}
use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method setSpawnersUnstackable.
@Override
public void setSpawnersUnstackable() {
try {
final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
maxStackSize.setAccessible(true);
maxStackSize.set(spawner, 1);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method setSpawnersUnstackable.
@Override
public void setSpawnersUnstackable() {
try {
final Item spawner = IRegistry.ITEM.get(new MinecraftKey(NAMESPACED_SPAWNER_ID));
final Field maxStackSize = Item.class.getDeclaredField("maxStackSize");
maxStackSize.setAccessible(true);
maxStackSize.set(spawner, 1);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R2.Item in project SilkSpawners by timbru31.
the class NMSHandler method newEggItem.
@SuppressWarnings("deprecation")
@Override
public ItemStack newEggItem(final String entityID, final int amount, final String displayName) {
Material spawnEgg = Material.matchMaterial(entityID.toUpperCase() + "_SPAWN_EGG");
if (spawnEgg == null) {
spawnEgg = Material.LEGACY_MONSTER_EGG;
}
final ItemStack item = new ItemStack(spawnEgg, amount);
if (displayName != null) {
final ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(displayName);
item.setItemMeta(itemMeta);
}
net.minecraft.server.v1_16_R2.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final NBTTagCompound tag = itemStack.getOrCreateTag();
if (!tag.hasKey("SilkSpawners")) {
tag.set("SilkSpawners", new NBTTagCompound());
}
tag.getCompound("SilkSpawners").setString("entity", entityID);
if (!tag.hasKey("EntityTag")) {
tag.set("EntityTag", new NBTTagCompound());
}
String prefixedEntity;
if (!entityID.startsWith("minecraft:")) {
prefixedEntity = "minecraft:" + entityID;
} else {
prefixedEntity = entityID;
}
tag.getCompound("EntityTag").setString("id", prefixedEntity);
return CraftItemStack.asCraftMirror(itemStack);
}
use of net.minecraft.server.v1_16_R2.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)));
}
Aggregations