Programming Minecraft Plugin Recipe for Invisible Item Frame?

Ca
- in Plugins
12

How can I make the item frame invisible in the recipe? Can you do that with ItemMeta or how?

I currently have:

public ShapedRecipe Invisible_Itemframe () {

ItemStack itemStack = new ItemStack (Material.ITEM_FRAME);
ItemMeta itemMeta = itemStack.getItemMeta ();
itemStack.setItemMeta (itemMeta);

NamespacedKey namespacedKey = new NamespacedKey ((Plugin) this, "Invisible_Itemframe");
ShapedRecipe shapedRecipe = new ShapedRecipe (namespacedKey, itemStack);

shapedRecipe.shape ("", "I", "");
shapedRecipe.setIngredient ('I', Material.ITEM_FRAME);
return shapedRecipe;

An

Either via NBT or, when crafting, you have to mark the ItemStack via MetaData and when the item is set, you have to intercept it via an event and make it invisible.

I would recommend NBT because invisible is included as a day. Of course, it depends on how well you get on with NBT.

Ca

How would that go with NBT? Am a beginner

Ca

@Tobihogh can you help me?

Pr

/ data merge entity [your entity] {Invisible: 1b}

Ca

In a plugin?

Pr

No

An

In order for an ItemFrame to be invisible, the Invisible Tag must be set to 1.

This works with a command:

/ data modify entity @e [type = item_frame, limit = 1, sort = nearest] Invisible set value 1b

In NMS it looks like this:

ItemStack item = new ItemStack (Material.ITEM_FRAME);
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy (item);
NBTTagCompound compound = new NBTTagCompound ();

NBTTagCompound entityTag = new NBTTagCompound ();
entityTag.set ("Invisible", NBTTagByte.a (true));
compound.set ("EntityTag", entityTag);

nmsItem.setTag (compound);

((Player) arg0) .getInventory (). AddItem (CraftItemStack.asBukkitCopy (nmsItem));

Ca

With arg0 there's an error message "arg0 can't be resolved to a variable"

can you fix it somehow? Or do I have to position it differently?

at the moment it's like this:

public ShapedRecipe Invisible_Itemframe () {

ItemStack itemStack = new ItemStack (Material.ITEM_FRAME);
ItemMeta itemMeta = itemStack.getItemMeta ();
itemStack.setItemMeta (itemMeta);

ItemStack item = new ItemStack (Material.ITEM_FRAME);
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy (item);
NBTTagCompound compound = new NBTTagCompound ();

NBTTagCompound entityTag = new NBTTagCompound ();
entityTag.set ("Invisible", NBTTagByte.a (true));
compound.set ("EntityTag", entityTag);

nmsItem.setTag (compound);

((Player) arg0) .getInventory (). AddItem (CraftItemStack.asBukkitCopy (nmsItem));

NamespacedKey namespacedKey = new NamespacedKey ((Plugin) this, "Invisible_Itemframe");
ShapedRecipe shapedRecipe = new ShapedRecipe (namespacedKey, itemStack);

shapedRecipe.shape ("", "I", "");
shapedRecipe.setIngredient ('I', Material.ITEM_FRAME);
return shapedRecipe;

An

The above was just sample code that gives a player (arg0) an invisible item frame. You just have to change that to your application.

An

For a recipe it should look like this:

A class for expansion:

public class InvisibleFrame {

public ItemStack getItemStack () {
ItemStack item = new ItemStack (Material.ITEM_FRAME);
net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy (item);
NBTTagCompound compound = new NBTTagCompound ();

NBTTagCompound entityTag = new NBTTagCompound ();
entityTag.set ("Invisible", NBTTagByte.a (true));
compound.set ("EntityTag", entityTag);

nmsItem.setTag (compound);

return CraftItemStack.asBukkitCopy (nmsItem);
}

}

And in the onEnable function:

public class Test extends JavaPlugin {

@Override
public void onEnable () {

InvisibleFrame iif = new InvisibleFrame ();
getCommand ("iif"). SetExecutor (iif);
NamespacedKey key = new NamespacedKey (this, "InvisibleItemframe");
ShapedRecipe r = new ShapedRecipe (key, iif.getItemStack ());
r.shape ("", "I", "");
r.setIngredient ('I', Material.ITEM_FRAME);
Bukkit.addRecipe (r);
}

An

If you dismantle the invisible ItemFrame, however, a normal ItemFrame will be dropped. To prevent this, you have to intercept the event and drop an ItemStack with invisible ItemFrames.

@EventHandler
public void onFrameBreak (HangingBreakByEntityEvent e) {
if (e.getEntity (). GetType () == EntityType.ITEM_FRAME) {
net.minecraft.server.v1_16_R3.Entity nmsEntity = ((CraftEntity) e.getEntity ()). GetHandle ();
NBTTagCompound compound = new NBTTagCompound ();
nmsEntity.d (compound);

if (compound.getBoolean ("Invisible")) {
e.setCancelled (true);
e.getEntity (). GetLocation (). GetWorld (). DropItem (e.getEntity (). GetLocation (), getItemStack ());
e.getEntity (). Remove ();
}
}
}

An

After a bit of cleanup it looks like this:

InvisibleFrame.java:

Test.java: