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
|
|
|
|
2016-07-24 02:54:07 +02:00
|
|
|
import cofh.api.energy.IEnergyConnection;
|
|
|
|
import cofh.api.energy.IEnergyHandler;
|
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;
|
2016-07-24 02:54:07 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
|
|
|
|
import net.darkhax.tesla.api.ITeslaConsumer;
|
|
|
|
import net.darkhax.tesla.api.ITeslaHolder;
|
|
|
|
import net.darkhax.tesla.api.ITeslaProducer;
|
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
|
|
|
if(this.isBoundThingInRange()){
|
2016-07-24 02:54:07 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IEnergyReceiver){
|
|
|
|
return ((IEnergyReceiver)tile).receiveEnergy(from, maxReceive, simulate);
|
|
|
|
}
|
|
|
|
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, from)){
|
|
|
|
ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, from);
|
|
|
|
if(cap != null){
|
|
|
|
return (int)cap.givePower(maxReceive, simulate);
|
|
|
|
}
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-24 02:54:07 +02:00
|
|
|
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate){
|
2015-10-10 02:58:07 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
2016-07-24 02:54:07 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IEnergyProvider){
|
|
|
|
return ((IEnergyProvider)tile).extractEnergy(from, maxExtract, simulate);
|
|
|
|
}
|
|
|
|
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaProducer, from)){
|
|
|
|
ITeslaProducer cap = tile.getCapability(TeslaUtil.teslaProducer, from);
|
|
|
|
if(cap != null){
|
|
|
|
return (int)cap.takePower(maxExtract, simulate);
|
|
|
|
}
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-24 02:54:07 +02:00
|
|
|
@Override
|
|
|
|
public int getEnergyStored(EnumFacing from){
|
|
|
|
if(this.isBoundThingInRange()){
|
2016-05-02 17:46:53 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
2016-07-24 02:54:07 +02:00
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IEnergyHandler){
|
|
|
|
return ((IEnergyHandler)tile).getEnergyStored(from);
|
|
|
|
}
|
|
|
|
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){
|
|
|
|
ITeslaHolder cap = tile.getCapability(TeslaUtil.teslaHolder, from);
|
|
|
|
if(cap != null){
|
|
|
|
return (int)cap.getStoredPower();
|
|
|
|
}
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-24 02:54:07 +02:00
|
|
|
return 0;
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 02:54:07 +02:00
|
|
|
@Override
|
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
|
|
|
if(this.isBoundThingInRange()){
|
2016-05-02 17:46:53 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
2016-07-24 02:54:07 +02:00
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IEnergyHandler){
|
|
|
|
return ((IEnergyHandler)tile).getMaxEnergyStored(from);
|
|
|
|
}
|
|
|
|
else if(teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){
|
|
|
|
ITeslaHolder cap = tile.getCapability(TeslaUtil.teslaHolder, from);
|
|
|
|
if(cap != null){
|
|
|
|
return (int)cap.getCapacity();
|
|
|
|
}
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-24 02:54:07 +02:00
|
|
|
return 0;
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBoundThingInRange(){
|
2016-07-24 02:54:07 +02:00
|
|
|
if(super.isBoundThingInRange()){
|
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
return tile != null && (tile instanceof IEnergyHandler || (teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, null)));
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return false;
|
|
|
|
}
|
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()){
|
2016-07-24 02:54:07 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IEnergyConnection){
|
|
|
|
return ((IEnergyConnection)tile).canConnectEnergy(from);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from);
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|