2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("TileEntityPhantomface.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-05-20 22:39:43 +02:00
|
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
import ellpeck.actuallyadditions.blocks.BlockPhantom;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-07-07 11:51:05 +02:00
|
|
|
|
import ellpeck.actuallyadditions.util.WorldPos;
|
2015-05-29 18:17:28 +02:00
|
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
import net.minecraft.block.Block;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
public class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-07-07 11:51:05 +02:00
|
|
|
|
public WorldPos boundPosition;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-08-10 22:55:34 +02:00
|
|
|
|
public BlockPhantom.Type type;
|
2015-05-27 21:57:53 +02:00
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
public int range;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-07-07 16:22:37 +02:00
|
|
|
|
private int rangeBefore;
|
|
|
|
|
private WorldPos boundPosBefore;
|
|
|
|
|
private Block boundBlockBefore;
|
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
|
public TileEntityPhantomface(String name){
|
|
|
|
|
super(0, name);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void updateEntity(){
|
|
|
|
|
if(!worldObj.isRemote){
|
2015-08-15 20:41:45 +02:00
|
|
|
|
this.range = upgradeRange(ConfigIntValues.PHANTOMFACE_RANGE.getValue(), worldObj, xCoord, yCoord, zCoord);
|
2015-05-27 21:57:53 +02:00
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
if(!this.hasBoundPosition()){
|
2015-06-12 19:12:06 +02:00
|
|
|
|
this.boundPosition = null;
|
2015-05-27 21:57:53 +02:00
|
|
|
|
}
|
2015-07-07 16:22:37 +02:00
|
|
|
|
|
2015-08-11 00:39:57 +02:00
|
|
|
|
if(this.boundPosition != this.boundPosBefore || (this.boundPosition != null && this.boundPosition.getBlock() != this.boundBlockBefore) || this.rangeBefore != this.range){
|
2015-07-07 16:22:37 +02:00
|
|
|
|
this.rangeBefore = this.range;
|
|
|
|
|
this.boundPosBefore = this.boundPosition;
|
|
|
|
|
this.boundBlockBefore = this.boundPosition == null ? null : this.boundPosition.getBlock();
|
|
|
|
|
WorldUtil.updateTileAndTilesAround(this);
|
|
|
|
|
}
|
2015-05-27 21:57:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
|
public static int upgradeRange(int defaultRange, World world, int x, int y, int z){
|
|
|
|
|
int newRange = defaultRange;
|
|
|
|
|
for(int i = 0; i < 3; i++){
|
|
|
|
|
Block block = world.getBlock(x, y+1+i, z);
|
|
|
|
|
if(block == InitBlocks.blockPhantomBooster){
|
|
|
|
|
newRange = newRange*2;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-06-12 19:12:06 +02:00
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
return newRange;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean hasBoundPosition(){
|
|
|
|
|
if(this.boundPosition != null && this.boundPosition.getWorld() != null){
|
|
|
|
|
if(this.boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) instanceof IPhantomTile || (this.xCoord == this.boundPosition.getX() && this.yCoord == this.boundPosition.getY() && this.zCoord == this.boundPosition.getZ() && this.worldObj == this.boundPosition.getWorld())){
|
|
|
|
|
this.boundPosition = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return this.boundPosition.getWorld() == this.worldObj;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isBoundThingInRange(){
|
|
|
|
|
if(this.hasBoundPosition()){
|
|
|
|
|
int xDif = this.boundPosition.getX()-this.xCoord;
|
|
|
|
|
int yDif = this.boundPosition.getY()-this.yCoord;
|
|
|
|
|
int zDif = this.boundPosition.getZ()-this.zCoord;
|
|
|
|
|
|
|
|
|
|
if(xDif >= -this.range && xDif <= this.range){
|
|
|
|
|
if(yDif >= -this.range && yDif <= this.range){
|
|
|
|
|
if(zDif >= -this.range && zDif <= this.range){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public WorldPos getBoundPosition(){
|
|
|
|
|
return this.boundPosition;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void setBoundPosition(WorldPos pos){
|
|
|
|
|
this.boundPosition = pos == null ? null : pos.copy();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
@Override
|
|
|
|
|
public int getGuiID(){
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getRange(){
|
|
|
|
|
return this.range;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
|
@Override
|
2015-10-18 15:28:06 +02:00
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
|
super.readSyncableNBT(compound, sync);
|
2015-10-03 10:19:40 +02:00
|
|
|
|
int x = compound.getInteger("XCoordOfTileStored");
|
|
|
|
|
int y = compound.getInteger("YCoordOfTileStored");
|
|
|
|
|
int z = compound.getInteger("ZCoordOfTileStored");
|
|
|
|
|
World world = DimensionManager.getWorld(compound.getInteger("WorldOfTileStored"));
|
|
|
|
|
if(x != 0 && y != 0 && z != 0 && world != null){
|
|
|
|
|
this.boundPosition = new WorldPos(world, x, y, z);
|
|
|
|
|
this.markDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 22:13:57 +02:00
|
|
|
|
@Override
|
2015-10-18 15:28:06 +02:00
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
|
super.writeSyncableNBT(compound, sync);
|
2015-10-03 22:13:57 +02:00
|
|
|
|
if(this.hasBoundPosition()){
|
|
|
|
|
compound.setInteger("XCoordOfTileStored", boundPosition.getX());
|
|
|
|
|
compound.setInteger("YCoordOfTileStored", boundPosition.getY());
|
|
|
|
|
compound.setInteger("ZCoordOfTileStored", boundPosition.getZ());
|
|
|
|
|
compound.setInteger("WorldOfTileStored", boundPosition.getWorld().provider.dimensionId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|