/*
 * Copyright 2014 Matthew Collins
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.thinkofdeath.mapviewer.shared.block.blocks;

import uk.co.thinkofdeath.mapviewer.shared.Face;
import uk.co.thinkofdeath.mapviewer.shared.IMapViewer;
import uk.co.thinkofdeath.mapviewer.shared.Texture;
import uk.co.thinkofdeath.mapviewer.shared.block.Block;
import uk.co.thinkofdeath.mapviewer.shared.block.BlockFactory;
import uk.co.thinkofdeath.mapviewer.shared.block.StateMap;
import uk.co.thinkofdeath.mapviewer.shared.block.states.BooleanState;
import uk.co.thinkofdeath.mapviewer.shared.model.Model;
import uk.co.thinkofdeath.mapviewer.shared.model.ModelFace;

public class BlockPortal extends BlockFactory {

    public static final String ROTATED = "rotated";

    private final Texture texture;

    public BlockPortal(IMapViewer iMapViewer) {
        super(iMapViewer);
        addState(ROTATED, new BooleanState());
        texture = mapViewer.getTexture("portal");
    }

    @Override
    protected Block createBlock(StateMap states) {
        return new BlockImpl(states);
    }

    private class BlockImpl extends Block {

        BlockImpl(StateMap state) {
            super(BlockPortal.this, state);
        }

        @Override
        public int getLegacyData() {
            return this.<Boolean>getState(ROTATED) ? 1 : 2;
        }

        @Override
        public Model getModel() {
            if (model == null) {
                model = new Model();

                model.addFace(new ModelFace(Face.LEFT, texture, 0, 0, 16, 16, 10));
                model.addFace(new ModelFace(Face.RIGHT, texture, 0, 0, 16, 16, 6));

                if (getState(ROTATED)) {
                    model.rotateY(90);
                }
            }
            return model;
        }
    }
}

@@ -1042,23 +1042,23 @@
 .states.
-Boolean
+Integer
 State;%0Ai
@@ -1420,21 +1420,25 @@
 new 
-Boolean
+Integer
 State(
+0, 2
 ));%0A
@@ -1824,15 +1824,15 @@
 is.%3C
-Boolean
+Integer
 %3Eget
@@ -1849,16 +1849,8 @@
 TED)
- ? 1 : 2
 ;%0A  
@@ -2170,16 +2170,30 @@
     if (
+this.%3CInteger%3E
 getState
@@ -2201,16 +2201,21 @@
 ROTATED)
+ == 1
 ) %7B%0A    

Fix portals