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
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-07 11:51:05 +02:00
|
|
|
|
package ellpeck.actuallyadditions.util;
|
|
|
|
|
|
2015-07-07 12:49:34 +02:00
|
|
|
|
import net.minecraft.block.Block;
|
2015-07-20 06:39:52 +02:00
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
|
import net.minecraft.item.Item;
|
2015-07-07 12:49:34 +02:00
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-07-07 11:51:05 +02:00
|
|
|
|
import net.minecraft.world.World;
|
2015-10-21 06:56:40 +02:00
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2015-07-07 11:51:05 +02:00
|
|
|
|
|
|
|
|
|
public class WorldPos{
|
|
|
|
|
|
|
|
|
|
private int x;
|
|
|
|
|
private int y;
|
|
|
|
|
private int z;
|
2015-10-21 06:56:40 +02:00
|
|
|
|
private int worldID;
|
2015-07-07 11:51:05 +02:00
|
|
|
|
|
|
|
|
|
public WorldPos(World world, int x, int y, int z){
|
2015-10-21 06:56:40 +02:00
|
|
|
|
this.worldID = world.provider.dimensionId;
|
2015-07-07 11:51:05 +02:00
|
|
|
|
this.x = x;
|
|
|
|
|
this.y = y;
|
|
|
|
|
this.z = z;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 12:49:34 +02:00
|
|
|
|
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 12:49:34 +02:00
|
|
|
|
}
|
2015-07-07 14:32:10 +02:00
|
|
|
|
|
2015-10-23 16:54:33 +02:00
|
|
|
|
public World getWorld(){
|
|
|
|
|
return DimensionManager.getWorld(this.worldID);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 06:39:52 +02:00
|
|
|
|
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;
|
2015-07-20 06:39:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Item getItemBlock(){
|
2015-10-21 06:56:40 +02:00
|
|
|
|
return this.getWorld() != null ? Item.getItemFromBlock(this.getBlock()) : null;
|
2015-07-20 06:39:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 06:39:52 +02:00
|
|
|
|
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-20 06:39:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
2015-10-20 00:22:36 +02:00
|
|
|
|
|
|
|
|
|
public String toString(){
|
2015-10-21 06:56:40 +02:00
|
|
|
|
return "["+this.x+", "+this.y+", "+this.z+" in world "+this.worldID+"]";
|
2015-10-20 00:22:36 +02:00
|
|
|
|
}
|
2015-07-07 11:51:05 +02:00
|
|
|
|
}
|