package org.konstructs.furnace;

import akka.actor.ActorRef;
import akka.actor.Props;
import konstructs.api.*;
import konstructs.api.messages.*;
import konstructs.plugin.KonstructsActor;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class FurnaceViewActor extends KonstructsActor {

    /*
     *   [A]         - Input
     *        [C]    - Output
     *   [B]         - Fuel
     *
     */

    private InventoryView inputView = new InventoryView(6, 2, 1, 1);
    private InventoryView fuelView = new InventoryView(2, 2, 1, 1);
    private InventoryView outputView = new InventoryView(4, 4, 1, 1);
    private Map<InventoryId, InventoryView> inventoryViewMapping = new HashMap<>();

    private ActorRef player;
    private UUID blockId;

    private static final InventoryId INV_FUEL = InventoryId.fromString("org/konstructs/FUEL");

    public FurnaceViewActor(ActorRef universe, ActorRef player, UUID blockId) {
        super(universe);

        this.player = player;
        this.blockId = blockId;

        inventoryViewMapping.put(InventoryId.INPUT, inputView);
        inventoryViewMapping.put(InventoryId.OUTPUT, outputView);
        inventoryViewMapping.put(INV_FUEL, fuelView);

        player.tell(new ConnectView(getSelf(), View.EMPTY), getSelf());
        getUniverse().tell(new GetInventoriesView(blockId, inventoryViewMapping), player);
    }

    private boolean foo(Object message) {
        if(message instanceof PutViewStack) {
            PutViewStack putViewStack = (PutViewStack)message;
            for (Map.Entry<InventoryId, InventoryView> e : inventoryViewMapping.entrySet()) {
                if (e.getValue().contains(putViewStack.getPosition())) {
                    getUniverse().tell(new PutStackIntoSlot(blockId, e.getKey(), e.getValue().translate(putViewStack.getPosition()), putViewStack.getStack()), player);
                    getUniverse().tell(new GetInventoriesView(blockId, inventoryViewMapping), player);
                }
            }
            return true;
        } else if (message instanceof RemoveViewStack) {
            RemoveViewStack removeViewStack = (RemoveViewStack)message;
            for (Map.Entry<InventoryId, InventoryView> e : inventoryViewMapping.entrySet()) {
                if (e.getValue().contains(removeViewStack.getPosition())) {
                    getUniverse().tell(new RemoveStackFromSlot(blockId, e.getKey(), e.getValue().translate(removeViewStack.getPosition()), removeViewStack.getAmount()), player);
                    getUniverse().tell(new GetInventoriesView(blockId, inventoryViewMapping), player);
                }
            }
            return true;
        }
        return false;
    }

    @Override
    public void onReceive(Object message) {
        if (message instanceof PutViewStack && outputView.contains(((PutViewStack)message).getPosition())) {
            player.tell(new ReceiveStack(((PutViewStack)message).getStack()), getSelf());
        } else if (foo(message)) {
            // pass
        } else if(message instanceof CloseView) {
            getContext().stop(getSelf());
        } else {
            super.onReceive(message);
        }
    }

    public static Props props(ActorRef universe, ActorRef player, UUID blockId) {
        return Props.create(FurnaceViewActor.class, universe, player, blockId);
    }
}

@@ -1392,1330 +1392,8 @@
  %7D%0A%0A
-    private boolean foo(Object message) %7B%0A        if(message instanceof PutViewStack) %7B%0A            PutViewStack putViewStack = (PutViewStack)message;%0A            for (Map.Entry%3CInventoryId, InventoryView%3E e : inventoryViewMapping.entrySet()) %7B%0A                if (e.getValue().contains(putViewStack.getPosition())) %7B%0A                    getUniverse().tell(new PutStackIntoSlot(blockId, e.getKey(), e.getValue().translate(putViewStack.getPosition()), putViewStack.getStack()), player);%0A                    getUniverse().tell(new GetInventoriesView(blockId, inventoryViewMapping), player);%0A                %7D%0A            %7D%0A            return true;%0A        %7D else if (message instanceof RemoveViewStack) %7B%0A            RemoveViewStack removeViewStack = (RemoveViewStack)message;%0A            for (Map.Entry%3CInventoryId, InventoryView%3E e : inventoryViewMapping.entrySet()) %7B%0A                if (e.getValue().contains(removeViewStack.getPosition())) %7B%0A                    getUniverse().tell(new RemoveStackFromSlot(blockId, e.getKey(), e.getValue().translate(removeViewStack.getPosition()), removeViewStack.getAmount()), player);%0A                    getUniverse().tell(new GetInventoriesView(blockId, inventoryViewMapping), player);%0A                %7D%0A            %7D%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A
     
@@ -1402,16 +1402,16 @@
 verride%0A
+
     publ
@@ -1668,19 +1668,107 @@
 if (
-foo(message
+View.manageViewMessagesForInventories(message, blockId, inventoryViewMapping, getUniverse(), player
 )) %7B

Use convenience method from the API.