ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java

101 lines
2.7 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("WorldPos.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
package ellpeck.actuallyadditions.util;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
2015-10-21 06:56:40 +02:00
import net.minecraftforge.common.DimensionManager;
public class WorldPos{
private int x;
private int y;
private int z;
2015-10-21 06:56:40 +02:00
private int worldID;
public WorldPos(World world, int x, int y, int z){
2015-10-27 20:58:42 +01:00
this(world.provider.dimensionId, x, y, z);
}
public WorldPos(int worldID, int x, int y, int z){
this.worldID = worldID;
this.x = x;
this.y = y;
this.z = z;
}
2015-10-27 20:58:42 +01:00
public int getWorldID(){
return this.worldID;
}
public TileEntity getTileEntity(){
2015-10-21 06:56:40 +02:00
return this.getWorld() != null ? this.getWorld().getTileEntity(this.x, this.y, this.z) : null;
}
2015-07-07 14:32:10 +02:00
2015-10-23 16:54:33 +02:00
public World getWorld(){
return DimensionManager.getWorld(this.worldID);
}
public Material getMaterial(){
2015-10-21 06:56:40 +02:00
return this.getWorld() != null ? this.getWorld().getBlock(this.x, this.y, this.z).getMaterial() : null;
}
public Item getItemBlock(){
2015-10-21 06:56:40 +02:00
return this.getWorld() != null ? Item.getItemFromBlock(this.getBlock()) : null;
}
2015-10-23 16:54:33 +02:00
public Block getBlock(){
return this.getWorld() != null ? this.getWorld().getBlock(this.x, this.y, this.z) : null;
}
public int getMetadata(){
2015-10-21 06:56:40 +02:00
return this.getWorld() != null ? this.getWorld().getBlockMetadata(this.x, this.y, this.z) : 0;
}
2015-07-07 14:32:10 +02:00
public boolean isEqual(WorldPos pos){
2015-10-21 06:56:40 +02:00
return pos != null && this.x == pos.getX() && this.y == pos.getY() && this.z == pos.getZ() && this.getWorld() == pos.getWorld();
2015-10-21 00:22:50 +02:00
}
2015-10-03 10:19:40 +02:00
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
public int getZ(){
return this.z;
}
2015-10-23 16:54:33 +02:00
public void update(){
if(this.getWorld() != null){
this.getWorld().markBlockForUpdate(this.x, this.y, this.z);
}
2015-10-03 10:19:40 +02:00
}
2015-07-07 14:32:10 +02:00
public WorldPos copy(){
2015-10-21 06:56:40 +02:00
return new WorldPos(this.getWorld(), this.x, this.y, this.z);
2015-07-07 14:32:10 +02:00
}
public String toString(){
2015-10-21 06:56:40 +02:00
return "["+this.x+", "+this.y+", "+this.z+" in world "+this.worldID+"]";
}
public Vec3 toVec(){
return Vec3.createVectorHelper(this.x, this.y, this.z);
}
}