2015-05-25 17:00:54 +02:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-05-25 17:00:54 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.ChunkCoordinates;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class TileEntityPhantomPlacer extends TileEntityInventoryBase{
|
|
|
|
|
|
|
|
public static class TileEntityPhantomBreaker extends TileEntityPhantomPlacer{
|
|
|
|
|
|
|
|
public TileEntityPhantomBreaker(){
|
|
|
|
super(9, "phantomBreaker");
|
|
|
|
this.isBreaker = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public ChunkCoordinates boundPosition;
|
|
|
|
public World boundWorld;
|
|
|
|
|
|
|
|
public int currentTime;
|
2015-05-27 21:57:53 +02:00
|
|
|
public final int timeNeeded = ConfigIntValues.PHANTOM_PLACER_TIME.getValue();
|
2015-05-25 17:00:54 +02:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public final int defaultRange = ConfigIntValues.PHANTOM_PLACER_RANGE.getValue();
|
|
|
|
public int range;
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
public boolean isBreaker;
|
|
|
|
|
|
|
|
public TileEntityPhantomPlacer(int slots, String name){
|
|
|
|
super(slots, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileEntityPhantomPlacer(){
|
|
|
|
super(9, "phantomPlacer");
|
|
|
|
this.isBreaker = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
if(!worldObj.isRemote){
|
2015-06-12 19:12:06 +02:00
|
|
|
this.range = TileEntityPhantomface.upgradeRange(defaultRange, worldObj, xCoord, yCoord, zCoord);
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
if(!this.hasBoundPosition()){
|
|
|
|
this.boundPosition = null;
|
|
|
|
this.boundWorld = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.isBoundPositionInRange()){
|
|
|
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
|
|
|
if(this.currentTime > 0){
|
|
|
|
this.currentTime--;
|
|
|
|
if(this.currentTime <= 0){
|
|
|
|
if(this.isBreaker){
|
|
|
|
Block blockToBreak = boundWorld.getBlock(boundPosition.posX, boundPosition.posY, boundPosition.posZ);
|
|
|
|
if(blockToBreak != null && blockToBreak.getBlockHardness(boundWorld, boundPosition.posX, boundPosition.posY, boundPosition.posZ) > -1.0F){
|
|
|
|
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
|
|
|
int meta = boundWorld.getBlockMetadata(boundPosition.posX, boundPosition.posY, boundPosition.posZ);
|
|
|
|
drops.addAll(blockToBreak.getDrops(boundWorld, boundPosition.posX, boundPosition.posY, boundPosition.posZ, meta, 0));
|
|
|
|
|
|
|
|
if(TileEntityBreaker.addToInventory(this.slots, drops, false)){
|
|
|
|
boundWorld.playAuxSFX(2001, boundPosition.posX, boundPosition.posY, boundPosition.posZ, Block.getIdFromBlock(blockToBreak) + (meta << 12));
|
|
|
|
WorldUtil.breakBlockAtSide(ForgeDirection.UNKNOWN, boundWorld, boundPosition.posX, boundPosition.posY, boundPosition.posZ);
|
|
|
|
TileEntityBreaker.addToInventory(this.slots, drops, true);
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(boundWorld.getBlock(boundPosition.posX, boundPosition.posY, boundPosition.posZ).isReplaceable(boundWorld, boundPosition.posX, boundPosition.posY, boundPosition.posZ)){
|
2015-05-30 17:47:57 +02:00
|
|
|
int theSlot = TileEntityBreaker.testInventory(this.slots);
|
|
|
|
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(ForgeDirection.UNKNOWN, boundWorld, boundPosition.posX, boundPosition.posY, boundPosition.posZ, this.slots[theSlot]));
|
|
|
|
if(this.slots[0] != null && this.slots[0].stackSize <= 0) this.slots[0] = null;
|
2015-05-25 17:00:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else this.currentTime = this.timeNeeded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBoundPositionInRange(){
|
|
|
|
if(this.hasBoundPosition()){
|
|
|
|
int xDif = this.boundPosition.posX-this.xCoord;
|
|
|
|
int yDif = this.boundPosition.posY-this.yCoord;
|
|
|
|
int zDif = this.boundPosition.posZ-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasBoundPosition(){
|
|
|
|
if(this.boundPosition != null && this.boundWorld != null){
|
|
|
|
if(this.xCoord == this.boundPosition.posX && this.yCoord == this.boundPosition.posY && this.zCoord == this.boundPosition.posZ && this.worldObj == this.boundWorld){
|
|
|
|
this.boundPosition = null;
|
|
|
|
this.boundWorld = null;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.boundWorld == this.worldObj;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
super.writeToNBT(compound);
|
|
|
|
compound.setInteger("Time", currentTime);
|
|
|
|
if(this.hasBoundPosition()){
|
|
|
|
compound.setInteger("XCoordOfTileStored", boundPosition.posX);
|
|
|
|
compound.setInteger("YCoordOfTileStored", boundPosition.posY);
|
|
|
|
compound.setInteger("ZCoordOfTileStored", boundPosition.posZ);
|
|
|
|
compound.setInteger("WorldOfTileStored", boundWorld.provider.dimensionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
super.readFromNBT(compound);
|
|
|
|
int x = compound.getInteger("XCoordOfTileStored");
|
|
|
|
int y = compound.getInteger("YCoordOfTileStored");
|
|
|
|
int z = compound.getInteger("ZCoordOfTileStored");
|
|
|
|
if(x != 0 && y != 0 && z != 0){
|
|
|
|
this.boundPosition = new ChunkCoordinates(x, y, z);
|
|
|
|
this.boundWorld = DimensionManager.getWorld(compound.getInteger("WorldOfTileStored"));
|
2015-06-12 19:12:06 +02:00
|
|
|
this.markDirty();
|
2015-05-25 17:00:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2015-05-30 17:47:57 +02:00
|
|
|
return !this.isBreaker;
|
2015-05-25 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
2015-05-30 17:47:57 +02:00
|
|
|
return this.isBreaker;
|
2015-05-25 17:00:54 +02:00
|
|
|
}
|
|
|
|
}
|