2015-12-23 01:43:49 +01:00
|
|
|
/*
|
2015-12-30 22:02:15 +01:00
|
|
|
* This file ("Position.java") is part of the Actually Additions Mod for Minecraft.
|
2015-12-23 01:43:49 +01:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-12-23 01:43:49 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-12-23 01:43:49 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.api;
|
2015-12-23 01:43:49 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-12-23 01:43:49 +01:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-12-23 01:43:49 +01:00
|
|
|
import net.minecraft.util.Vec3;
|
2016-01-07 19:47:53 +01:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-12-23 01:43:49 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
/**
|
|
|
|
* This utility class describes a position in the world
|
|
|
|
*/
|
2016-01-07 19:04:29 +01:00
|
|
|
public class Position extends BlockPos{
|
2015-12-23 01:43:49 +01:00
|
|
|
|
|
|
|
public Position(int x, int y, int z){
|
2016-01-07 19:04:29 +01:00
|
|
|
super(x, y, z);
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public TileEntity getTileEntity(IBlockAccess world){
|
2016-01-07 19:04:29 +01:00
|
|
|
return world != null ? world.getTileEntity(this) : null;
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public Material getMaterial(IBlockAccess world){
|
2016-01-07 18:20:59 +01:00
|
|
|
if(world != null){
|
|
|
|
Block block = this.getBlock(world);
|
|
|
|
if(block != null){
|
|
|
|
return block.getMaterial();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public Item getItemBlock(IBlockAccess world){
|
2015-12-23 01:43:49 +01:00
|
|
|
return world != null ? Item.getItemFromBlock(this.getBlock(world)) : null;
|
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public Block getBlock(IBlockAccess world){
|
2016-01-07 18:20:59 +01:00
|
|
|
if(world != null){
|
|
|
|
IBlockState state = this.getBlockState(world);
|
|
|
|
if(state != null){
|
|
|
|
return state.getBlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public int getMetadata(IBlockAccess world){
|
2016-01-07 18:20:59 +01:00
|
|
|
//TODO Fix meta
|
|
|
|
return /*world != null ? world.getBlockMetadata(this.x, this.y, this.z) : */0;
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public void setMetadata(IBlockAccess world, int meta, int flag){
|
2016-01-07 18:20:59 +01:00
|
|
|
//TODO Fix meta
|
|
|
|
/*if(world != null){
|
2015-12-23 01:43:49 +01:00
|
|
|
world.setBlockMetadataWithNotify(this.x, this.y, this.z, meta, flag);
|
2016-01-07 18:20:59 +01:00
|
|
|
}*/
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEqual(Position pos){
|
2016-01-07 19:04:29 +01:00
|
|
|
return pos != null && this.getX() == pos.getX() && this.getY() == pos.getY() && this.getZ() == pos.getZ();
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 18:20:59 +01:00
|
|
|
public boolean setBlock(World world, Block block, int meta, int flag){
|
|
|
|
//TODO Fix meta
|
|
|
|
return world != null && this.setBlockState(world, block.getDefaultState(), meta, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean setBlockState(World world, IBlockState state, int meta, int flag){
|
|
|
|
//TODO Fix meta
|
2016-01-07 19:04:29 +01:00
|
|
|
return world.setBlockState(this, state, flag);
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Position copy(){
|
2016-01-07 19:04:29 +01:00
|
|
|
return new Position(this.getX(), this.getY(), this.getZ());
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String toString(){
|
2016-01-07 19:04:29 +01:00
|
|
|
return "["+this.getX()+", "+this.getY()+", "+this.getZ()+"]";
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Vec3 toVec(){
|
2016-01-07 19:04:29 +01:00
|
|
|
return new Vec3(this.getX(), this.getY(), this.getZ());
|
2016-01-07 18:20:59 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public IBlockState getBlockState(IBlockAccess world){
|
2016-01-07 19:04:29 +01:00
|
|
|
return world != null ? world.getBlockState(this) : null;
|
2016-01-07 18:20:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Position getOffsetPosition(EnumFacing side){
|
2016-01-07 19:04:29 +01:00
|
|
|
return new Position(this.getX()+side.getFrontOffsetX(), this.getY()+side.getFrontOffsetY(), this.getZ()+side.getFrontOffsetZ());
|
2016-01-07 18:20:59 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 19:47:53 +01:00
|
|
|
public Position getOffsetPosition(int x, int y, int z){
|
|
|
|
return new Position(this.getX()+x, this.getY()+y, this.getZ()+z);
|
|
|
|
}
|
|
|
|
|
2016-01-07 18:20:59 +01:00
|
|
|
public static Position fromTileEntity(TileEntity tile){
|
2016-01-07 19:47:53 +01:00
|
|
|
return fromBlockPos(tile.getPos());
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|
2016-01-07 19:04:29 +01:00
|
|
|
|
|
|
|
public static Position fromBlockPos(BlockPos pos){
|
|
|
|
return (Position)pos;
|
|
|
|
}
|
2015-12-23 01:43:49 +01:00
|
|
|
}
|