use of net.minecraft.server.v1_11_R1.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_11_R1.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_11_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;
}
net.minecraft.server.v1_11_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null) {
tag = new NBTTagCompound();
itemStack.setTag(tag);
}
if (!tag.hasKey("SilkSpawners")) {
tag.set("SilkSpawners", new NBTTagCompound());
}
tag.getCompound("SilkSpawners").setString("entity", entity);
if (!tag.hasKey("BlockEntityTag")) {
tag.set("BlockEntityTag", new NBTTagCompound());
}
tag.getCompound("BlockEntityTag").setString("EntityId", entity);
if (!tag.hasKey("SpawnData")) {
tag.set("SpawnData", new NBTTagCompound());
}
tag.getCompound("SpawnData").setString("id", entity);
if (!tag.getCompound("BlockEntityTag").hasKey("SpawnData")) {
tag.getCompound("BlockEntityTag").set("SpawnData", new NBTTagCompound());
}
tag.getCompound("BlockEntityTag").getCompound("SpawnData").setString("id", entity);
if (!tag.getCompound("BlockEntityTag").hasKey("SpawnPotentials")) {
tag.getCompound("BlockEntityTag").set("SpawnPotentials", new NBTTagCompound());
}
if (!tag.hasKey("EntityTag")) {
tag.set("EntityTag", new NBTTagCompound());
}
String prefixedEntity;
if (!entity.startsWith("minecraft:")) {
prefixedEntity = "minecraft:" + entity;
} else {
prefixedEntity = entity;
}
tag.getCompound("EntityTag").setString("id", prefixedEntity);
return CraftItemStack.asCraftMirror(itemStack);
}
use of net.minecraft.server.v1_11_R1.Item in project SilkSpawners by timbru31.
the class NMSHandler method getVanillaNBTEntityID.
@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
net.minecraft.server.v1_11_R1.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
NBTTagCompound tag = itemStack.getTag();
if (tag == null || !tag.hasKey("BlockEntityTag")) {
return null;
}
tag = tag.getCompound("BlockEntityTag");
if (tag.hasKey("EntityId")) {
return tag.getString("EntityId");
} else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
return tag.getCompound("SpawnData").getString("id");
} else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
return tag.getList("SpawnPotentials", 8).get(0).getCompound("Entity").getString("id");
} else {
return null;
}
}
use of net.minecraft.server.v1_11_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)));
}
Aggregations