Reduces visibility of internal fields/methods

Reduces the visibility of all fields to private and create setters/getters
when necessary. Exceptions are fields with GuiSync as these need to be
public.

Reduces the visibility of internal methods to private/protected/default when possible.
This commit is contained in:
yueh
2015-10-08 15:42:42 +02:00
parent f054bd699b
commit e94a0cfccf
497 changed files with 7865 additions and 6908 deletions
@@ -19,188 +19,188 @@
package appeng.parts.layers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
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.api.util.ForgeDirection;
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();
if( te == null )
{
return false;
}
return !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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
{
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( TileEntity receiver, ForgeDirection direction )
{
if( !this.isInIC2() )
{
return false;
}
IPart part = this.getPart( direction );
if( part instanceof IEnergySink )
{
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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
{
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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
{
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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
{
IPart part = this.getPart( dir );
if( part instanceof IEnergySource )
{
return ( (IEnergySource) part ).getSourceTier();
}
}
return 0;
}
}
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.world.World;
//import net.minecraftforge.common.MinecraftForge;
//import ic2.api.energy.tile.IEnergyEmitter;
//import ic2.api.energy.tile.IEnergySink;
//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.api.util.ForgeDirection;
//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();
// if( te == null )
// {
// return false;
// }
// return !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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
// {
// 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( TileEntity receiver, ForgeDirection direction )
// {
// if( !this.isInIC2() )
// {
// return false;
// }
//
// IPart part = this.getPart( direction );
// if( part instanceof IEnergySink )
// {
// 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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
// {
// 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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
// {
// 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( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
// {
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySource )
// {
// return ( (IEnergySource) part ).getSourceTier();
// }
// }
//
// return 0;
// }
// }