2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("TileEntityPhantomPlacer.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-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-08-10 10:37:44 +02:00
|
|
|
|
import ellpeck.actuallyadditions.inventory.GuiHandler;
|
2015-07-07 11:51:05 +02:00
|
|
|
|
import ellpeck.actuallyadditions.util.WorldPos;
|
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.world.World;
|
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements IPhantomTile{
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
|
|
public static class TileEntityPhantomBreaker extends TileEntityPhantomPlacer{
|
|
|
|
|
|
|
|
|
|
public TileEntityPhantomBreaker(){
|
|
|
|
|
super(9, "phantomBreaker");
|
|
|
|
|
this.isBreaker = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 11:51:05 +02:00
|
|
|
|
public WorldPos boundPosition;
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
|
|
public int currentTime;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
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-08-15 20:41:45 +02:00
|
|
|
|
this.range = TileEntityPhantomface.upgradeRange(ConfigIntValues.PHANTOM_PLACER_RANGE.getValue(), worldObj, xCoord, yCoord, zCoord);
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
|
|
if(!this.hasBoundPosition()){
|
|
|
|
|
this.boundPosition = null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
if(this.isBoundThingInRange()){
|
2015-05-25 17:00:54 +02:00
|
|
|
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
|
|
|
|
if(this.currentTime > 0){
|
|
|
|
|
this.currentTime--;
|
|
|
|
|
if(this.currentTime <= 0){
|
|
|
|
|
if(this.isBreaker){
|
2015-07-07 11:51:05 +02:00
|
|
|
|
Block blockToBreak = boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
|
|
|
|
if(blockToBreak != null && blockToBreak.getBlockHardness(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) > -1.0F){
|
2015-05-25 17:00:54 +02:00
|
|
|
|
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
2015-07-07 11:51:05 +02:00
|
|
|
|
int meta = boundPosition.getWorld().getBlockMetadata(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
|
|
|
|
drops.addAll(blockToBreak.getDrops(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), meta, 0));
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
2015-07-07 12:32:25 +02:00
|
|
|
|
if(WorldUtil.addToInventory(this.slots, drops, false)){
|
2015-07-07 11:51:05 +02:00
|
|
|
|
boundPosition.getWorld().playAuxSFX(2001, boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), Block.getIdFromBlock(blockToBreak)+(meta << 12));
|
|
|
|
|
WorldUtil.breakBlockAtSide(ForgeDirection.UNKNOWN, boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
2015-07-07 12:32:25 +02:00
|
|
|
|
WorldUtil.addToInventory(this.slots, drops, true);
|
2015-05-25 17:00:54 +02:00
|
|
|
|
this.markDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2015-07-07 11:51:05 +02:00
|
|
|
|
if(boundPosition.getWorld().getBlock(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()).isReplaceable(boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ())){
|
2015-07-07 12:34:20 +02:00
|
|
|
|
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
2015-07-07 11:51:05 +02:00
|
|
|
|
this.setInventorySlotContents(theSlot, WorldUtil.placeBlockAtSide(ForgeDirection.UNKNOWN, boundPosition.getWorld(), boundPosition.getX(), boundPosition.getY(), boundPosition.getZ(), this.slots[theSlot]));
|
2015-06-21 02:28:49 +02:00
|
|
|
|
if(this.slots[theSlot] != null && this.slots[theSlot].stackSize <= 0) this.slots[theSlot] = null;
|
2015-05-25 17:00:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-15 20:41:45 +02:00
|
|
|
|
else this.currentTime = ConfigIntValues.PHANTOM_PLACER_TIME.getValue();
|
2015-05-25 17:00:54 +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(){
|
2015-05-25 17:00:54 +02:00
|
|
|
|
if(this.hasBoundPosition()){
|
2015-07-07 11:51:05 +02:00
|
|
|
|
int xDif = this.boundPosition.getX()-this.xCoord;
|
|
|
|
|
int yDif = this.boundPosition.getY()-this.yCoord;
|
|
|
|
|
int zDif = this.boundPosition.getZ()-this.zCoord;
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
|
|
if(xDif >= -this.range && xDif <= this.range){
|
|
|
|
|
if(yDif >= -this.range && yDif <= this.range){
|
2015-07-07 16:35:37 +02:00
|
|
|
|
if(zDif >= -this.range && zDif <= this.range){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-05-25 17:00:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
|
@Override
|
|
|
|
|
public WorldPos getBoundPosition(){
|
|
|
|
|
return this.boundPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getGuiID(){
|
|
|
|
|
return GuiHandler.GuiTypes.PHANTOM_PLACER.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getRange(){
|
|
|
|
|
return this.range;
|
2015-05-25 17:00:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-22 19:47:20 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void setBoundPosition(WorldPos pos){
|
|
|
|
|
this.boundPosition = pos == null ? null : pos.copy();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
|
super.writeToNBT(compound);
|
|
|
|
|
compound.setInteger("Time", currentTime);
|
|
|
|
|
if(this.hasBoundPosition()){
|
2015-07-07 11:51:05 +02:00
|
|
|
|
compound.setInteger("XCoordOfTileStored", boundPosition.getX());
|
|
|
|
|
compound.setInteger("YCoordOfTileStored", boundPosition.getY());
|
|
|
|
|
compound.setInteger("ZCoordOfTileStored", boundPosition.getZ());
|
|
|
|
|
compound.setInteger("WorldOfTileStored", boundPosition.getWorld().provider.dimensionId);
|
2015-05-25 17:00:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
|
super.readFromNBT(compound);
|
|
|
|
|
int x = compound.getInteger("XCoordOfTileStored");
|
|
|
|
|
int y = compound.getInteger("YCoordOfTileStored");
|
|
|
|
|
int z = compound.getInteger("ZCoordOfTileStored");
|
2015-07-07 11:51:05 +02:00
|
|
|
|
World world = DimensionManager.getWorld(compound.getInteger("WorldOfTileStored"));
|
|
|
|
|
if(x != 0 && y != 0 && z != 0 && world != null){
|
|
|
|
|
this.boundPosition = new WorldPos(world, x, y, z);
|
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
|
|
|
|
}
|
|
|
|
|
}
|