Minecraft Plugin Rezept für unsichtbaren Item Frame Programmieren?
Wie kann ich den Item Frame im Rezept unsichtbar machen? Kann man das mit der ItemMeta oder wie?
Momentan habe ich:
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;
}
3 Antworten
Entweder per NBT oder, du musst beim Craften den ItemStack per MetaData markieren und wenn das item gesetzt wird, musst du das per Event abfangen und unsichtbar machen.
Ich würde NBT empfehlen, weil da schon invisible als Tag dabei ist. Hängt aber natürlich davon ab, wie gut du mit NBT zurecht kommst.
Normalerweise kannst du mit "/give @s item_frame{EntityTag:{Invisible:1}} " einen unsichtbaren item frame bekommen ( Nur in Java )! LG
Damit ein ItemFrame unsichtbar wird, muss der Invisible Tag auf 1 gesetzt sein.
Per Command funktioniert das durch:
/data modify entity @e[type=item_frame,limit=1,sort=nearest] Invisible set value 1b
In NMS sieht das folgendermaßen aus:
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));
bei arg0 kommt eine fehlermeldung "arg0 cannot be resolved to a variable"
kann man das irgend wie beheben? oder muss ich das anders positionieren?
habs im moment so:
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;
}
Das oben war nur ein Beispielcode, der einem Spieler (arg0) ein invisible Item Frame gibt. Das musst du halt auf deine Anwendung abändern.
Für ein Rezept müsste das folgendermaßen aussehen:
Eine Klasse für die Erweiterung:
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);
}
}
Und in der onEnable Funktion:
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);
}
}
Wenn du den invisible ItemFrame abbaust, wird allerdings ein normaler ItemFrame gedropt. Um das zu verhindern, muss man das Event abfangen, und ein ItemStack mit invisible ItemFrames droppen.
@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();
}
}
}
Nach bisschen cleanup sieht das folgendermaßen aus:
InvisibleFrame.java: https://pastebin.com/beAkfbuR
Test.java: https://pastebin.com/cgd3WfmR
@TheOrzoBiased Hab eine frage: Wieso funktioniert bei der Metode die ItemMeta nicht? Also ich will dem Invisible Item Frame einen Namen geben aber die ItemMeta geht nicht.
wie würde das mit NBT gehen? bin ein Anfänger