ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/util/PosUtil.java

81 lines
2.7 KiB
Java
Raw Normal View History

2016-01-08 13:31:58 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("PosUtil.java") is part of the Actually Additions mod for Minecraft.
2016-01-08 13:31:58 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2016-01-08 13:31:58 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2016-01-08 13:31:58 +01:00
*/
package de.ellpeck.actuallyadditions.mod.util;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
2016-01-08 13:31:58 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
2016-01-08 13:31:58 +01:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class PosUtil{
2016-02-01 17:49:55 +01:00
public static Material getMaterial(BlockPos pos, IBlockAccess world){
2016-03-18 23:47:22 +01:00
return getBlock(pos, world).getMaterial(world.getBlockState(pos));
2016-02-01 17:49:55 +01:00
}
2016-01-08 13:31:58 +01:00
public static Block getBlock(BlockPos pos, IBlockAccess world){
if(pos != null){
IBlockState state = world.getBlockState(pos);
if(state != null){
return state.getBlock();
}
}
return null;
2016-01-08 13:31:58 +01:00
}
public static int getMetadata(BlockPos pos, IBlockAccess world){
2016-02-18 22:48:53 +01:00
Block block = getBlock(pos, world);
2016-03-18 15:42:06 +01:00
return block != null ? block.getMetaFromState(world.getBlockState(pos)) : 0;
}
public static int getMetadata(IBlockState state){
Block block = state.getBlock();
return block != null ? block.getMetaFromState(state) : 0;
2016-01-08 13:31:58 +01:00
}
public static BlockPos offset(BlockPos pos, int x, int y, int z){
return new BlockPos(pos.getX()+x, pos.getY()+y, pos.getZ()+z);
}
public static boolean setBlock(BlockPos pos, World world, Block block, int meta, int flag){
return world.setBlockState(pos, block.getStateFromMeta(meta), flag);
}
2016-03-18 23:47:22 +01:00
public static Vec3d toVec(BlockPos pos){
return new Vec3d(pos.getX(), pos.getY(), pos.getZ());
2016-01-08 13:31:58 +01:00
}
public static BlockPos copyPos(BlockPos pos){
return new BlockPos(pos.getX(), pos.getY(), pos.getZ());
}
public static ItemBlock getItemBlock(BlockPos pos, IBlockAccess world){
Item item = Item.getItemFromBlock(getBlock(pos, world));
if(item instanceof ItemBlock){
return (ItemBlock)item;
}
return null;
}
public static void setMetadata(BlockPos pos, World world, int meta, int flag){
world.setBlockState(pos, getBlock(pos, world).getStateFromMeta(meta), flag);
}
public static boolean areSamePos(BlockPos first, BlockPos second){
return first.getX() == second.getX() && first.getY() == second.getY() && first.getZ() == second.getZ();
}
}