Search in sources :

Example 1 with InventoryCraftResult

use of net.minecraft.world.inventory.InventoryCraftResult in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method setItems.

protected void setItems(List<org.bukkit.inventory.ItemStack> items) {
    int index = 0;
    for (org.bukkit.inventory.ItemStack item : items) {
        this.items.set(index++, CraftItemStack.asNMSCopy(item));
    }
    // Want to update the result without having to use a real player
    if (this.resultInventory instanceof InventoryCraftResult) {
        CustomContainerWorkbench container = new CustomContainerWorkbench(0, manager.mockPlayer.getBukkitEntity(), bloc, this, (InventoryCraftResult) resultInventory);
        container.a(this);
        CraftingInventory crafting = (CraftingInventory) container.getBukkitView().getTopInventory();
        Bukkit.getPluginManager().callEvent(new PrepareItemCraftEvent(crafting, container.getBukkitView(), false));
    }
    display.forceUpdate();
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory) PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) InventoryCraftResult(net.minecraft.world.inventory.InventoryCraftResult)

Example 2 with InventoryCraftResult

use of net.minecraft.world.inventory.InventoryCraftResult in project PublicCrafters by BananaPuncher714.

the class CustomTileEntityContainerWorkbench method createMenu.

/**
 * This is an ITileEntityContainer method that returns a new container for whatever tile entity
 */
@Override
public Container createMenu(int id, PlayerInventory inv, EntityHuman ent) {
    CustomInventoryCrafting crafting = manager.benches.get(bloc);
    if (crafting == null) {
        crafting = new CustomInventoryCrafting(bloc, manager, new SelfContainer(id), 3, 3);
        manager.put(bloc, crafting);
    }
    IInventory inventory = crafting.resultInventory;
    InventoryCraftResult result;
    if (inventory instanceof InventoryCraftResult || inventory == null) {
        result = new InventoryCraftResult();
        crafting.resultInventory = result;
    } else {
        result = (InventoryCraftResult) inventory;
    }
    Container container = new CustomContainerWorkbench(id, ent.getBukkitEntity(), bloc, crafting, result);
    crafting.addContainer(container);
    return container;
}
Also used : IInventory(net.minecraft.world.IInventory) ITileEntityContainer(net.minecraft.world.inventory.ITileEntityContainer) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_17_R1.ContainerManager_v1_17_R1.SelfContainer) Container(net.minecraft.world.inventory.Container) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_17_R1.ContainerManager_v1_17_R1.SelfContainer) InventoryCraftResult(net.minecraft.world.inventory.InventoryCraftResult)

Example 3 with InventoryCraftResult

use of net.minecraft.world.inventory.InventoryCraftResult in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_18_R2 method load.

@Override
public void load(Location location, List<ItemStack> items) {
    // Is 0 really ok as an id?!?
    CustomInventoryCrafting crafting = new CustomInventoryCrafting(location, this, new SelfContainer(0), 3, 3);
    InventoryCraftResult result = new InventoryCraftResult();
    crafting.resultInventory = result;
    crafting.setItems(items);
    benches.put(location, crafting);
}
Also used : InventoryCraftResult(net.minecraft.world.inventory.InventoryCraftResult)

Example 4 with InventoryCraftResult

use of net.minecraft.world.inventory.InventoryCraftResult in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method setItems.

protected void setItems(List<org.bukkit.inventory.ItemStack> items) {
    int index = 0;
    for (org.bukkit.inventory.ItemStack item : items) {
        this.items.set(index++, CraftItemStack.asNMSCopy(item));
    }
    // Want to update the result without having to use a real player
    if (this.resultInventory instanceof InventoryCraftResult) {
        CustomContainerWorkbench container = new CustomContainerWorkbench(0, manager.mockPlayer.getBukkitEntity(), bloc, this, (InventoryCraftResult) resultInventory);
        container.a(this);
        CraftingInventory crafting = (CraftingInventory) container.getBukkitView().getTopInventory();
        Bukkit.getPluginManager().callEvent(new PrepareItemCraftEvent(crafting, container.getBukkitView(), false));
    }
    display.forceUpdate();
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory) PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) InventoryCraftResult(net.minecraft.world.inventory.InventoryCraftResult)

Example 5 with InventoryCraftResult

use of net.minecraft.world.inventory.InventoryCraftResult in project PublicCrafters by BananaPuncher714.

the class CustomTileEntityContainerWorkbench method createMenu.

/**
 * This is an ITileEntityContainer method that returns a new container for whatever tile entity
 */
@Override
public Container createMenu(int id, PlayerInventory inv, EntityHuman ent) {
    CustomInventoryCrafting crafting = manager.benches.get(bloc);
    if (crafting == null) {
        crafting = new CustomInventoryCrafting(bloc, manager, new SelfContainer(id), 3, 3);
        manager.put(bloc, crafting);
    }
    IInventory inventory = crafting.resultInventory;
    InventoryCraftResult result;
    if (inventory instanceof InventoryCraftResult || inventory == null) {
        result = new InventoryCraftResult();
        crafting.resultInventory = result;
    } else {
        result = (InventoryCraftResult) inventory;
    }
    Container container = new CustomContainerWorkbench(id, ent.getBukkitEntity(), bloc, crafting, result);
    crafting.addContainer(container);
    return container;
}
Also used : IInventory(net.minecraft.world.IInventory) ITileEntityContainer(net.minecraft.world.inventory.ITileEntityContainer) Container(net.minecraft.world.inventory.Container) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_18_R2.ContainerManager_v1_18_R2.SelfContainer) SelfContainer(io.github.bananapuncher714.crafters.implementation.v1_18_R2.ContainerManager_v1_18_R2.SelfContainer) InventoryCraftResult(net.minecraft.world.inventory.InventoryCraftResult)

Aggregations

InventoryCraftResult (net.minecraft.world.inventory.InventoryCraftResult)12 PublicCraftingInventory (io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory)4 IInventory (net.minecraft.world.IInventory)4 Container (net.minecraft.world.inventory.Container)4 ITileEntityContainer (net.minecraft.world.inventory.ITileEntityContainer)4 PrepareItemCraftEvent (org.bukkit.event.inventory.PrepareItemCraftEvent)4 CraftingInventory (org.bukkit.inventory.CraftingInventory)4 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_17_1.ContainerManager_v1_17_1.SelfContainer)1 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_17_R1.ContainerManager_v1_17_R1.SelfContainer)1 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_18_R1.ContainerManager_v1_18_R1.SelfContainer)1 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_18_R2.ContainerManager_v1_18_R2.SelfContainer)1