lyonlancer5.karasu.lib.WorldCoord.java Source code

Java tutorial

Introduction

Here is the source code for lyonlancer5.karasu.lib.WorldCoord.java

Source

/***************************************************************************\
* Copyright 2016 [Lyonlancer5]                                              *
*                                                                           *
* 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 lyonlancer5.karasu.lib;

import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

import org.apache.commons.lang3.builder.HashCodeBuilder;

public class WorldCoord extends BlockPos {// implements Comparable<WorldCoord> {

    //public int x;
    //public int y;
    //public int z;

    public WorldCoord(int x, int y, int z) {
        //this.x = x;
        //this.y = y;
        //this.z = z;
        super(x, y, z);
    }

    public WorldCoord(TileEntity tile) {
        //x = tile.xCoord;
        //y = tile.yCoord;
        //z = tile.zCoord;
        super(tile.xCoord, tile.yCoord, tile.zCoord);
    }

    public WorldCoord add(ForgeDirection dir) {
        return new WorldCoord(getX() + dir.offsetX, getY() + dir.offsetY, getZ() + dir.offsetZ);
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(getX()).append(getY()).append(getZ()).hashCode();
    }

    @Override
    public int compareTo(Vec3i wc) {
        if (wc instanceof WorldCoord) {
            WorldCoord wcx = (WorldCoord) wc;
            int legthThis = getX() * getX() + getY() * getY() + getZ() * getZ();
            int legthOther = wcx.getX() * wcx.getX() + wcx.getY() * wcx.getY() + wcx.getZ() * wcx.getZ();

            return Integer.compare(legthThis, legthOther);
        }
        return super.compareTo(wc);
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof WorldCoord))
            return false;
        WorldCoord wc = (WorldCoord) obj;

        return getX() == wc.getX() && getY() == wc.getY() && getZ() == wc.getZ();
    }

    @Override
    public String toString() {
        return "Coord: " + getX() + ", " + getY() + ", " + getZ();
    }
}