Re-enabled the RF and IC2 handler, as well as their P2P tunnels. Added Forge Energy P2P tunnel.

This commit is contained in:
Gunther De Wachter
2017-07-14 21:52:04 +02:00
parent fdab91323c
commit 66c87a2fa2
26 changed files with 1776 additions and 1241 deletions
@@ -0,0 +1,141 @@
/*
*
* * This file is part of Applied Energistics 2.
* * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
* *
* * Applied Energistics 2 is free software: you can redistribute it and/or modify
* * it under the terms of the GNU Lesser General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * Applied Energistics 2 is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU Lesser General Public License for more details.
* *
* * You should have received a copy of the GNU Lesser General Public License
* * along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*
*/
package appeng.parts.layers;
import appeng.api.parts.IPart;
import appeng.api.parts.LayerBase;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* @author GuntherDW
*/
public class LayerForgeEnergy extends LayerBase implements ICapabilityProvider, IEnergyStorage
{
private final EnumFacing facing;
public LayerForgeEnergy()
{
this.facing = null;
}
public LayerForgeEnergy( EnumFacing facing )
{
this.facing = facing;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
if( facing != null)
{
IPart part = getPart( facing );
if( part instanceof IEnergyStorage )
{
return ( (IEnergyStorage) part ).receiveEnergy( maxReceive, simulate );
}
}
return 0;
}
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
if( facing != null)
{
IPart part = getPart( facing );
if( part instanceof IEnergyStorage )
{
return ( (IEnergyStorage) part ).extractEnergy( maxExtract, simulate );
}
}
return 0;
}
@Override
public int getEnergyStored()
{
if( facing != null)
{
IPart part = getPart( facing );
if( part instanceof IEnergyStorage )
{
return ( (IEnergyStorage) part ).getEnergyStored();
}
}
return 0;
}
@Override
public int getMaxEnergyStored()
{
if( facing != null)
{
IPart part = getPart( facing );
if( part instanceof IEnergyStorage )
{
return ( (IEnergyStorage) part ).getMaxEnergyStored();
}
}
return 0;
}
@Override
public boolean canExtract()
{
if( facing != null)
{
IPart part = getPart( facing );
if( part instanceof IEnergyStorage )
{
return ( (IEnergyStorage) part ).canExtract();
}
}
return false;
}
@Override
public boolean canReceive()
{
if( facing != null)
{
IPart part = getPart( facing );
if( part instanceof IEnergyStorage )
{
return ( (IEnergyStorage) part ).canReceive();
}
}
return false;
}
}
@@ -19,75 +19,75 @@
package appeng.parts.layers;
//import cofh.api.energy.IEnergyConnection;
//import cofh.api.energy.IEnergyHandler;
//import cofh.api.energy.IEnergyProvider;
//import cofh.api.energy.IEnergyReceiver;
//import appeng.api.parts.IPart;
//import appeng.api.parts.LayerBase;
//import appeng.api.util.ForgeDirection;
//
//
//public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
//{
//
// @Override
// public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
// {
// IPart part = this.getPart( from );
// if( part instanceof IEnergyReceiver )
// {
// return ( (IEnergyReceiver) part ).receiveEnergy( from, maxReceive, simulate );
// }
//
// return 0;
// }
//
// @Override
// public int extractEnergy( ForgeDirection from, int maxExtract, boolean simulate )
// {
// IPart part = this.getPart( from );
// if( part instanceof IEnergyProvider )
// {
// return ( (IEnergyProvider) part ).extractEnergy( from, maxExtract, simulate );
// }
//
// return 0;
// }
//
// @Override
// public int getEnergyStored( ForgeDirection from )
// {
// IPart part = this.getPart( from );
// if( part instanceof IEnergyProvider )
// {
// return ( (IEnergyProvider) part ).getEnergyStored( from );
// }
//
// return 0;
// }
//
// @Override
// public int getMaxEnergyStored( ForgeDirection from )
// {
// IPart part = this.getPart( from );
// if( part instanceof IEnergyProvider )
// {
// return ( (IEnergyProvider) part ).getMaxEnergyStored( from );
// }
//
// return 0;
// }
//
// @Override
// public boolean canConnectEnergy( ForgeDirection from )
// {
// IPart part = this.getPart( from );
// if( part instanceof IEnergyConnection )
// {
// return ( (IEnergyConnection) part ).canConnectEnergy( from );
// }
//
// return false;
// }
// }
import appeng.api.parts.IPart;
import appeng.api.parts.LayerBase;
import cofh.redstoneflux.api.IEnergyConnection;
import cofh.redstoneflux.api.IEnergyHandler;
import cofh.redstoneflux.api.IEnergyProvider;
import cofh.redstoneflux.api.IEnergyReceiver;
import net.minecraft.util.EnumFacing;
public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler, IEnergyReceiver, IEnergyProvider
{
@Override
public int receiveEnergy( EnumFacing from, int maxReceive, boolean simulate )
{
IPart part = this.getPart( from );
if( part instanceof IEnergyReceiver )
{
return ( (IEnergyReceiver) part ).receiveEnergy( from, maxReceive, simulate );
}
return 0;
}
@Override
public int extractEnergy( EnumFacing from, int maxExtract, boolean simulate )
{
IPart part = this.getPart( from );
if( part instanceof IEnergyProvider )
{
return ( (IEnergyProvider) part ).extractEnergy( from, maxExtract, simulate );
}
return 0;
}
@Override
public int getEnergyStored( EnumFacing from )
{
IPart part = this.getPart( from );
if( part instanceof IEnergyProvider )
{
return ( (IEnergyProvider) part ).getEnergyStored( from );
}
return 0;
}
@Override
public int getMaxEnergyStored( EnumFacing from )
{
IPart part = this.getPart( from );
if( part instanceof IEnergyProvider )
{
return ( (IEnergyProvider) part ).getMaxEnergyStored( from );
}
return 0;
}
@Override
public boolean canConnectEnergy( EnumFacing from )
{
IPart part = this.getPart( from );
if( part instanceof IEnergyConnection )
{
return ( (IEnergyConnection) part ).canConnectEnergy( from );
}
return false;
}
}
@@ -1,204 +1,204 @@
///*
// * This file is part of Applied Energistics 2.
// * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
// *
// * Applied Energistics 2 is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Lesser General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * Applied Energistics 2 is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU Lesser General Public License for more details.
// *
// * You should have received a copy of the GNU Lesser General Public License
// * along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
// */
//
//package appeng.parts.layers;
//
//
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.util.EnumFacing;
//import net.minecraft.world.World;
//import net.minecraftforge.common.MinecraftForge;
//
//import ic2.api.energy.tile.IEnergyAcceptor;
//import ic2.api.energy.tile.IEnergyEmitter;
//import ic2.api.energy.tile.IEnergySink;
//import ic2.api.energy.tile.IEnergyTile;
//
//import appeng.api.parts.IPart;
//import appeng.api.parts.IPartHost;
//import appeng.api.parts.LayerBase;
//import appeng.api.parts.LayerFlags;
//import appeng.util.Platform;
//
//
//public class LayerIEnergySink extends LayerBase implements IEnergySink
//{
//
// private TileEntity getEnergySinkTile()
// {
// IPartHost host = (IPartHost) this;
// return host.getTile();
// }
//
// private World getEnergySinkWorld()
// {
// if( this.getEnergySinkTile() == null )
// {
// return null;
// }
//
// return this.getEnergySinkTile().getWorld();
// }
//
// private boolean isTileValid()
// {
// TileEntity te = this.getEnergySinkTile();
//
// if( te == null )
// {
// return false;
// }
//
// return !te.isInvalid() && te.getWorld().isBlockLoaded( te.getPos() );
// }
//
// private void addToENet()
// {
// if( this.getEnergySinkWorld() == null )
// {
// return;
// }
//
// // re-add
// this.removeFromENet();
//
// if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
// {
// this.getLayerFlags().add( LayerFlags.IC2_ENET );
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySinkTile() ) );
// }
// }
//
// private void removeFromENet()
// {
// if( this.getEnergySinkWorld() == null )
// {
// return;
// }
//
// if( this.isInIC2() && Platform.isServer() )
// {
// this.getLayerFlags().remove( LayerFlags.IC2_ENET );
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySinkTile() ) );
// }
// }
//
// private boolean interestedInIC2()
// {
// if( !( (IPartHost) this ).isInWorld() )
// {
// return false;
// }
//
// int interested = 0;
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergyTile )
// {
// interested++;
// }
// }
// return interested == 1;// if more then one tile is interested we need to abandon...
// }
//
// @Override
// public void partChanged()
// {
// super.partChanged();
//
// if( this.interestedInIC2() )
// {
// this.addToENet();
// }
// else
// {
// this.removeFromENet();
// }
// }
//
// @Override
// public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
// {
// if( !this.isInIC2() )
// {
// return false;
// }
//
// IPart part = this.getPart( direction );
// if( part instanceof IEnergySink )
// {
// return ( (IEnergyAcceptor) part ).acceptsEnergyFrom( emitter, direction );
// }
// return false;
// }
//
// private boolean isInIC2()
// {
// return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
// }
//
// @Override
// public double getDemandedEnergy()
// {
// if( !this.isInIC2() )
// {
// return 0;
// }
//
// // this is a flawed implementation, that requires a change to the IC2 API.
//
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySink )
// {
// // use lower number cause ic2 deletes power it sends that isn't received.
// return ( (IEnergySink) part ).getDemandedEnergy();
// }
// }
//
// return 0;
// }
//
// @Override
// public int getSinkTier()
// {
// return Integer.MAX_VALUE; // no real options here...
// }
//
// @Override
// public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
// {
// if( !this.isInIC2() )
// {
// return amount;
// }
//
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySink )
// {
// return ( (IEnergySink) part ).injectEnergy( directionFrom, amount, voltage );
// }
// }
//
// return amount;
// }
//}
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.layers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergyTile;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.LayerBase;
import appeng.api.parts.LayerFlags;
import appeng.util.Platform;
public class LayerIEnergySink extends LayerBase implements IEnergySink
{
private TileEntity getEnergySinkTile()
{
IPartHost host = (IPartHost) this;
return host.getTile();
}
private World getEnergySinkWorld()
{
if( this.getEnergySinkTile() == null )
{
return null;
}
return this.getEnergySinkTile().getWorld();
}
private boolean isTileValid()
{
TileEntity te = this.getEnergySinkTile();
if( te == null )
{
return false;
}
return !te.isInvalid() && te.getWorld().isBlockLoaded( te.getPos() );
}
private void addToENet()
{
if( this.getEnergySinkWorld() == null )
{
return;
}
// re-add
this.removeFromENet();
if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
{
this.getLayerFlags().add( LayerFlags.IC2_ENET );
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySinkTile() ) );
}
}
private void removeFromENet()
{
if( this.getEnergySinkWorld() == null )
{
return;
}
if( this.isInIC2() && Platform.isServer() )
{
this.getLayerFlags().remove( LayerFlags.IC2_ENET );
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySinkTile() ) );
}
}
private boolean interestedInIC2()
{
if( !( (IPartHost) this ).isInWorld() )
{
return false;
}
int interested = 0;
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergyTile )
{
interested++;
}
}
return interested == 1;// if more then one tile is interested we need to abandon...
}
@Override
public void partChanged()
{
super.partChanged();
if( this.interestedInIC2() )
{
this.addToENet();
}
else
{
this.removeFromENet();
}
}
@Override
public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
{
if( !this.isInIC2() )
{
return false;
}
IPart part = this.getPart( direction );
if( part instanceof IEnergySink )
{
return ( (IEnergyAcceptor) part ).acceptsEnergyFrom( emitter, direction );
}
return false;
}
private boolean isInIC2()
{
return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
}
@Override
public double getDemandedEnergy()
{
if( !this.isInIC2() )
{
return 0;
}
// this is a flawed implementation, that requires a change to the IC2 API.
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergySink )
{
// use lower number cause ic2 deletes power it sends that isn't received.
return ( (IEnergySink) part ).getDemandedEnergy();
}
}
return 0;
}
@Override
public int getSinkTier()
{
return Integer.MAX_VALUE; // no real options here...
}
@Override
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
{
if( !this.isInIC2() )
{
return amount;
}
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergySink )
{
return ( (IEnergySink) part ).injectEnergy( directionFrom, amount, voltage );
}
}
return amount;
}
}
@@ -1,207 +1,207 @@
///*
// * This file is part of Applied Energistics 2.
// * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
// *
// * Applied Energistics 2 is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Lesser General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * Applied Energistics 2 is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU Lesser General Public License for more details.
// *
// * You should have received a copy of the GNU Lesser General Public License
// * along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
// */
//
//package appeng.parts.layers;
//
//
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.util.EnumFacing;
//import net.minecraft.world.World;
//import net.minecraftforge.common.MinecraftForge;
//
//import ic2.api.energy.tile.IEnergyAcceptor;
//import ic2.api.energy.tile.IEnergyEmitter;
//import ic2.api.energy.tile.IEnergySource;
//import ic2.api.energy.tile.IEnergyTile;
//
//import appeng.api.parts.IPart;
//import appeng.api.parts.IPartHost;
//import appeng.api.parts.LayerBase;
//import appeng.api.parts.LayerFlags;
//import appeng.util.Platform;
//
//
//public class LayerIEnergySource extends LayerBase implements IEnergySource
//{
//
// private TileEntity getEnergySourceTile()
// {
// IPartHost host = (IPartHost) this;
// return host.getTile();
// }
//
// private World getEnergySourceWorld()
// {
// if( this.getEnergySourceTile() == null )
// {
// return null;
// }
// return this.getEnergySourceTile().getWorld();
// }
//
// private boolean isTileValid()
// {
// TileEntity te = this.getEnergySourceTile();
// return te != null && !te.isInvalid();
// }
//
// private void addToENet()
// {
// if( this.getEnergySourceWorld() == null )
// {
// return;
// }
//
// // re-add
// this.removeFromENet();
//
// if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
// {
// this.getLayerFlags().add( LayerFlags.IC2_ENET );
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
// }
// }
//
// private void removeFromENet()
// {
// if( this.getEnergySourceWorld() == null )
// {
// return;
// }
//
// if( this.isInIC2() && Platform.isServer() )
// {
// this.getLayerFlags().remove( LayerFlags.IC2_ENET );
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
// }
// }
//
// private boolean interestedInIC2()
// {
// if( !( (IPartHost) this ).isInWorld() )
// {
// return false;
// }
//
// int interested = 0;
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergyTile )
// {
// interested++;
// }
// }
// return interested == 1;// if more then one tile is interested we need to abandon...
// }
//
// @Override
// public void partChanged()
// {
// super.partChanged();
//
// if( this.interestedInIC2() )
// {
// this.addToENet();
// }
// else
// {
// this.removeFromENet();
// }
// }
//
// @Override
// public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
// {
// if( !this.isInIC2() )
// {
// return false;
// }
//
// IPart part = this.getPart( direction );
// if( part instanceof IEnergyEmitter )
// {
// return ( (IEnergyEmitter) part ).emitsEnergyTo( receiver, direction );
// }
// return false;
// }
//
// private boolean isInIC2()
// {
// return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
// }
//
// @Override
// public double getOfferedEnergy()
// {
// if( !this.isInIC2() )
// {
// return 0;
// }
//
// // this is a flawed implementation, that requires a change to the IC2 API.
//
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySource )
// {
// // use lower number cause ic2 deletes power it sends that isn't received.
// return ( (IEnergySource) part ).getOfferedEnergy();
// }
// }
//
// return 0;
// }
//
// @Override
// public void drawEnergy( double amount )
// {
// // this is a flawed implementation, that requires a change to the IC2 API.
//
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySource )
// {
// ( (IEnergySource) part ).drawEnergy( amount );
// return;
// }
// }
// }
//
// @Override
// public int getSourceTier()
// {
// // this is a flawed implementation, that requires a change to the IC2 API.
//
// for( EnumFacing dir : EnumFacing.values() )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySource )
// {
// return ( (IEnergySource) part ).getSourceTier();
// }
// }
//
// return 0;
// }
//
//
//
//}
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.layers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.energy.tile.IEnergyTile;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.LayerBase;
import appeng.api.parts.LayerFlags;
import appeng.util.Platform;
public class LayerIEnergySource extends LayerBase implements IEnergySource
{
private TileEntity getEnergySourceTile()
{
IPartHost host = (IPartHost) this;
return host.getTile();
}
private World getEnergySourceWorld()
{
if( this.getEnergySourceTile() == null )
{
return null;
}
return this.getEnergySourceTile().getWorld();
}
private boolean isTileValid()
{
TileEntity te = this.getEnergySourceTile();
return te != null && !te.isInvalid();
}
private void addToENet()
{
if( this.getEnergySourceWorld() == null )
{
return;
}
// re-add
this.removeFromENet();
if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
{
this.getLayerFlags().add( LayerFlags.IC2_ENET );
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
}
}
private void removeFromENet()
{
if( this.getEnergySourceWorld() == null )
{
return;
}
if( this.isInIC2() && Platform.isServer() )
{
this.getLayerFlags().remove( LayerFlags.IC2_ENET );
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
}
}
private boolean interestedInIC2()
{
if( !( (IPartHost) this ).isInWorld() )
{
return false;
}
int interested = 0;
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergyTile )
{
interested++;
}
}
return interested == 1;// if more then one tile is interested we need to abandon...
}
@Override
public void partChanged()
{
super.partChanged();
if( this.interestedInIC2() )
{
this.addToENet();
}
else
{
this.removeFromENet();
}
}
@Override
public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
{
if( !this.isInIC2() )
{
return false;
}
IPart part = this.getPart( direction );
if( part instanceof IEnergyEmitter )
{
return ( (IEnergyEmitter) part ).emitsEnergyTo( receiver, direction );
}
return false;
}
private boolean isInIC2()
{
return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
}
@Override
public double getOfferedEnergy()
{
if( !this.isInIC2() )
{
return 0;
}
// this is a flawed implementation, that requires a change to the IC2 API.
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergySource )
{
// use lower number cause ic2 deletes power it sends that isn't received.
return ( (IEnergySource) part ).getOfferedEnergy();
}
}
return 0;
}
@Override
public void drawEnergy( double amount )
{
// this is a flawed implementation, that requires a change to the IC2 API.
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergySource )
{
( (IEnergySource) part ).drawEnergy( amount );
return;
}
}
}
@Override
public int getSourceTier()
{
// this is a flawed implementation, that requires a change to the IC2 API.
for( EnumFacing dir : EnumFacing.values() )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergySource )
{
return ( (IEnergySource) part ).getSourceTier();
}
}
return 0;
}
}
@@ -0,0 +1,250 @@
/*
*
* * This file is part of Applied Energistics 2.
* * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
* *
* * Applied Energistics 2 is free software: you can redistribute it and/or modify
* * it under the terms of the GNU Lesser General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * Applied Energistics 2 is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU Lesser General Public License for more details.
* *
* * You should have received a copy of the GNU Lesser General Public License
* * along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*
*/
package appeng.parts.p2p;
import appeng.api.config.PowerUnits;
import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.util.Platform;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
/**
* @author GuntherDW
*/
public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower> implements IEnergyStorage
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fe" );
private boolean cachedTarget = false;
private IEnergyStorage outputTarget;
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
public PartP2PFEPower( ItemStack is )
{
super( is );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
this.cachedTarget = false;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
if( this.isOutput() )
{
return 0;
}
if( this.isActive() )
{
int total = 0;
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
if( Platform.getRandomInt() % 2 > 0 )
{
int receiver = t.getOutput().receiveEnergy( maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
if( maxReceive > 0 )
{
for( PartP2PFEPower t : this.getOutputs() )
{
int receiver = t.getOutput().receiveEnergy( maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
this.queueTunnelDrain( PowerUnits.RF, total );
}
catch( GridAccessException ignored )
{
}
return total;
}
return 0;
}
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
return 0;
}
private IEnergyStorage getOutput()
{
if( this.isOutput() )
{
if( !this.cachedTarget )
{
TileEntity self = this.getTile();
TileEntity te = self.getWorld().getTileEntity( new BlockPos( self.getPos().getX() + this.getSide().xOffset, self.getPos().getY() + this.getSide().yOffset, self.getPos().getZ() + this.getSide().zOffset ) );
this.outputTarget = te.hasCapability( CapabilityEnergy.ENERGY, this.getSide().getOpposite().getFacing() ) ? te.getCapability( CapabilityEnergy.ENERGY, this.getSide().getOpposite().getFacing() ) : null;
this.cachedTarget = true;
}
if( this.outputTarget == null || !this.outputTarget.canReceive() )
{
return null;
}
return this.outputTarget;
}
return null;
}
@Override
public int getEnergyStored()
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
@Override
public int getMaxEnergyStored()
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
@Override
public boolean canExtract()
{
return false;
}
@Override
public boolean canReceive()
{
return true;
}
@Override
public boolean hasCapability( @Nonnull Capability<?> capability )
{
if( capability == CapabilityEnergy.ENERGY )
{
return true;
}
return super.hasCapability( capability );
}
@Nullable
@Override
public <T> T getCapability( @Nonnull Capability<T> capability )
{
if( capability == CapabilityEnergy.ENERGY )
{
return (T) this;
}
return super.getCapability( capability );
}
}
@@ -1,263 +1,263 @@
///*
// * This file is part of Applied Energistics 2.
// * Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
// *
// * Applied Energistics 2 is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Lesser General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * Applied Energistics 2 is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU Lesser General Public License for more details.
// *
// * You should have received a copy of the GNU Lesser General Public License
// * along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
// */
//
//package appeng.parts.p2p;
//
//
//import java.util.LinkedList;
//import java.util.List;
//
//import net.minecraft.item.ItemStack;
//import net.minecraft.nbt.NBTTagCompound;
//import net.minecraft.util.EnumFacing;
//
//import ic2.api.energy.tile.IEnergyAcceptor;
//import ic2.api.energy.tile.IEnergyEmitter;
//import ic2.api.energy.tile.IEnergySink;
//
//import appeng.api.config.PowerUnits;
//import appeng.api.networking.energy.IEnergySource;
//import appeng.api.parts.IPartModel;
//import appeng.coremod.annotations.Integration.Interface;
//import appeng.coremod.annotations.Integration.InterfaceList;
//import appeng.integration.IntegrationType;
//import appeng.items.parts.PartModels;
//import appeng.me.GridAccessException;
//import appeng.me.cache.helpers.TunnelCollection;
//import appeng.util.Platform;
//
//
//@InterfaceList( value = {
// @Interface( iface = "ic2.api.energy.tile.IEnergySink", iname = IntegrationType.IC2 ),
// @Interface( iface = "ic2.api.energy.tile.IEnergySource", iname = IntegrationType.IC2 )
//} )
//public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements IEnergySink, IEnergySource
//{
//
// private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
// private static final String TAG_BUFFERED_ENERGY_2 = "bufferedEnergy2";
// private static final String TAG_BUFFERED_VOLTAGE_1 = "outputPacket1";
// private static final String TAG_BUFFERED_VOLTAGE_2 = "outputPacket2";
//
// private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_ic2" );
//
// @PartModels
// public static List<IPartModel> getModels()
// {
// return MODELS.getModels();
// }
//
// // Buffer the energy + voltage for two IC2 ENET packets
// private double bufferedEnergy1;
// private double bufferedVoltage1;
// private double bufferedEnergy2;
// private double bufferedVoltage2;
//
// public PartP2PIC2Power( ItemStack is )
// {
// super( is );
// }
//
// @Override
// public void readFromNBT( NBTTagCompound tag )
// {
// super.readFromNBT( tag );
// this.bufferedEnergy1 = tag.getDouble( TAG_BUFFERED_ENERGY_1 );
// this.bufferedEnergy2 = tag.getDouble( TAG_BUFFERED_ENERGY_2 );
// this.bufferedVoltage1 = tag.getDouble( TAG_BUFFERED_VOLTAGE_1 );
// this.bufferedVoltage2 = tag.getDouble( TAG_BUFFERED_VOLTAGE_2 );
// }
//
// @Override
// public void writeToNBT( NBTTagCompound tag )
// {
// super.writeToNBT( tag );
// tag.setDouble( TAG_BUFFERED_ENERGY_1, this.bufferedEnergy1 );
// tag.setDouble( TAG_BUFFERED_ENERGY_2, this.bufferedEnergy2 );
// tag.setDouble( TAG_BUFFERED_VOLTAGE_1, this.bufferedVoltage1 );
// tag.setDouble( TAG_BUFFERED_VOLTAGE_2, this.bufferedVoltage2 );
// }
//
// @Override
// public void onTunnelConfigChange()
// {
// this.getHost().partChanged();
// }
//
// @Override
// public void onTunnelNetworkChange()
// {
// this.getHost().notifyNeighbors();
// }
//
// @Override
// public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
// {
// return !this.isOutput() && direction == this.getSide().getFacing();
// }
//
// @Override
// public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
// {
// return this.isOutput() && direction == this.getSide().getFacing();
// }
//
// @Override
// public double getDemandedEnergy()
// {
// if( this.isOutput() )
// {
// return 0;
// }
//
// try
// {
// for( PartP2PIC2Power t : this.getOutputs() )
// {
// if( t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001 )
// {
// return 2048;
// }
// }
// }
// catch( GridAccessException e )
// {
// return 0;
// }
//
// return 0;
// }
//
// @Override
// public int getSinkTier()
// {
// return 4;
// }
//
// @Override
// public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
// {
// TunnelCollection<PartP2PIC2Power> outs;
// try
// {
// outs = this.getOutputs();
// }
// catch( GridAccessException e )
// {
// return amount;
// }
//
// if( outs.isEmpty() )
// {
// return amount;
// }
//
// LinkedList<PartP2PIC2Power> options = new LinkedList<>();
// for( PartP2PIC2Power o : outs )
// {
// if( o.bufferedEnergy1 <= 0.01 )
// {
// options.add( o );
// }
// }
//
// if( options.isEmpty() )
// {
// for( PartP2PIC2Power o : outs )
// {
// if( o.bufferedEnergy2 <= 0.01 )
// {
// options.add( o );
// }
// }
// }
//
// if( options.isEmpty() )
// {
// for( PartP2PIC2Power o : outs )
// {
// options.add( o );
// }
// }
//
// if( options.isEmpty() )
// {
// return amount;
// }
//
// PartP2PIC2Power x = Platform.pickRandom( options );
//
// if( x != null && x.bufferedEnergy1 <= 0.001 )
// {
// this.queueTunnelDrain( PowerUnits.EU, amount );
// x.bufferedEnergy1 = amount;
// x.bufferedVoltage1 = voltage;
// return 0;
// }
//
// if( x != null && x.bufferedEnergy2 <= 0.001 )
// {
// this.queueTunnelDrain( PowerUnits.EU, amount );
// x.bufferedEnergy2 = amount;
// x.bufferedVoltage2 = voltage;
// return 0;
// }
//
// return amount;
// }
//
// @Override
// public double getOfferedEnergy()
// {
// if( this.isOutput() )
// {
// return this.bufferedEnergy1;
// }
// return 0;
// }
//
// @Override
// public void drawEnergy( double amount )
// {
// this.bufferedEnergy1 -= amount;
// if( this.bufferedEnergy1 < 0.001 )
// {
// this.bufferedEnergy1 = this.bufferedEnergy2;
// this.bufferedEnergy2 = 0;
//
// this.bufferedVoltage1 = this.bufferedVoltage2;
// this.bufferedVoltage2 = 0;
// }
// }
//
// @Override
// public int getSourceTier()
// {
// // Sadly IC2 doesn't support changing the tier once we're registered, so we
// // go with the highest here... At this point it's somewhat unclear as to what effect
// // this realistically has.
// return 4;
// }
//
// @Override
// public IPartModel getStaticModels()
// {
// return MODELS.getModel( isPowered(), isActive() );
// }
//
//}
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.parts.p2p;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource;
import appeng.api.config.PowerUnits;
import appeng.api.parts.IPartModel;
import appeng.coremod.annotations.Integration.Interface;
import appeng.coremod.annotations.Integration.InterfaceList;
import appeng.integration.IntegrationType;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.util.Platform;
@InterfaceList( value = {
@Interface( iface = "ic2.api.energy.tile.IEnergySink", iname = IntegrationType.IC2 ),
@Interface( iface = "ic2.api.energy.tile.IEnergySource", iname = IntegrationType.IC2 )
} )
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements IEnergySink, IEnergySource
{
private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
private static final String TAG_BUFFERED_ENERGY_2 = "bufferedEnergy2";
private static final String TAG_BUFFERED_VOLTAGE_1 = "outputPacket1";
private static final String TAG_BUFFERED_VOLTAGE_2 = "outputPacket2";
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_ic2" );
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
// Buffer the energy + voltage for two IC2 ENET packets
private double bufferedEnergy1;
private double bufferedVoltage1;
private double bufferedEnergy2;
private double bufferedVoltage2;
public PartP2PIC2Power( ItemStack is )
{
super( is );
}
@Override
public void readFromNBT( NBTTagCompound tag )
{
super.readFromNBT( tag );
this.bufferedEnergy1 = tag.getDouble( TAG_BUFFERED_ENERGY_1 );
this.bufferedEnergy2 = tag.getDouble( TAG_BUFFERED_ENERGY_2 );
this.bufferedVoltage1 = tag.getDouble( TAG_BUFFERED_VOLTAGE_1 );
this.bufferedVoltage2 = tag.getDouble( TAG_BUFFERED_VOLTAGE_2 );
}
@Override
public void writeToNBT( NBTTagCompound tag )
{
super.writeToNBT( tag );
tag.setDouble( TAG_BUFFERED_ENERGY_1, this.bufferedEnergy1 );
tag.setDouble( TAG_BUFFERED_ENERGY_2, this.bufferedEnergy2 );
tag.setDouble( TAG_BUFFERED_VOLTAGE_1, this.bufferedVoltage1 );
tag.setDouble( TAG_BUFFERED_VOLTAGE_2, this.bufferedVoltage2 );
}
@Override
public void onTunnelConfigChange()
{
this.getHost().partChanged();
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
{
return !this.isOutput() && direction == this.getSide().getFacing();
}
@Override
public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
{
return this.isOutput() && direction == this.getSide().getFacing();
}
@Override
public double getDemandedEnergy()
{
if( this.isOutput() )
{
return 0;
}
try
{
for( PartP2PIC2Power t : this.getOutputs() )
{
if( t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001 )
{
return 2048;
}
}
}
catch( GridAccessException e )
{
return 0;
}
return 0;
}
@Override
public int getSinkTier()
{
return 4;
}
@Override
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
{
TunnelCollection<PartP2PIC2Power> outs;
try
{
outs = this.getOutputs();
}
catch( GridAccessException e )
{
return amount;
}
if( outs.isEmpty() )
{
return amount;
}
LinkedList<PartP2PIC2Power> options = new LinkedList<>();
for( PartP2PIC2Power o : outs )
{
if( o.bufferedEnergy1 <= 0.01 )
{
options.add( o );
}
}
if( options.isEmpty() )
{
for( PartP2PIC2Power o : outs )
{
if( o.bufferedEnergy2 <= 0.01 )
{
options.add( o );
}
}
}
if( options.isEmpty() )
{
for( PartP2PIC2Power o : outs )
{
options.add( o );
}
}
if( options.isEmpty() )
{
return amount;
}
PartP2PIC2Power x = Platform.pickRandom( options );
if( x != null && x.bufferedEnergy1 <= 0.001 )
{
this.queueTunnelDrain( PowerUnits.EU, amount );
x.bufferedEnergy1 = amount;
x.bufferedVoltage1 = voltage;
return 0;
}
if( x != null && x.bufferedEnergy2 <= 0.001 )
{
this.queueTunnelDrain( PowerUnits.EU, amount );
x.bufferedEnergy2 = amount;
x.bufferedVoltage2 = voltage;
return 0;
}
return amount;
}
@Override
public double getOfferedEnergy()
{
if( this.isOutput() )
{
return this.bufferedEnergy1;
}
return 0;
}
@Override
public void drawEnergy( double amount )
{
this.bufferedEnergy1 -= amount;
if( this.bufferedEnergy1 < 0.001 )
{
this.bufferedEnergy1 = this.bufferedEnergy2;
this.bufferedEnergy2 = 0;
this.bufferedVoltage1 = this.bufferedVoltage2;
this.bufferedVoltage2 = 0;
}
}
@Override
public int getSourceTier()
{
// Sadly IC2 doesn't support changing the tier once we're registered, so we
// go with the highest here... At this point it's somewhat unclear as to what effect
// this realistically has.
return 4;
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
}
+193 -256
View File
@@ -18,260 +18,197 @@
package appeng.parts.p2p;
import java.util.List;
import java.util.Stack;
//import java.util.Stack;
//
//import net.minecraft.init.Blocks;
//import net.minecraft.item.ItemStack;
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.util.IIcon;
//import net.minecraftforge.common.util.ForgeDirection;
//
//import cpw.mods.fml.relauncher.Side;
//import cpw.mods.fml.relauncher.SideOnly;
//
//import cofh.api.energy.IEnergyReceiver;
//
//import appeng.api.config.PowerUnits;
//import appeng.integration.IntegrationType;
//import appeng.integration.modules.helpers.NullRFHandler;
//import appeng.me.GridAccessException;
//import appeng.coremod.annotations.Integration.Interface;
//import appeng.coremod.annotations.Integration.InterfaceList;
//import appeng.util.Platform;
//
//
//@InterfaceList( value = { @Interface( iface = "cofh.api.energy.IEnergyReceiver", iname = IntegrationType.RF ) } )
//public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEnergyReceiver
//{
// private static final ThreadLocal<Stack<PartP2PRFPower>> THREAD_STACK = new ThreadLocal<Stack<PartP2PRFPower>>();
// /**
// * Default element based on the null element pattern
// */
// private static final IEnergyReceiver NULL_HANDLER = new NullRFHandler();
// private boolean cachedTarget = false;
// private IEnergyReceiver outputTarget;
//
// public PartP2PRFPower( ItemStack is )
// {
// super( is );
// }
//
// @Override
// @SideOnly( Side.CLIENT )
// public IIcon getTypeTexture()
// {
// return Blocks.iron_block.getBlockTextureFromSide( 0 );
// }
//
// @Override
// public void onTunnelNetworkChange()
// {
// this.getHost().notifyNeighbors();
// }
//
// @Override
// public void onNeighborChanged()
// {
// super.onNeighborChanged();
//
// this.cachedTarget = false;
// }
//
// @Override
// public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
// {
// if( this.output )
// {
// return 0;
// }
//
// if( this.isActive() )
// {
// Stack<PartP2PRFPower> stack = this.getDepth();
//
// for( PartP2PRFPower t : stack )
// {
// if( t == this )
// {
// return 0;
// }
// }
//
// stack.push( this );
//
// int total = 0;
//
// try
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// if( Platform.getRandomInt() % 2 > 0 )
// {
// int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
// maxReceive -= receiver;
// total += receiver;
//
// if( maxReceive <= 0 )
// {
// break;
// }
// }
// }
//
// if( maxReceive > 0 )
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
// maxReceive -= receiver;
// total += receiver;
//
// if( maxReceive <= 0 )
// {
// break;
// }
// }
// }
//
// this.queueTunnelDrain( PowerUnits.RF, total );
// }
// catch( GridAccessException ignored )
// {
// }
//
// if( stack.pop() != this )
// {
// throw new IllegalStateException( "Invalid Recursion detected." );
// }
//
// return total;
// }
//
// return 0;
// }
//
// private Stack<PartP2PRFPower> getDepth()
// {
// Stack<PartP2PRFPower> s = THREAD_STACK.get();
//
// if( s == null )
// {
// THREAD_STACK.set( s = new Stack<PartP2PRFPower>() );
// }
//
// return s;
// }
//
// private IEnergyReceiver getOutput()
// {
// if( this.output )
// {
// if( !this.cachedTarget )
// {
// TileEntity self = this.getTile();
// TileEntity te = self.getworld().getTileEntity( self.x + this.side.offsetX, self.y + this.side.offsetY, self.z + this.side.offsetZ );
// this.outputTarget = te instanceof IEnergyReceiver ? (IEnergyReceiver) te : null;
// this.cachedTarget = true;
// }
//
// if( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.side.getOpposite() ) )
// {
// return NULL_HANDLER;
// }
//
// return this.outputTarget;
// }
// return NULL_HANDLER;
// }
//
// @Override
// public int getEnergyStored( ForgeDirection from )
// {
// if( this.output || !this.isActive() )
// {
// return 0;
// }
//
// int total = 0;
//
// Stack<PartP2PRFPower> stack = this.getDepth();
//
// for( PartP2PRFPower t : stack )
// {
// if( t == this )
// {
// return 0;
// }
// }
//
// stack.push( this );
//
// try
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// total += t.getOutput().getEnergyStored( t.side.getOpposite() );
// }
// }
// catch( GridAccessException e )
// {
// return 0;
// }
//
// if( stack.pop() != this )
// {
// throw new IllegalStateException( "Invalid Recursion detected." );
// }
//
// return total;
// }
//
// @Override
// public int getMaxEnergyStored( ForgeDirection from )
// {
// if( this.output || !this.isActive() )
// {
// return 0;
// }
//
// int total = 0;
//
// Stack<PartP2PRFPower> stack = this.getDepth();
//
// for( PartP2PRFPower t : stack )
// {
// if( t == this )
// {
// return 0;
// }
// }
//
// stack.push( this );
//
// try
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
// }
// }
// catch( GridAccessException e )
// {
// return 0;
// }
//
// if( stack.pop() != this )
// {
// throw new IllegalStateException( "Invalid Recursion detected." );
// }
//
// return total;
// }
//
// @Override
// public boolean canConnectEnergy( ForgeDirection from )
// {
// return true;
// }
// }
import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels;
import cofh.redstoneflux.api.IEnergyReceiver;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.config.PowerUnits;
import appeng.integration.IntegrationType;
import appeng.me.GridAccessException;
import appeng.coremod.annotations.Integration.Interface;
import appeng.coremod.annotations.Integration.InterfaceList;
import appeng.util.Platform;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
@InterfaceList( value = { @Interface( iface = "cofh.redstoneflux.api.IEnergyReceiver", iname = IntegrationType.RF ) } )
public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEnergyReceiver
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_rf" );
private boolean cachedTarget = false;
private IEnergyReceiver outputTarget;
public PartP2PRFPower( ItemStack is )
{
super( is );
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
this.cachedTarget = false;
}
@Override
public int receiveEnergy( EnumFacing from, int maxReceive, boolean simulate )
{
if( this.isOutput() )
{
return 0;
}
if( this.isActive() )
{
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
if( Platform.getRandomInt() % 2 > 0 )
{
int receiver = t.getOutput().receiveEnergy( t.getSide().getFacing().getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
if( maxReceive > 0 )
{
for( PartP2PRFPower t : this.getOutputs() )
{
int receiver = t.getOutput().receiveEnergy( t.getSide().getFacing().getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
this.queueTunnelDrain( PowerUnits.RF, total );
}
catch( GridAccessException ignored )
{
}
return total;
}
return 0;
}
private IEnergyReceiver getOutput()
{
if( this.isOutput() )
{
if( !this.cachedTarget )
{
TileEntity self = this.getTile();
TileEntity te = self.getWorld().getTileEntity( new BlockPos( self.getPos().getX() + this.getSide().xOffset, self.getPos().getY() + this.getSide().yOffset, self.getPos().getZ() + this.getSide().zOffset ) );
this.outputTarget = te instanceof IEnergyReceiver ? (IEnergyReceiver) te : null;
this.cachedTarget = true;
}
if( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.getSide().getOpposite().getFacing() ) )
{
return null;
}
return this.outputTarget;
}
return null;
}
@Override
public int getEnergyStored( EnumFacing from )
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored( this.getSide().getOpposite().getFacing() );
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
@Override
public int getMaxEnergyStored( EnumFacing from )
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored( this.getSide().getOpposite().getFacing() );
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
@Override
public boolean canConnectEnergy( EnumFacing from )
{
return true;
}
}
@@ -222,22 +222,17 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
newType = parts.p2PTunnelLight().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
/*
* case RF_POWER:
* for( ItemStack stack : parts.p2PTunnelRF().maybeStack( 1 ).asSet() )
* {
* newType = stack;
* }
* break;
*/
case RF_POWER:
newType = parts.p2PTunnelRF().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case FLUID:
newType = parts.p2PTunnelFluids().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
//case IC2_POWER:
// newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( ItemStack.EMPTY );
// break;
case IC2_POWER:
newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case ITEM:
newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( ItemStack.EMPTY );