2015-10-10 02:58:07 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityPhantomEnergyface.java") is part of the Actually Additions mod for Minecraft.
|
2015-10-10 02:58:07 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-10-10 02:58:07 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-10-10 02:58:07 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
|
|
|
import cofh.api.energy.IEnergyProvider;
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
2015-10-10 02:58:07 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
2016-02-16 21:49:44 +01:00
|
|
|
public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements IEnergyReceiver, IEnergyProvider{
|
2015-10-10 02:58:07 +02:00
|
|
|
|
|
|
|
public TileEntityPhantomEnergyface(){
|
|
|
|
super("energyface");
|
|
|
|
this.type = BlockPhantom.Type.ENERGYFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 18:20:59 +01:00
|
|
|
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
|
2015-10-10 02:58:07 +02:00
|
|
|
return this.isBoundThingInRange() && this.getReceiver() != null ? this.getReceiver().receiveEnergy(from, maxReceive, simulate) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 18:20:59 +01:00
|
|
|
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate){
|
2015-10-10 02:58:07 +02:00
|
|
|
return this.isBoundThingInRange() && this.getProvider() != null ? this.getProvider().extractEnergy(from, maxExtract, simulate) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 18:20:59 +01:00
|
|
|
public int getEnergyStored(EnumFacing from){
|
2015-10-10 02:58:07 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
if(this.getProvider() != null){
|
|
|
|
return this.getProvider().getEnergyStored(from);
|
|
|
|
}
|
|
|
|
if(this.getReceiver() != null){
|
|
|
|
return this.getReceiver().getEnergyStored(from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 18:20:59 +01:00
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
2015-10-10 02:58:07 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
if(this.getProvider() != null){
|
|
|
|
return this.getProvider().getMaxEnergyStored(from);
|
|
|
|
}
|
|
|
|
if(this.getReceiver() != null){
|
|
|
|
return this.getReceiver().getMaxEnergyStored(from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnergyProvider getProvider(){
|
2015-12-23 01:43:49 +01:00
|
|
|
if(this.boundPosition != null){
|
2016-05-02 17:46:53 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
2015-10-10 02:58:07 +02:00
|
|
|
if(tile instanceof IEnergyProvider){
|
|
|
|
return (IEnergyProvider)tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnergyReceiver getReceiver(){
|
2015-12-23 01:43:49 +01:00
|
|
|
if(this.boundPosition != null){
|
2016-05-02 17:46:53 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
2015-10-10 02:58:07 +02:00
|
|
|
if(tile instanceof IEnergyReceiver){
|
|
|
|
return (IEnergyReceiver)tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBoundThingInRange(){
|
2016-05-02 17:46:53 +02:00
|
|
|
return super.isBoundThingInRange() && (this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyReceiver || this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyProvider);
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 18:20:59 +01:00
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
2015-10-10 02:58:07 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
if(this.getProvider() != null){
|
|
|
|
return this.getProvider().canConnectEnergy(from);
|
|
|
|
}
|
|
|
|
if(this.getReceiver() != null){
|
|
|
|
return this.getReceiver().canConnectEnergy(from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|