Hello,
I want to create a ChestUI for my plugin. It requires only one page.
Well, I have really no clue how to create a ChestUI in Nukkit.
Can someone help me with that?
Best regards,
Schdow
I don't need it anymore but maybe you can post it for the othersDid you figure out how to do it? If not I have some code I can share![]()
I don't need it anymore but maybe you can post it for the others![]()
private Int2ObjectOpenHashMap<Item> chest;
private void chestItems() {
this.chest = new Int2ObjectOpenHashMap(); //Adds the chest items to this array
int i = -1; //Starts at -1 so items don't skip the first chest slot.
Item q = Item.get(360).setCustomName("nothing");
q.addEnchantment(new Enchantment[] { Enchantment.get(0) } );
chest.put(++i, q); //Sets the item in the chest
}
public game() {
chestItems();
}
private void menu(Player player) {
UpdateBlockPacket pk = new UpdateBlockPacket();
pk.x = (int)player.x + 1;
pk.y = (int)player.y + 1;
pk.z = (int)player.z + 1;
pk.flags = 0;
pk.blockRuntimeId = GlobalBlockPalette.getOrCreateRuntimeId(54, 0);
BlockEntityDataPacket pk2 = new BlockEntityDataPacket();
pk2.x = pk.x;
pk2.y = pk.y;
pk2.z = pk.z;
try {
pk2.namedTag = NBTIO.write((new CompoundTag())
.putString("CustomName", "Cosmetics")
.putInt("x", pk.x)
.putInt("y", pk.y)
.putInt("z", pk.z)
.putString("id", "Chest"), ByteOrder.LITTLE_ENDIAN, true);
} catch (Exception exception) {}
player.dataPacket(pk);
player.dataPacket(pk2);
final holder h = new holder(new Vector3(pk.x, pk.y, pk.z));
final FI fi = new FI(h);
fi.setContents(this.chest);
player.addWindow(fi);
}
import cn.nukkit.inventory.Inventory;
import cn.nukkit.inventory.InventoryHolder;
import cn.nukkit.math.Vector3;
public class holder extends Vector3 implements InventoryHolder {
public holder(final Vector3 pos) {
this.x = pos.x;
this.y = pos.y;
this.z = pos.z;
}
public Inventory getInventory() {
return null;
}
}
package --;
import cn.nukkit.inventory.CustomInventory;
import cn.nukkit.inventory.InventoryType;
public class FI extends CustomInventory {
public FI(holder holder) {
super(holder, InventoryType.CHEST);
}
}
@EventHandler
public void onChest(InventoryTransactionEvent e) {
Player pl = e.getTransaction().getSource();
if (!(pl.getLevel() == Server.getInstance().getDefaultLevel())) {
return;
}
for (final InventoryAction action : e.getTransaction().getActions()) {
if (this.interact(action.getSourceItem().getId(), e.getTransaction().getSource(), e.getTransaction().getInventories()) || this.interact(action.getTargetItem().getId(), e.getTransaction().getSource(), e.getTransaction().getInventories())) {
e.setCancelled();
return;
}
}
e.setCancelled();
}
private boolean interact(int id, Player player, Set<Inventory> inv) {
switch (id) {
case 360: {
player.sendMessage("test");
}
}
return false;
}
Thanks for sharing. I'm pretty sure it will help out some usersLike I said, There are other ways of doing this.
Thanks for sharing. I'm pretty sure it will help out some users![]()