I wanted to make a chest with kits but how can i give the player the chest and how can i create a custom “Kit-inventory”?
(right-click chest should open the inventory with different items that gives you a kit if you click on them)
first, you will need to give the player a Chest.
public static ItemStack CHEST = getChest();
private static ItemStack getChest(){
ItemStack.Builder builder = GAME.getRegistry().createBuilder(ItemStack.Builder.class);
builder.itemType(ItemTypes.CHEST).quantity(1);
ItemStack stack = builder.build();
return stack;
}
after that you will need to offer the item to the player
Player player;
player.getInventory().offer(CHEST);
then you will need to listen for a inventory click, you will also need a custom inventory (not been implemented yet) but this is how you would do it
public CustomInventory createEmptyInventory(String name, int size){
CustomInventory.Builder builder = GAME.getRegistry().createBuilder(CustomInventory.Builder.class);
builder.name(new FixedTranslation(name)).size(size);
Optional<CustomInventory> opInv = builder.build();
if(opInv.isPresent()){
return opInv.get();
}
}
after that you will need to open the inventory
Player player;
player.openInventory(CUSTOM_INVENTORY);
references:
Opening inventories
working with ItemStacks
working with custom inventories
3 Likes
If i do this :
eclipse says : Type mismatch: cannot convert from ItemStack to Optional
Have CustomInventories been implemented?
No (15 characters)
nope. as far as i know at least
ah i was thinking of a older sponge version
just do the following (using whole code to make sure everyone who reads this understands … also editing the post before)
private static ItemStack getChest(){
ItemStack.Builder builder = GAME.getRegistry().createBuilder(ItemStack.Builder.class);
builder.itemType(ItemTypes.CHEST).quantity(1);
ItemStack stack = builder.build();
return stack;
}