Format sourcecode

This commit is contained in:
yueh
2017-07-20 21:17:10 +02:00
parent 66437897be
commit 621910df91
295 changed files with 2142 additions and 1562 deletions
+155 -152
View File
@@ -20,6 +20,7 @@
package appeng.parts.p2p;
import appeng.api.config.PowerUnits;
import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels;
@@ -36,194 +37,196 @@ 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 static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fe" );
private boolean cachedTarget = false;
private boolean cachedTarget = false;
private IEnergyStorage outputTarget;
private IEnergyStorage outputTarget;
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
public PartP2PFEPower( ItemStack is )
{
super( is );
}
public PartP2PFEPower( ItemStack is )
{
super( is );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
this.cachedTarget = false;
}
this.cachedTarget = false;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
if( this.isOutput() )
{
return 0;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
if( this.isOutput() )
{
return 0;
}
if( this.isActive() )
{
int total = 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;
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 )
{
break;
}
}
}
if( maxReceive > 0 )
{
for( PartP2PFEPower t : this.getOutputs() )
{
int receiver = t.getOutput().receiveEnergy( maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive > 0 )
{
for( PartP2PFEPower t : this.getOutputs() )
{
int receiver = t.getOutput().receiveEnergy( maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
if( maxReceive <= 0 )
{
break;
}
}
}
this.queueTunnelDrain( PowerUnits.RF, total );
}
catch( GridAccessException ignored )
{
}
this.queueTunnelDrain( PowerUnits.RF, total );
}
catch( GridAccessException ignored )
{
}
return total;
}
return total;
}
return 0;
}
return 0;
}
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
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;
}
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;
}
if( this.outputTarget == null || !this.outputTarget.canReceive() )
{
return null;
}
return this.outputTarget;
}
return null;
}
return this.outputTarget;
}
return null;
}
@Override
public int getEnergyStored()
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
@Override
public int getEnergyStored()
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
int total = 0;
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
return total;
}
@Override
public int getMaxEnergyStored()
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
@Override
public int getMaxEnergyStored()
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
int total = 0;
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
try
{
for( PartP2PFEPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
return total;
}
@Override
public boolean canExtract()
{
return false;
}
@Override
public boolean canExtract()
{
return false;
}
@Override
public boolean canReceive()
{
return true;
}
@Override
public boolean canReceive()
{
return true;
}
@Override
public boolean hasCapability( @Nonnull Capability<?> capability )
@@ -294,10 +294,11 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
* The ItemStack should not be modified in this function!
* Note: This behaviour is subtly different from IFluidHandlers.fill()
*
* @param slot Slot to insert into.
* @param stack ItemStack to insert.
* @param slot Slot to insert into.
* @param stack ItemStack to insert.
* @param simulate If true, the insertion is only simulated
* @return The remaining ItemStack that was not inserted (if the entire stack is accepted, then return ItemStack.EMPTY).
* @return The remaining ItemStack that was not inserted (if the entire stack is accepted, then return
* ItemStack.EMPTY).
* May be the same as the input ItemStack if unchanged, otherwise a new ItemStack.
**/
@Nonnull
@@ -305,11 +306,12 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
{
if( isItemValidForSlot( slot, stack ) )
if( isItemValidForSlot( slot, stack ) )
{
AdaptorIInventory adaptor = new AdaptorIInventory( this.getDestination() );
if( simulate ) {
if( simulate )
{
return adaptor.simulateAdd( stack );
}
else
@@ -325,8 +327,8 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements /* IPip
* if nothing is extracted, otherwise it's stack size must not be greater than amount or the
* itemstacks getMaxStackSize().
*
* @param slot Slot to extract from.
* @param amount Amount to extract (may be greater than the current stacks max limit)
* @param slot Slot to extract from.
* @param amount Amount to extract (may be greater than the current stacks max limit)
* @param simulate If true, the extraction is only simulated
* @return ItemStack extracted from the slot, must be ItemStack.EMPTY, if nothing can be extracted
**/
@@ -19,173 +19,176 @@
package appeng.parts.p2p;
//import javax.annotation.Nullable;
// import javax.annotation.Nullable;
//
//import net.minecraft.item.ItemStack;
//import net.minecraft.nbt.NBTTagCompound;
//import net.minecraft.util.IIcon;
//import net.minecraftforge.common.util.ForgeDirection;
// import net.minecraft.item.ItemStack;
// import net.minecraft.nbt.NBTTagCompound;
// import net.minecraft.util.IIcon;
// import net.minecraftforge.common.util.ForgeDirection;
//
//import cpw.mods.fml.relauncher.Side;
//import cpw.mods.fml.relauncher.SideOnly;
// import cpw.mods.fml.relauncher.Side;
// import cpw.mods.fml.relauncher.SideOnly;
//
//import li.cil.oc.api.API;
//import li.cil.oc.api.Items;
//import li.cil.oc.api.Network;
//import li.cil.oc.api.network.Environment;
//import li.cil.oc.api.network.Message;
//import li.cil.oc.api.network.Node;
//import li.cil.oc.api.network.SidedEnvironment;
//import li.cil.oc.api.network.Visibility;
// import li.cil.oc.api.API;
// import li.cil.oc.api.Items;
// import li.cil.oc.api.Network;
// import li.cil.oc.api.network.Environment;
// import li.cil.oc.api.network.Message;
// import li.cil.oc.api.network.Node;
// import li.cil.oc.api.network.SidedEnvironment;
// import li.cil.oc.api.network.Visibility;
//
//import appeng.api.networking.events.MENetworkBootingStatusChange;
//import appeng.api.networking.events.MENetworkChannelsChanged;
//import appeng.api.networking.events.MENetworkEventSubscribe;
//import appeng.api.networking.events.MENetworkPowerStatusChange;
//import appeng.integration.IntegrationRegistry;
//import appeng.integration.IntegrationType;
//import appeng.coremod.annotations.Integration.Interface;
//import appeng.coremod.annotations.Integration.InterfaceList;
// import appeng.api.networking.events.MENetworkBootingStatusChange;
// import appeng.api.networking.events.MENetworkChannelsChanged;
// import appeng.api.networking.events.MENetworkEventSubscribe;
// import appeng.api.networking.events.MENetworkPowerStatusChange;
// import appeng.integration.IntegrationRegistry;
// import appeng.integration.IntegrationType;
// import appeng.coremod.annotations.Integration.Interface;
// import appeng.coremod.annotations.Integration.InterfaceList;
//
//
//@InterfaceList( value = { @Interface( iface = "li.cil.oc.api.network.Environment", iname = IntegrationType.OpenComputers ), @Interface( iface = "li.cil.oc.api.network.SidedEnvironment", iname = IntegrationType.OpenComputers ) } )
//public final class PartP2POpenComputers extends PartP2PTunnel<PartP2POpenComputers> implements Environment, SidedEnvironment
//{
// @Nullable
// private final Node node;
// @InterfaceList( value = { @Interface( iface = "li.cil.oc.api.network.Environment", iname =
// IntegrationType.OpenComputers ), @Interface( iface = "li.cil.oc.api.network.SidedEnvironment", iname =
// IntegrationType.OpenComputers ) } )
// public final class PartP2POpenComputers extends PartP2PTunnel<PartP2POpenComputers> implements Environment,
// SidedEnvironment
// {
// @Nullable
// private final Node node;
//
// public PartP2POpenComputers( final ItemStack is )
// {
// super( is );
// public PartP2POpenComputers( final ItemStack is )
// {
// super( is );
//
// if( !IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.OpenComputers ) )
// {
// throw new RuntimeException( "OpenComputers is not installed!" );
// }
// if( !IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.OpenComputers ) )
// {
// throw new RuntimeException( "OpenComputers is not installed!" );
// }
//
// // Avoid NPE when called in pre-init phase (part population).
// if( API.network != null )
// {
// this.node = Network.newNode( this, Visibility.None ).create();
// }
// else
// {
// this.node = null; // to satisfy final
// }
// }
// // Avoid NPE when called in pre-init phase (part population).
// if( API.network != null )
// {
// this.node = Network.newNode( this, Visibility.None ).create();
// }
// else
// {
// this.node = null; // to satisfy final
// }
// }
//
// @MENetworkEventSubscribe
// public void changeStateA( final MENetworkBootingStatusChange bs )
// {
// this.updateConnections();
// }
// @MENetworkEventSubscribe
// public void changeStateA( final MENetworkBootingStatusChange bs )
// {
// this.updateConnections();
// }
//
// @MENetworkEventSubscribe
// public void changeStateB( final MENetworkChannelsChanged bs )
// {
// this.updateConnections();
// }
// @MENetworkEventSubscribe
// public void changeStateB( final MENetworkChannelsChanged bs )
// {
// this.updateConnections();
// }
//
// @MENetworkEventSubscribe
// public void changeStateC( final MENetworkPowerStatusChange bs )
// {
// this.updateConnections();
// }
// @MENetworkEventSubscribe
// public void changeStateC( final MENetworkPowerStatusChange bs )
// {
// this.updateConnections();
// }
//
// @Override
// @SideOnly( Side.CLIENT )
// public IIcon getTypeTexture()
// {
// return Items.get( "adapter" ).block().getBlockTextureFromSide( 2 );
// }
// @Override
// @SideOnly( Side.CLIENT )
// public IIcon getTypeTexture()
// {
// return Items.get( "adapter" ).block().getBlockTextureFromSide( 2 );
// }
//
// @Override
// public void removeFromWorld()
// {
// super.removeFromWorld();
// if( this.node != null )
// {
// this.node.remove();
// }
// }
// @Override
// public void removeFromWorld()
// {
// super.removeFromWorld();
// if( this.node != null )
// {
// this.node.remove();
// }
// }
//
// @Override
// public void onTunnelNetworkChange()
// {
// this.updateConnections();
// }
// @Override
// public void onTunnelNetworkChange()
// {
// this.updateConnections();
// }
//
// @Override
// public void readFromNBT( final NBTTagCompound data )
// {
// super.readFromNBT( data );
// if( this.node != null )
// {
// this.node.load( data );
// }
// }
// @Override
// public void readFromNBT( final NBTTagCompound data )
// {
// super.readFromNBT( data );
// if( this.node != null )
// {
// this.node.load( data );
// }
// }
//
// @Override
// public void writeToNBT( final NBTTagCompound data )
// {
// super.writeToNBT( data );
// if( this.node != null )
// {
// this.node.save( data );
// }
// }
// @Override
// public void writeToNBT( final NBTTagCompound data )
// {
// super.writeToNBT( data );
// if( this.node != null )
// {
// this.node.save( data );
// }
// }
//
// private void updateConnections()
// {
// if( this.getProxy().isPowered() && this.getProxy().isActive() )
// {
// // Make sure we're connected to existing OC nodes in the world.
// Network.joinOrCreateNetwork( this.getTile() );
// private void updateConnections()
// {
// if( this.getProxy().isPowered() && this.getProxy().isActive() )
// {
// // Make sure we're connected to existing OC nodes in the world.
// Network.joinOrCreateNetwork( this.getTile() );
//
// if( this.isOutput() && this.getInput() != null && this.node != null )
// {
// Network.joinOrCreateNetwork( this.getInput().getTile() );
// this.node.connect( this.getInput().node() );
// }
// }
// else if( this.node != null )
// {
// this.node.remove();
// }
// }
// if( this.isOutput() && this.getInput() != null && this.node != null )
// {
// Network.joinOrCreateNetwork( this.getInput().getTile() );
// this.node.connect( this.getInput().node() );
// }
// }
// else if( this.node != null )
// {
// this.node.remove();
// }
// }
//
// @Nullable
// @Override
// public Node node()
// {
// return this.node;
// }
// @Nullable
// @Override
// public Node node()
// {
// return this.node;
// }
//
// @Override
// public void onConnect( final Node node )
// {
// }
// @Override
// public void onConnect( final Node node )
// {
// }
//
// @Override
// public void onDisconnect( final Node node )
// {
// }
// @Override
// public void onDisconnect( final Node node )
// {
// }
//
// @Override
// public void onMessage( final Message message )
// {
// }
// @Override
// public void onMessage( final Message message )
// {
// }
//
// @Nullable
// @Override
// public Node sidedNode( final ForgeDirection side )
// {
// return side == this.getSide() ? this.node : null;
// }
// @Nullable
// @Override
// public Node sidedNode( final ForgeDirection side )
// {
// return side == this.getSide() ? this.node : null;
// }
//
// @Override
// public boolean canConnect( final ForgeDirection side )
// {
// return side == this.getSide();
// }
//}
// @Override
// public boolean canConnect( final ForgeDirection side )
// {
// return side == this.getSide();
// }
// }
@@ -18,6 +18,7 @@
package appeng.parts.p2p;
import java.util.List;
import java.util.Stack;
@@ -27,7 +28,6 @@ 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;
@@ -141,7 +141,8 @@ public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implemen
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 ) );
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;
}
@@ -211,4 +212,4 @@ public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implemen
{
return true;
}
}
}