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-07-25 02:07:16 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
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;
|
2016-11-26 19:00:02 +01:00
|
|
|
import net.minecraftforge.energy.CapabilityEnergy;
|
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
2016-08-31 20:16:36 +02:00
|
|
|
public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ICustomEnergyReceiver, ISharingEnergyProvider{
|
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);
|
|
|
|
}
|
2016-11-26 19:00:02 +01:00
|
|
|
else if(tile.hasCapability(CapabilityEnergy.ENERGY, from)){
|
|
|
|
IEnergyStorage cap = tile.getCapability(CapabilityEnergy.ENERGY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.receiveEnergy(maxReceive, simulate);
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 02:07:16 +02:00
|
|
|
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, from)){
|
2016-07-24 02:54:07 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-11-26 19:00:02 +01:00
|
|
|
else if(tile.hasCapability(CapabilityEnergy.ENERGY, from)){
|
|
|
|
IEnergyStorage cap = tile.getCapability(CapabilityEnergy.ENERGY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.extractEnergy(maxExtract, simulate);
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 02:07:16 +02:00
|
|
|
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaProducer, from)){
|
2016-07-24 02:54:07 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-11-26 19:00:02 +01:00
|
|
|
else if(tile.hasCapability(CapabilityEnergy.ENERGY, from)){
|
|
|
|
IEnergyStorage cap = tile.getCapability(CapabilityEnergy.ENERGY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.getEnergyStored();
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 02:07:16 +02:00
|
|
|
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){
|
2016-07-24 02:54:07 +02:00
|
|
|
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);
|
|
|
|
}
|
2016-11-26 19:00:02 +01:00
|
|
|
else if(tile.hasCapability(CapabilityEnergy.ENERGY, from)){
|
|
|
|
IEnergyStorage cap = tile.getCapability(CapabilityEnergy.ENERGY, from);
|
|
|
|
if(cap != null){
|
|
|
|
return cap.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 02:07:16 +02:00
|
|
|
else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from)){
|
2016-07-24 02:54:07 +02:00
|
|
|
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);
|
2016-09-02 08:33:54 +02:00
|
|
|
if(tile != null){
|
|
|
|
if(tile instanceof IEnergyHandler){
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-26 19:00:02 +01:00
|
|
|
else{
|
2016-09-02 08:33:54 +02:00
|
|
|
for(EnumFacing facing : EnumFacing.values()){
|
2016-11-26 19:00:02 +01:00
|
|
|
if(tile.hasCapability(CapabilityEnergy.ENERGY, facing)){
|
2016-09-02 08:33:54 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-26 19:00:02 +01:00
|
|
|
else if(ActuallyAdditions.teslaLoaded){
|
|
|
|
if(tile.hasCapability(TeslaUtil.teslaHolder, facing)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-09-02 08:33:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-24 02:54:07 +02:00
|
|
|
}
|
2016-09-02 08:33:54 +02:00
|
|
|
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{
|
2016-11-26 19:00:02 +01:00
|
|
|
return tile.hasCapability(CapabilityEnergy.ENERGY, from) || (ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaHolder, from));
|
2016-07-24 02:54:07 +02:00
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-31 20:16:36 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyToSplitShare(){
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean doesShareEnergy(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing[] getEnergyShareSides(){
|
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|