Search in sources :

Example 1 with ContainerCraftingBrewingstand

use of com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand in project minecolonies by Minecolonies.

the class BrewingCraftingGuiHandler method updateServer.

@Override
protected void updateServer(@NotNull final WindowBrewingstandCrafting gui) {
    final Map<Integer, ItemStack> matrix = new HashMap<>();
    final ContainerCraftingBrewingstand inventory = gui.getMenu();
    matrix.put(0, inventory.getSlot(0).getItem());
    for (int slot = 1; slot <= 3; ++slot) {
        final ItemStack container = inventory.getSlot(1).getItem();
        if (!container.isEmpty()) {
            matrix.put(1, container);
            break;
        }
    }
    final TransferRecipeCraftingTeachingMessage message = new TransferRecipeCraftingTeachingMessage(matrix, false);
    Network.getNetwork().sendToServer(message);
}
Also used : ContainerCraftingBrewingstand(com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand) TransferRecipeCraftingTeachingMessage(com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ContainerCraftingBrewingstand

use of com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand in project minecolonies by Minecolonies.

the class TransferRecipeCraftingTeachingMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final PlayerEntity player = ctxIn.getSender();
    if (player.containerMenu instanceof ContainerCrafting) {
        final ContainerCrafting container = (ContainerCrafting) player.containerMenu;
        if (complete) {
            container.handleSlotClick(container.getSlot(1), itemStacks.getOrDefault(0, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(2), itemStacks.getOrDefault(1, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(3), itemStacks.getOrDefault(2, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(4), itemStacks.getOrDefault(3, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(5), itemStacks.getOrDefault(4, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(6), itemStacks.getOrDefault(5, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(7), itemStacks.getOrDefault(6, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(8), itemStacks.getOrDefault(7, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(9), itemStacks.getOrDefault(8, ItemStackUtils.EMPTY));
        } else {
            container.handleSlotClick(container.getSlot(1), itemStacks.getOrDefault(0, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(2), itemStacks.getOrDefault(1, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(3), itemStacks.getOrDefault(3, ItemStackUtils.EMPTY));
            container.handleSlotClick(container.getSlot(4), itemStacks.getOrDefault(4, ItemStackUtils.EMPTY));
        }
        container.broadcastChanges();
    } else if (player.containerMenu instanceof ContainerCraftingFurnace) {
        final ContainerCraftingFurnace container = (ContainerCraftingFurnace) player.containerMenu;
        container.setFurnaceInput(itemStacks.getOrDefault(0, ItemStack.EMPTY));
    } else if (player.containerMenu instanceof ContainerCraftingBrewingstand) {
        final ContainerCraftingBrewingstand container = (ContainerCraftingBrewingstand) player.containerMenu;
        container.setInput(itemStacks.getOrDefault(0, ItemStack.EMPTY));
        container.setContainer(itemStacks.getOrDefault(1, ItemStack.EMPTY));
    }
}
Also used : ContainerCraftingBrewingstand(com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with ContainerCraftingBrewingstand

use of com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand in project minecolonies by Minecolonies.

the class OpenCraftingGUIMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final ServerPlayerEntity player = ctxIn.getSender();
    if (player == null) {
        return;
    }
    final AbstractCraftingBuildingModule module = building.getModuleMatching(AbstractCraftingBuildingModule.class, m -> m.getId().equals(id));
    if (module.canLearn(ModCraftingTypes.SMELTING)) {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Furnace Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCraftingFurnace(id, inv, building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBlockPos(building.getID()).writeUtf(module.getId())));
    } else if (module.canLearn(ModCraftingTypes.BREWING)) {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Brewing Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCraftingBrewingstand(id, inv, building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBlockPos(building.getID()).writeUtf(module.getId())));
    } else {
        NetworkHooks.openGui(player, new INamedContainerProvider() {

            @NotNull
            @Override
            public ITextComponent getDisplayName() {
                return new StringTextComponent("Crafting GUI");
            }

            @NotNull
            @Override
            public Container createMenu(final int id, @NotNull final PlayerInventory inv, @NotNull final PlayerEntity player) {
                return new ContainerCrafting(id, inv, module.canLearn(ModCraftingTypes.LARGE_CRAFTING), building.getID(), module.getId());
            }
        }, buffer -> new PacketBuffer(buffer.writeBoolean(module.canLearn(ModCraftingTypes.LARGE_CRAFTING))).writeBlockPos(building.getID()).writeUtf(module.getId()));
    }
}
Also used : PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Container(net.minecraft.inventory.container.Container) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) ModCraftingTypes(com.minecolonies.api.crafting.ModCraftingTypes) ITextComponent(net.minecraft.util.text.ITextComponent) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) AbstractBuildingServerMessage(com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) IColony(com.minecolonies.api.colony.IColony) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) StringTextComponent(net.minecraft.util.text.StringTextComponent) NotNull(org.jetbrains.annotations.NotNull) ContainerCraftingBrewingstand(com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand) PacketBuffer(net.minecraft.network.PacketBuffer) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractCraftingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule) ContainerCrafting(com.minecolonies.api.inventory.container.ContainerCrafting) ITextComponent(net.minecraft.util.text.ITextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) NotNull(org.jetbrains.annotations.NotNull) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ContainerCraftingBrewingstand(com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand) Container(net.minecraft.inventory.container.Container) ContainerCraftingFurnace(com.minecolonies.api.inventory.container.ContainerCraftingFurnace) StringTextComponent(net.minecraft.util.text.StringTextComponent) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

ContainerCraftingBrewingstand (com.minecolonies.api.inventory.container.ContainerCraftingBrewingstand)3 ContainerCrafting (com.minecolonies.api.inventory.container.ContainerCrafting)2 ContainerCraftingFurnace (com.minecolonies.api.inventory.container.ContainerCraftingFurnace)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 IColony (com.minecolonies.api.colony.IColony)1 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)1 ModCraftingTypes (com.minecolonies.api.crafting.ModCraftingTypes)1 AbstractCraftingBuildingModule (com.minecolonies.coremod.colony.buildings.modules.AbstractCraftingBuildingModule)1 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)1 AbstractBuildingServerMessage (com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage)1 TransferRecipeCraftingTeachingMessage (com.minecolonies.coremod.network.messages.server.TransferRecipeCraftingTeachingMessage)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Container (net.minecraft.inventory.container.Container)1 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)1 ItemStack (net.minecraft.item.ItemStack)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)1