Layers and IC2 Tunnel (#2565)

* Re-Activated the IC2 layers to implement an IC2 P2P tunnel.
This commit is contained in:
shartte 2016-11-04 11:20:56 +01:00 committed by GitHub
parent 6f15c2921a
commit f5e4a202cb
21 changed files with 822 additions and 1518 deletions

View file

@ -40,7 +40,6 @@ repositories {
apply from: 'gradle/scripts/dependencies.gradle' apply from: 'gradle/scripts/dependencies.gradle'
apply from: 'gradle/scripts/artifacts.gradle' apply from: 'gradle/scripts/artifacts.gradle'
apply from: 'gradle/scripts/integration.gradle'
apply from: 'gradle/scripts/optional.gradle' apply from: 'gradle/scripts/optional.gradle'
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8

View file

@ -1,29 +0,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>.
*/
// Should be provided by ForgeGradle, some idea user should confirm it.
apply plugin: 'idea'
idea {
module {
inheritOutputDirs = true
// excludes integration due to not being available upon port
excludeDirs += file('src/main/java/appeng/parts/layers/')
}
}

View file

@ -78,7 +78,7 @@ public interface IParts
IItemDefinition p2PTunnelLiquids(); IItemDefinition p2PTunnelLiquids();
// IItemDefinition p2PTunnelEU(); IItemDefinition p2PTunnelEU();
// IItemDefinition p2PTunnelRF(); // IItemDefinition p2PTunnelRF();

View file

@ -63,6 +63,8 @@ import appeng.core.localization.GuiText;
import appeng.core.localization.PlayerMessages; import appeng.core.localization.PlayerMessages;
import appeng.core.stats.PlayerStatsRegistration; import appeng.core.stats.PlayerStatsRegistration;
import appeng.hooks.TickHandler; import appeng.hooks.TickHandler;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.items.materials.ItemMaterial; import appeng.items.materials.ItemMaterial;
import appeng.items.parts.ItemFacade; import appeng.items.parts.ItemFacade;
import appeng.loot.ChestLoot; import appeng.loot.ChestLoot;
@ -246,13 +248,11 @@ public final class Registration
final Runnable recipeLoader = new RecipeLoader( recipeDirectory, customRecipeConfig, this.recipeHandler ); final Runnable recipeLoader = new RecipeLoader( recipeDirectory, customRecipeConfig, this.recipeHandler );
recipeLoader.run(); recipeLoader.run();
// TODO readd layers if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.IC2 ) )
{
// if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.IC2 ) ) partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" );
// { partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySource", "ic2.api.energy.tile.IEnergySource" );
// partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySink", "ic2.api.energy.tile.IEnergySink" ); }
// partHelper.registerNewLayer( "appeng.parts.layers.LayerIEnergySource", "ic2.api.energy.tile.IEnergySource" );
// }
// //
// if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.RF ) ) // if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.RF ) )
// { // {

View file

@ -28,7 +28,10 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.base.Joiner; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
@ -64,9 +67,16 @@ import appeng.tile.networking.TileCableBus;
public class ApiPart implements IPartHelper public class ApiPart implements IPartHelper
{ {
private final Map<String, Class<? extends AEBaseTile>> tileImplementations = new HashMap<>(); private final LoadingCache<CacheKey, Class<? extends AEBaseTile>> cache = CacheBuilder.newBuilder().build( new CacheLoader<CacheKey, Class<? extends AEBaseTile>>()
private final Map<Class<?>, String> interfaces2Layer = new HashMap<Class<?>, String>(); {
private final Map<String, Class> roots = new HashMap<String, Class>(); @Override
public Class<? extends AEBaseTile> load( CacheKey key ) throws Exception
{
return generateCombinedClass( key );
}
} );
private final Map<Class<?>, String> interfaces2Layer = new HashMap<>();
private final List<String> desc = new LinkedList<String>(); private final List<String> desc = new LinkedList<String>();
public void initFMPSupport() public void initFMPSupport()
@ -80,64 +90,79 @@ public class ApiPart implements IPartHelper
} }
} }
/**
* Conceptually this method will build a new class hierarchy that is rooted at the given base class, and includes a chain of all registered layers.
* <p/>
* To accomplish this, it takes the first registered layer, replaces it's inheritance from LayerBase with an inheritance from the given baseClass,
* and uses the resulting class as the parent class for the next registered layer, for which it repeats this process. This process is then repeated
* until a class hierarchy of all layers is formed. While janking out the inheritance from LayerBase, it'll make also sure that calls to that
* classes method will instead be forwarded to the superclass that was inserted as part of the described process.
* <p/>
* Example: If layers A and B are registered, and TileCableBus is passed in as the baseClass, a synthetic class A_B_TileCableBus should be returned,
* which has A_B_TileCableBus -extends-> B_TileCableBus -extends-> TileCableBus as it's class hierarchy, where A_B_TileCableBus has been generated
* from A, and B_TileCableBus has been generated from B.
*/
public Class<? extends AEBaseTile> getCombinedInstance( final Class<? extends AEBaseTile> baseClass ) public Class<? extends AEBaseTile> getCombinedInstance( final Class<? extends AEBaseTile> baseClass )
{ {
String base = baseClass.getName();
if( this.desc.isEmpty() ) if( this.desc.isEmpty() )
{ {
// No layers registered...
return baseClass; return baseClass;
} }
final String description = base + ':' + Joiner.on( ";" ).skipNulls().join( this.desc.iterator() ); return cache.getUnchecked( new CacheKey( baseClass, this.desc ) );
if( this.tileImplementations.get( description ) != null )
{
return this.tileImplementations.get( description );
}
String f = base;// TileCableBus.class.getName();
String Addendum = baseClass.getSimpleName();
Class<? extends AEBaseTile> myClass = baseClass;
String path = f;
for( final String name : this.desc )
{
try
{
final String newPath = path + ';' + name;
myClass = this.getClassByDesc( baseClass.getSimpleName(), newPath, f, this.interfaces2Layer.get( Class.forName( name ) ) );
path = newPath;
}
catch( final Throwable t )
{
AELog.warn( "Error loading " + name );
AELog.debug( t );
}
f = myClass.getName();
}
this.tileImplementations.put( description, myClass );
return myClass;
} }
private Class getClassByDesc( final String addendum, final String fullPath, final String root, final String next ) private Class<? extends AEBaseTile> generateCombinedClass( CacheKey cacheKey )
{ {
if( this.roots.get( fullPath ) != null ) final Class<? extends AEBaseTile> parentClass;
// Get the list of interfaces that still need to be implemented beyond the current one
List<String> remainingInterfaces = cacheKey.getInterfaces().subList( 1, cacheKey.getInterfaces().size() );
// We are not at the root of the class hierarchy yet
if( !remainingInterfaces.isEmpty() )
{ {
return this.roots.get( fullPath ); CacheKey parentKey = new CacheKey( cacheKey.getBaseClass(), remainingInterfaces );
parentClass = cache.getUnchecked( parentKey );
}
else
{
parentClass = cacheKey.getBaseClass();
} }
// Which interface should be implemented in this layer?
String interfaceName = cacheKey.getInterfaces().get( 0 );
try
{
// This is the particular interface that this layer was registered for. Loading the class may fail if i.e. an API is broken or not present
// and in this case, the layer will be skipped!
Class<?> interfaceClass = Class.forName( interfaceName );
String layerImpl = this.interfaces2Layer.get( interfaceClass );
return this.getClassByDesc( parentClass, layerImpl );
}
catch( final Throwable t )
{
AELog.warn( "Error loading " + interfaceName );
AELog.debug( t );
return parentClass;
}
}
@SuppressWarnings( "unchecked" )
private Class<? extends AEBaseTile> getClassByDesc( Class<? extends AEBaseTile> baseClass, final String next )
{
final ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS ); final ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
final ClassNode n = this.getReader( next ); final ClassNode n = this.getReader( next );
final String originalName = n.name; final String originalName = n.name;
try try
{ {
n.name = n.name + '_' + addendum; n.name = n.name + '_' + baseClass.getSimpleName();
n.superName = Class.forName( root ).getName().replace( ".", "/" ); n.superName = baseClass.getName().replace( '.', '/' );
} }
catch( final Throwable t ) catch( final Throwable t )
{ {
@ -167,14 +192,13 @@ public class ApiPart implements IPartHelper
try try
{ {
final Object fish = clazz.newInstance(); final Object fish = clazz.newInstance();
final Class rootC = Class.forName( root );
boolean hasError = false; boolean hasError = false;
if( !rootC.isInstance( fish ) ) if( !baseClass.isInstance( fish ) )
{ {
hasError = true; hasError = true;
AELog.error( "Error, Expected layer to implement " + root + " did not." ); AELog.error( "Error, Expected layer to implement " + baseClass + " did not." );
} }
if( fish instanceof LayerBase ) if( fish instanceof LayerBase )
@ -183,19 +207,16 @@ public class ApiPart implements IPartHelper
AELog.error( "Error, Expected layer to NOT implement LayerBase but it DID." ); AELog.error( "Error, Expected layer to NOT implement LayerBase but it DID." );
} }
if( !fullPath.contains( ".fmp." ) ) if( !( fish instanceof TileCableBus ) )
{ {
if( !( fish instanceof TileCableBus ) ) hasError = true;
{ AELog.error( "Error, Expected layer to implement TileCableBus did not." );
hasError = true; }
AELog.error( "Error, Expected layer to implement TileCableBus did not." );
}
if( !( fish instanceof TileEntity ) ) if( !( fish instanceof TileEntity ) )
{ {
hasError = true; hasError = true;
AELog.error( "Error, Expected layer to implement TileEntity did not." ); AELog.error( "Error, Expected layer to implement TileEntity did not." );
}
} }
if( !hasError ) if( !hasError )
@ -209,7 +230,6 @@ public class ApiPart implements IPartHelper
AELog.debug( t ); AELog.debug( t );
} }
this.roots.put( fullPath, clazz );
return clazz; return clazz;
} }
@ -260,10 +280,19 @@ public class ApiPart implements IPartHelper
defineClassMethod.setAccessible( true ); defineClassMethod.setAccessible( true );
try try
{ {
final Object[] argsA = { name, name, b }; final Object[] argsA = {
name,
name,
b
};
b = (byte[]) runTransformersMethod.invoke( loader, argsA ); b = (byte[]) runTransformersMethod.invoke( loader, argsA );
final Object[] args = { name, b, 0, b.length }; final Object[] args = {
name,
b,
0,
b.length
};
clazz = (Class) defineClassMethod.invoke( loader, args ); clazz = (Class) defineClassMethod.invoke( loader, args );
} }
finally finally
@ -319,7 +348,7 @@ public class ApiPart implements IPartHelper
private static class DefaultPackageClassNameRemapper extends Remapper private static class DefaultPackageClassNameRemapper extends Remapper
{ {
private final HashMap<String, String> inputOutput = new HashMap<String, String>(); private final HashMap<String, String> inputOutput = new HashMap<>();
@Override @Override
public String map( final String typeName ) public String map( final String typeName )
@ -332,4 +361,53 @@ public class ApiPart implements IPartHelper
return o; return o;
} }
} }
private static class CacheKey
{
private final Class<? extends AEBaseTile> baseClass;
private final List<String> interfaces;
private CacheKey( Class<? extends AEBaseTile> baseClass, List<String> interfaces )
{
this.baseClass = baseClass;
this.interfaces = ImmutableList.copyOf( interfaces );
}
private Class<? extends AEBaseTile> getBaseClass()
{
return baseClass;
}
private List<String> getInterfaces()
{
return interfaces;
}
@Override
public boolean equals( Object o )
{
if( this == o )
{
return true;
}
if( o == null || getClass() != o.getClass() )
{
return false;
}
CacheKey cacheKey = (CacheKey) o;
return baseClass.equals( cacheKey.baseClass ) && interfaces.equals( cacheKey.interfaces );
}
@Override
public int hashCode()
{
int result = baseClass.hashCode();
result = 31 * result + interfaces.hashCode();
return result;
}
}
} }

View file

@ -62,7 +62,7 @@ public final class ApiParts implements IParts
private final IItemDefinition p2PTunnelRedstone; private final IItemDefinition p2PTunnelRedstone;
private final IItemDefinition p2PTunnelItems; private final IItemDefinition p2PTunnelItems;
private final IItemDefinition p2PTunnelLiquids; private final IItemDefinition p2PTunnelLiquids;
// private final IItemDefinition p2PTunnelEU; private final IItemDefinition p2PTunnelEU;
// private final IItemDefinition p2PTunnelRF; // private final IItemDefinition p2PTunnelRF;
private final IItemDefinition p2PTunnelLight; private final IItemDefinition p2PTunnelLight;
// private final IItemDefinition p2PTunnelOpenComputers; // private final IItemDefinition p2PTunnelOpenComputers;
@ -113,7 +113,7 @@ public final class ApiParts implements IParts
this.p2PTunnelRedstone = new DamagedItemDefinition( "part.tunnel.redstone", itemPart.createPart( PartType.P2PTunnelRedstone ) ); this.p2PTunnelRedstone = new DamagedItemDefinition( "part.tunnel.redstone", itemPart.createPart( PartType.P2PTunnelRedstone ) );
this.p2PTunnelItems = new DamagedItemDefinition( "part.tunnel.item", itemPart.createPart( PartType.P2PTunnelItems ) ); this.p2PTunnelItems = new DamagedItemDefinition( "part.tunnel.item", itemPart.createPart( PartType.P2PTunnelItems ) );
this.p2PTunnelLiquids = new DamagedItemDefinition( "part.tunnel.fluid", itemPart.createPart( PartType.P2PTunnelLiquids ) ); this.p2PTunnelLiquids = new DamagedItemDefinition( "part.tunnel.fluid", itemPart.createPart( PartType.P2PTunnelLiquids ) );
// this.p2PTunnelEU = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelEU ) ); this.p2PTunnelEU = new DamagedItemDefinition( "part.tunnel.eu", itemPart.createPart( PartType.P2PTunnelEU ) );
// this.p2PTunnelRF = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelRF ) ); // this.p2PTunnelRF = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelRF ) );
this.p2PTunnelLight = new DamagedItemDefinition( "part.tunnel.light", itemPart.createPart( PartType.P2PTunnelLight ) ); this.p2PTunnelLight = new DamagedItemDefinition( "part.tunnel.light", itemPart.createPart( PartType.P2PTunnelLight ) );
// this.p2PTunnelOpenComputers = new DamagedItemDefinition( itemMultiPart.createPart( // this.p2PTunnelOpenComputers = new DamagedItemDefinition( itemMultiPart.createPart(
@ -286,13 +286,13 @@ public final class ApiParts implements IParts
return this.p2PTunnelLiquids; return this.p2PTunnelLiquids;
} }
/* @Override
* @Override public IItemDefinition p2PTunnelEU()
* public IItemDefinition p2PTunnelEU() {
* { return this.p2PTunnelEU;
* return this.p2PTunnelEU; }
* }
* @Override /* @Override
* public IItemDefinition p2PTunnelRF() * public IItemDefinition p2PTunnelRF()
* { * {
* return this.p2PTunnelRF; * return this.p2PTunnelRF;

View file

@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -49,13 +48,9 @@ import appeng.api.implementations.items.IItemGroup;
import appeng.api.parts.IPart; import appeng.api.parts.IPart;
import appeng.api.parts.IPartItem; import appeng.api.parts.IPartItem;
import appeng.api.util.AEColor; import appeng.api.util.AEColor;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.features.ActivityState; import appeng.core.features.ActivityState;
import appeng.core.features.ItemStackSrc; import appeng.core.features.ItemStackSrc;
import appeng.core.localization.GuiText; import appeng.core.localization.GuiText;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.items.AEBaseItem; import appeng.items.AEBaseItem;
@ -110,16 +105,7 @@ public final class ItemPart extends AEBaseItem implements IPartItem, IItemGroup
} }
} }
boolean enabled = true; boolean enabled = mat.isEnabled();
for( final AEFeature f : mat.getFeature() )
{
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
}
for( final IntegrationType integrationType : mat.getIntegrations() )
{
enabled &= IntegrationRegistry.INSTANCE.isEnabled( integrationType );
}
final int partDamage = mat.getBaseDamage() + varID; final int partDamage = mat.getBaseDamage() + varID;
final ActivityState state = ActivityState.from( enabled ); final ActivityState state = ActivityState.from( enabled );

View file

@ -37,9 +37,11 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.parts.IPart; import appeng.api.parts.IPart;
import appeng.api.util.AEColor; import appeng.api.util.AEColor;
import appeng.core.AEConfig;
import appeng.core.AppEng; import appeng.core.AppEng;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText; import appeng.core.localization.GuiText;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType; import appeng.integration.IntegrationType;
import appeng.parts.automation.PartAnnihilationPlane; import appeng.parts.automation.PartAnnihilationPlane;
import appeng.parts.automation.PartExportBus; import appeng.parts.automation.PartExportBus;
@ -57,6 +59,7 @@ import appeng.parts.networking.PartCableGlass;
import appeng.parts.networking.PartCableSmart; import appeng.parts.networking.PartCableSmart;
import appeng.parts.networking.PartDenseCable; import appeng.parts.networking.PartDenseCable;
import appeng.parts.networking.PartQuartzFiber; import appeng.parts.networking.PartQuartzFiber;
import appeng.parts.p2p.PartP2PIC2Power;
import appeng.parts.p2p.PartP2PItems; import appeng.parts.p2p.PartP2PItems;
import appeng.parts.p2p.PartP2PLight; import appeng.parts.p2p.PartP2PLight;
import appeng.parts.p2p.PartP2PLiquids; import appeng.parts.p2p.PartP2PLiquids;
@ -222,8 +225,15 @@ public enum PartType
} }
}, },
// P2PTunnelEU( 465, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelEU ), EnumSet.of( IntegrationType.IC2 ), P2PTunnelEU( 465, "p2p_tunnel_ic2", EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelEU ), EnumSet.of( IntegrationType.IC2 ),
// PartP2PIC2Power.class, GuiText.EUTunnel ), PartP2PIC2Power.class, GuiText.EUTunnel )
{
@Override
String getUnlocalizedName()
{
return "P2PTunnel";
}
},
// P2PTunnelRF( 466, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelRF ), EnumSet.of( IntegrationType.RF ), // P2PTunnelRF( 466, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelRF ), EnumSet.of( IntegrationType.RF ),
// PartP2PRFPower.class, GuiText.RFTunnel ), // PartP2PRFPower.class, GuiText.RFTunnel ),
@ -249,6 +259,7 @@ public enum PartType
@SideOnly( Side.CLIENT ) @SideOnly( Side.CLIENT )
private List<ModelResourceLocation> itemModels; private List<ModelResourceLocation> itemModels;
private final Set<ResourceLocation> models; private final Set<ResourceLocation> models;
private final boolean enabled;
private Constructor<? extends IPart> constructor; private Constructor<? extends IPart> constructor;
PartType( final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c ) PartType( final int baseMetaValue, final String itemModel, final Set<AEFeature> features, final Set<IntegrationType> integrations, final Class<? extends IPart> c )
@ -263,16 +274,31 @@ public enum PartType
this.integrations = Collections.unmodifiableSet( integrations ); this.integrations = Collections.unmodifiableSet( integrations );
this.myPart = c; this.myPart = c;
this.extraName = en; this.extraName = en;
if ( Platform.isClient() )
// The part is enabled if all features + integrations it needs are enabled
this.enabled = features.stream().allMatch( AEConfig.instance::isFeatureEnabled )
&& integrations.stream().allMatch( IntegrationRegistry.INSTANCE::isEnabled );
if( enabled )
{ {
this.itemModels = createItemModels( itemModel ); // Only load models if the part is enabled, otherwise we also run into class-loading issues while
} // scanning for annotations
if( c != null ) if( Platform.isClient() )
{ {
this.models = new HashSet<>( PartModelsHelper.createModels( c ) ); this.itemModels = createItemModels( itemModel );
}
if( c != null )
{
this.models = new HashSet<>( PartModelsHelper.createModels( c ) );
}
else
{
this.models = Collections.emptySet();
}
} }
else else
{ {
this.itemModels = Collections.emptyList();
this.models = Collections.emptySet(); this.models = Collections.emptySet();
} }
} }
@ -289,6 +315,11 @@ public enum PartType
return new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "part/" + baseName ), "inventory" ); return new ModelResourceLocation( new ResourceLocation( AppEng.MOD_ID, "part/" + baseName ), "inventory" );
} }
public boolean isEnabled()
{
return enabled;
}
int getBaseDamage() int getBaseDamage()
{ {
return this.baseDamage; return this.baseDamage;

View file

@ -1,147 +0,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 java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
public class InvLayerData
{
// a simple empty array for empty stuff..
private static final int[] NULL_SIDES = {};
// cache of inventory state.
private final int[][] sides;
private final List<ISidedInventory> inventories;
private final List<InvSot> slots;
public InvLayerData( final int[][] a, final List<ISidedInventory> b, final List<InvSot> c )
{
this.sides = a;
this.inventories = b;
this.slots = c;
}
public ItemStack decreaseStackSize( final int slot, final int amount )
{
if( this.isSlotValid( slot ) )
{
return this.slots.get( slot ).decreaseStackSize( amount );
}
return null;
}
/**
* check if a slot index is valid, prevent crashes from bad code :)
*
* @param slot slot index
*
* @return true, if the slot exists.
*/
boolean isSlotValid( final int slot )
{
return this.slots != null && slot >= 0 && slot < this.slots.size();
}
int getSizeInventory()
{
if( this.slots == null )
{
return 0;
}
return this.slots.size();
}
public ItemStack getStackInSlot( final int slot )
{
if( this.isSlotValid( slot ) )
{
return this.slots.get( slot ).getStackInSlot();
}
return null;
}
public boolean isItemValidForSlot( final int slot, final ItemStack itemstack )
{
if( this.isSlotValid( slot ) )
{
return this.slots.get( slot ).isItemValidForSlot( itemstack );
}
return false;
}
public void setInventorySlotContents( final int slot, final ItemStack itemstack )
{
if( this.isSlotValid( slot ) )
{
this.slots.get( slot ).setInventorySlotContents( itemstack );
}
}
public boolean canExtractItem( final int slot, final ItemStack itemstack, final EnumFacing side )
{
if( this.isSlotValid( slot ) )
{
return this.slots.get( slot ).canExtractItem( itemstack, side );
}
return false;
}
public boolean canInsertItem( final int slot, final ItemStack itemstack, final EnumFacing side )
{
if( this.isSlotValid( slot ) )
{
return this.slots.get( slot ).canInsertItem( itemstack, side );
}
return false;
}
void markDirty()
{
if( this.inventories != null )
{
for( final IInventory inv : this.inventories )
{
inv.markDirty();
}
}
}
public int[] getSlotsForFace( final EnumFacing side )
{
if( this.sides == null || side == null )
{
return NULL_SIDES;
}
return this.sides[side.ordinal()];
}
}

View file

@ -1,68 +0,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.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
public class InvSot
{
private final ISidedInventory partInv;
private final int index;
public InvSot( final ISidedInventory part, final int slot )
{
this.partInv = part;
this.index = slot;
}
public ItemStack decreaseStackSize( final int j )
{
return this.partInv.decrStackSize( this.index, j );
}
ItemStack getStackInSlot()
{
return this.partInv.getStackInSlot( this.index );
}
public boolean isItemValidForSlot( final ItemStack itemstack )
{
return this.partInv.isItemValidForSlot( this.index, itemstack );
}
public void setInventorySlotContents( final ItemStack itemstack )
{
this.partInv.setInventorySlotContents( this.index, itemstack );
}
public boolean canExtractItem( final ItemStack itemstack, final EnumFacing side )
{
return this.partInv.canExtractItem( this.index, itemstack, side );
}
public boolean canInsertItem( final ItemStack itemstack, final EnumFacing side )
{
return this.partInv.canInsertItem( this.index, itemstack, side );
}
}

View file

@ -19,183 +19,186 @@
package appeng.parts.layers; package appeng.parts.layers;
//import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
//import net.minecraft.world.World; import net.minecraft.util.EnumFacing;
//import net.minecraftforge.common.MinecraftForge; import net.minecraft.world.World;
//import ic2.api.energy.tile.IEnergyAcceptor; import net.minecraftforge.common.MinecraftForge;
//import ic2.api.energy.tile.IEnergySink;
//import ic2.api.energy.tile.IEnergyTile; import ic2.api.energy.tile.IEnergyAcceptor;
//import appeng.api.parts.IPart; import ic2.api.energy.tile.IEnergyEmitter;
//import appeng.api.parts.IPartHost; import ic2.api.energy.tile.IEnergySink;
//import appeng.api.parts.LayerBase; import ic2.api.energy.tile.IEnergyTile;
//import appeng.api.parts.LayerFlags;
//import appeng.api.util.ForgeDirection; import appeng.api.parts.IPart;
//import appeng.util.Platform; import appeng.api.parts.IPartHost;
// import appeng.api.parts.LayerBase;
// import appeng.api.parts.LayerFlags;
//public class LayerIEnergySink extends LayerBase implements IEnergySink import appeng.util.Platform;
//{
//
// private TileEntity getEnergySinkTile() public class LayerIEnergySink extends LayerBase implements IEnergySink
// { {
// IPartHost host = (IPartHost) this;
// return host.getTile(); private TileEntity getEnergySinkTile()
// } {
// IPartHost host = (IPartHost) this;
// private World getEnergySinkWorld() return host.getTile();
// { }
// if( this.getEnergySinkTile() == null )
// { private World getEnergySinkWorld()
// return null; {
// } if( this.getEnergySinkTile() == null )
// {
// return this.getEnergySinkTile().getWorld(); return null;
// } }
//
// private boolean isTileValid() return this.getEnergySinkTile().getWorld();
// { }
// TileEntity te = this.getEnergySinkTile();
// private boolean isTileValid()
// if( te == null ) {
// { TileEntity te = this.getEnergySinkTile();
// return false;
// } if( te == null )
// {
// return !te.isInvalid() && te.getWorld().blockExists( te.xCoord, te.yCoord, te.zCoord ); return false;
// } }
//
// private void addToENet() return !te.isInvalid() && te.getWorld().isBlockLoaded( te.getPos() );
// { }
// if( this.getEnergySinkWorld() == null )
// { private void addToENet()
// return; {
// } if( this.getEnergySinkWorld() == null )
// {
// // re-add return;
// this.removeFromENet(); }
//
// if( !this.isInIC2() && Platform.isServer() && this.isTileValid() ) // re-add
// { this.removeFromENet();
// this.getLayerFlags().add( LayerFlags.IC2_ENET );
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySinkTile() ) ); 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 )
// { private void removeFromENet()
// return; {
// } if( this.getEnergySinkWorld() == null )
// {
// if( this.isInIC2() && Platform.isServer() ) return;
// { }
// this.getLayerFlags().remove( LayerFlags.IC2_ENET );
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySinkTile() ) ); 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() )
// { private boolean interestedInIC2()
// return false; {
// } if( !( (IPartHost) this ).isInWorld() )
// {
// int interested = 0; return false;
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS ) }
// {
// IPart part = this.getPart( dir ); int interested = 0;
// if( part instanceof IEnergyTile ) for( EnumFacing dir : EnumFacing.values() )
// { {
// interested++; IPart part = this.getPart( dir );
// } if( part instanceof IEnergyTile )
// } {
// return interested == 1;// if more then one tile is interested we need to abandon... interested++;
// } }
// }
// @Override return interested == 1;// if more then one tile is interested we need to abandon...
// public void partChanged() }
// {
// super.partChanged(); @Override
// public void partChanged()
// if( this.interestedInIC2() ) {
// { super.partChanged();
// this.addToENet();
// } if( this.interestedInIC2() )
// else {
// { this.addToENet();
// this.removeFromENet(); }
// } else
// } {
// this.removeFromENet();
// @Override }
// public boolean acceptsEnergyFrom( TileEntity emitter, ForgeDirection direction ) }
// {
// if( !this.isInIC2() ) @Override
// { public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
// return false; {
// } if( !this.isInIC2() )
// {
// IPart part = this.getPart( direction ); return false;
// if( part instanceof IEnergySink ) }
// {
// return ( (IEnergyAcceptor) part ).acceptsEnergyFrom( emitter, direction ); IPart part = this.getPart( direction );
// } if( part instanceof IEnergySink )
// return false; {
// } return ( (IEnergyAcceptor) part ).acceptsEnergyFrom( emitter, direction );
// }
// private boolean isInIC2() return false;
// { }
// return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
// } private boolean isInIC2()
// {
// @Override return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
// public double getDemandedEnergy() }
// {
// if( !this.isInIC2() ) @Override
// { public double getDemandedEnergy()
// return 0; {
// } if( !this.isInIC2() )
// {
// // this is a flawed implementation, that requires a change to the IC2 API. return 0;
// }
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
// { // this is a flawed implementation, that requires a change to the IC2 API.
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySink ) for( EnumFacing dir : EnumFacing.values() )
// { {
// // use lower number cause ic2 deletes power it sends that isn't received. IPart part = this.getPart( dir );
// return ( (IEnergySink) part ).getDemandedEnergy(); if( part instanceof IEnergySink )
// } {
// } // use lower number cause ic2 deletes power it sends that isn't received.
// return ( (IEnergySink) part ).getDemandedEnergy();
// return 0; }
// } }
//
// @Override return 0;
// public int getSinkTier() }
// {
// return Integer.MAX_VALUE; // no real options here... @Override
// } public int getSinkTier()
// {
// @Override return Integer.MAX_VALUE; // no real options here...
// public double injectEnergy( ForgeDirection directionFrom, double amount, double voltage ) }
// {
// if( !this.isInIC2() ) @Override
// { public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
// return amount; {
// } if( !this.isInIC2() )
// {
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS ) return amount;
// { }
// IPart part = this.getPart( dir );
// if( part instanceof IEnergySink ) for( EnumFacing dir : EnumFacing.values() )
// { {
// return ( (IEnergySink) part ).injectEnergy( directionFrom, amount, voltage ); IPart part = this.getPart( dir );
// } if( part instanceof IEnergySink )
// } {
// return ( (IEnergySink) part ).injectEnergy( directionFrom, amount, voltage );
// return amount; }
// } }
// }
return amount;
}
}

View file

@ -19,188 +19,189 @@
package appeng.parts.layers; package appeng.parts.layers;
//import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
//import net.minecraft.world.World; import net.minecraft.util.EnumFacing;
//import net.minecraftforge.common.MinecraftForge; import net.minecraft.world.World;
//import ic2.api.energy.tile.IEnergyEmitter; import net.minecraftforge.common.MinecraftForge;
//import ic2.api.energy.tile.IEnergySink;
//import ic2.api.energy.tile.IEnergySource; import ic2.api.energy.tile.IEnergyAcceptor;
//import ic2.api.energy.tile.IEnergyTile; import ic2.api.energy.tile.IEnergyEmitter;
//import appeng.api.parts.IPart; import ic2.api.energy.tile.IEnergySource;
//import appeng.api.parts.IPartHost; import ic2.api.energy.tile.IEnergyTile;
//import appeng.api.parts.LayerBase;
//import appeng.api.parts.LayerFlags; import appeng.api.parts.IPart;
//import appeng.api.util.ForgeDirection; import appeng.api.parts.IPartHost;
//import appeng.util.Platform; import appeng.api.parts.LayerBase;
// import appeng.api.parts.LayerFlags;
// import appeng.util.Platform;
//public class LayerIEnergySource extends LayerBase implements IEnergySource
//{
// public class LayerIEnergySource extends LayerBase implements IEnergySource
// private TileEntity getEnergySourceTile() {
// {
// IPartHost host = (IPartHost) this; private TileEntity getEnergySourceTile()
// return host.getTile(); {
// } IPartHost host = (IPartHost) this;
// return host.getTile();
// private World getEnergySourceWorld() }
// {
// if( this.getEnergySourceTile() == null ) private World getEnergySourceWorld()
// { {
// return null; if( this.getEnergySourceTile() == null )
// } {
// return this.getEnergySourceTile().getWorld(); return null;
// } }
// return this.getEnergySourceTile().getWorld();
// private boolean isTileValid() }
// {
// TileEntity te = this.getEnergySourceTile(); private boolean isTileValid()
// if( te == null ) {
// { TileEntity te = this.getEnergySourceTile();
// return false; return te != null && !te.isInvalid();
// } }
// return !te.isInvalid();
// } private void addToENet()
// {
// private void addToENet() if( this.getEnergySourceWorld() == null )
// { {
// if( this.getEnergySourceWorld() == null ) return;
// { }
// return;
// } // re-add
// this.removeFromENet();
// // re-add
// this.removeFromENet(); if( !this.isInIC2() && Platform.isServer() && this.isTileValid() )
// {
// 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() ) );
// this.getLayerFlags().add( LayerFlags.IC2_ENET ); }
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergyTile) this.getEnergySourceTile() ) ); }
// }
// } private void removeFromENet()
// {
// private void removeFromENet() if( this.getEnergySourceWorld() == null )
// { {
// if( this.getEnergySourceWorld() == null ) return;
// { }
// return;
// } if( this.isInIC2() && Platform.isServer() )
// {
// if( this.isInIC2() && Platform.isServer() ) this.getLayerFlags().remove( LayerFlags.IC2_ENET );
// { MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySourceTile() ) );
// this.getLayerFlags().remove( LayerFlags.IC2_ENET ); }
// MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergyTile) this.getEnergySourceTile() ) ); }
// }
// } private boolean interestedInIC2()
// {
// private boolean interestedInIC2() if( !( (IPartHost) this ).isInWorld() )
// { {
// if( !( (IPartHost) this ).isInWorld() ) return false;
// { }
// return false;
// } int interested = 0;
// for( EnumFacing dir : EnumFacing.values() )
// int interested = 0; {
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS ) IPart part = this.getPart( dir );
// { if( part instanceof IEnergyTile )
// IPart part = this.getPart( dir ); {
// if( part instanceof IEnergyTile ) interested++;
// { }
// interested++; }
// } return interested == 1;// if more then one tile is interested we need to abandon...
// } }
// return interested == 1;// if more then one tile is interested we need to abandon...
// } @Override
// public void partChanged()
// @Override {
// public void partChanged() super.partChanged();
// {
// super.partChanged(); if( this.interestedInIC2() )
// {
// if( this.interestedInIC2() ) this.addToENet();
// { }
// this.addToENet(); else
// } {
// else this.removeFromENet();
// { }
// this.removeFromENet(); }
// }
// } @Override
// public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
// @Override {
// public boolean emitsEnergyTo( TileEntity receiver, ForgeDirection direction ) if( !this.isInIC2() )
// { {
// if( !this.isInIC2() ) return false;
// { }
// return false;
// } IPart part = this.getPart( direction );
// if( part instanceof IEnergyEmitter )
// IPart part = this.getPart( direction ); {
// if( part instanceof IEnergySink ) return ( (IEnergyEmitter) part ).emitsEnergyTo( receiver, direction );
// { }
// return ( (IEnergyEmitter) part ).emitsEnergyTo( receiver, direction ); return false;
// } }
// return false;
// } private boolean isInIC2()
// {
// private boolean isInIC2() return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
// { }
// return this.getLayerFlags().contains( LayerFlags.IC2_ENET );
// } @Override
// public double getOfferedEnergy()
// @Override {
// public double getOfferedEnergy() if( !this.isInIC2() )
// { {
// if( !this.isInIC2() ) return 0;
// { }
// return 0;
// } // this is a flawed implementation, that requires a change to the IC2 API.
//
// // this is a flawed implementation, that requires a change to the IC2 API. for( EnumFacing dir : EnumFacing.values() )
// {
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS ) IPart part = this.getPart( dir );
// { if( part instanceof IEnergySource )
// 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();
// // use lower number cause ic2 deletes power it sends that isn't received. }
// return ( (IEnergySource) part ).getOfferedEnergy(); }
// }
// } return 0;
// }
// return 0;
// } @Override
// public void drawEnergy( double amount )
// @Override {
// public void drawEnergy( double amount ) // this is a flawed implementation, that requires a change to the IC2 API.
// {
// // this is a flawed implementation, that requires a change to the IC2 API. for( EnumFacing dir : EnumFacing.values() )
// {
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS ) IPart part = this.getPart( dir );
// { if( part instanceof IEnergySource )
// IPart part = this.getPart( dir ); {
// if( part instanceof IEnergySource ) ( (IEnergySource) part ).drawEnergy( amount );
// { return;
// ( (IEnergySource) part ).drawEnergy( amount ); }
// return; }
// } }
// }
// } @Override
// public int getSourceTier()
// @Override {
// public int getSourceTier() // this is a flawed implementation, that requires a change to the IC2 API.
// {
// // this is a flawed implementation, that requires a change to the IC2 API. for( EnumFacing dir : EnumFacing.values() )
// {
// for( ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS ) IPart part = this.getPart( dir );
// { if( part instanceof IEnergySource )
// IPart part = this.getPart( dir ); {
// if( part instanceof IEnergySource ) return ( (IEnergySource) part ).getSourceTier();
// { }
// return ( (IEnergySource) part ).getSourceTier(); }
// }
// } return 0;
// }
// return 0;
// }
// }
}

View file

@ -1,100 +0,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.minecraftforge.fluids.FluidStack;
//import net.minecraftforge.fluids.FluidTankInfo;
//import net.minecraftforge.fluids.IFluidHandler;
//import appeng.api.parts.IPart;
//import appeng.api.parts.LayerBase;
//import appeng.api.util.ForgeDirection;
//
//
//public class LayerIFluidHandler extends LayerBase implements IFluidHandler
//{
//
// private static final FluidTankInfo[] EMPTY_LIST = new FluidTankInfo[0];
//
// @Override
// public int fill( ForgeDirection from, FluidStack resource, boolean doFill )
// {
// IPart part = this.getPart( from );
// if( part instanceof IFluidHandler )
// {
// return ( (IFluidHandler) part ).fill( from, resource, doFill );
// }
// return 0;
// }
//
// @Override
// public FluidStack drain( ForgeDirection from, FluidStack resource, boolean doDrain )
// {
// IPart part = this.getPart( from );
// if( part instanceof IFluidHandler )
// {
// return ( (IFluidHandler) part ).drain( from, resource, doDrain );
// }
// return null;
// }
//
// @Override
// public FluidStack drain( ForgeDirection from, int maxDrain, boolean doDrain )
// {
// IPart part = this.getPart( from );
// if( part instanceof IFluidHandler )
// {
// return ( (IFluidHandler) part ).drain( from, maxDrain, doDrain );
// }
// return null;
// }
//
// @Override
// public boolean canFill( ForgeDirection from, net.minecraftforge.fluids.Fluid fluid )
// {
// IPart part = this.getPart( from );
// if( part instanceof IFluidHandler )
// {
// return ( (IFluidHandler) part ).canFill( from, fluid );
// }
// return false;
// }
//
// @Override
// public boolean canDrain( ForgeDirection from, net.minecraftforge.fluids.Fluid fluid )
// {
// IPart part = this.getPart( from );
// if( part instanceof IFluidHandler )
// {
// return ( (IFluidHandler) part ).canDrain( from, fluid );
// }
// return false;
// }
//
// @Override
// public FluidTankInfo[] getTankInfo( ForgeDirection from )
// {
// IPart part = this.getPart( from );
// if( part instanceof IFluidHandler )
// {
// return ( (IFluidHandler) part ).getTankInfo( from );
// }
// return EMPTY_LIST;
// }
// }

View file

@ -1,44 +0,0 @@
/*
* 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.layers;
//import buildcraft.api.transport.IPipeConnection;
//import buildcraft.api.transport.IPipeTile.PipeType;
//import appeng.api.parts.IPart;
//import appeng.api.parts.LayerBase;
//import appeng.api.util.ForgeDirection;
//import appeng.helpers.Reflected;
//
//
//@Reflected
//public class LayerIPipeConnection extends LayerBase implements IPipeConnection
//{
//
// @Override
// public ConnectOverride overridePipeConnection( PipeType type, ForgeDirection with )
// {
// IPart part = this.getPart( with );
// if( part instanceof IPipeConnection )
// {
// return ( (IPipeConnection) part ).overridePipeConnection( type, with );
// }
// return ConnectOverride.DEFAULT;
// }
// }

View file

@ -1,300 +0,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 java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.LayerBase;
import appeng.api.util.AEPartLocation;
/**
* Inventory wrapper for parts,
*
* this is considerably more complicated then the other wrappers as it requires creating a "unified inventory".
*
* You must use {@link ISidedInventory} instead of {@link IInventory}.
*
* If your inventory changes in between placement and removal, you must trigger a PartChange on the {@link IPartHost} so
* it can recalculate the inventory wrapper.
*/
public class LayerISidedInventory extends LayerBase implements ISidedInventory
{
// a simple empty array for empty stuff..
private static final int[] NULL_SIDES = {};
private InvLayerData invLayer = null;
/**
* Recalculate inventory wrapper cache.
*/
@Override
public void notifyNeighbors()
{
// cache of inventory state.
int[][] sideData = null;
List<ISidedInventory> inventories = null;
List<InvSot> slots = null;
inventories = new ArrayList<ISidedInventory>();
int slotCount = 0;
for( final AEPartLocation side : AEPartLocation.SIDE_LOCATIONS )
{
final IPart bp = this.getPart( side );
if( bp instanceof ISidedInventory )
{
final ISidedInventory part = (ISidedInventory) bp;
slotCount += part.getSizeInventory();
inventories.add( part );
}
}
if( inventories.isEmpty() || slotCount == 0 )
{
inventories = null;
}
else
{
sideData = new int[][] { NULL_SIDES, NULL_SIDES, NULL_SIDES, NULL_SIDES, NULL_SIDES, NULL_SIDES };
slots = new ArrayList<InvSot>( Collections.nCopies( slotCount, (InvSot) null ) );
int offsetForLayer = 0;
int offsetForPart = 0;
for( final ISidedInventory sides : inventories )
{
offsetForPart = 0;
slotCount = sides.getSizeInventory();
AEPartLocation currentSide = AEPartLocation.INTERNAL;
for( final AEPartLocation side : AEPartLocation.SIDE_LOCATIONS )
{
if( this.getPart( side ) == sides )
{
currentSide = side;
break;
}
}
final int[] cSidesList = sideData[currentSide.ordinal()] = new int[slotCount];
for( int cSlot = 0; cSlot < slotCount; cSlot++ )
{
cSidesList[cSlot] = offsetForLayer;
slots.set( offsetForLayer, new InvSot( sides, offsetForPart ) );
offsetForLayer++;
offsetForPart++;
}
}
}
if( sideData == null || slots == null )
{
this.invLayer = null;
}
else
{
this.invLayer = new InvLayerData( sideData, inventories, slots );
}
// make sure inventory is updated before we call FMP.
super.notifyNeighbors();
}
@Override
public int getSizeInventory()
{
if( this.invLayer == null )
{
return 0;
}
return this.invLayer.getSizeInventory();
}
@Override
public ItemStack getStackInSlot( final int slot )
{
if( this.invLayer == null )
{
return null;
}
return this.invLayer.getStackInSlot( slot );
}
@Override
public ItemStack decrStackSize( final int slot, final int amount )
{
if( this.invLayer == null )
{
return null;
}
return this.invLayer.decreaseStackSize( slot, amount );
}
@Override
public ItemStack removeStackFromSlot( final int slot )
{
return null;
}
@Override
public void setInventorySlotContents( final int slot, final ItemStack itemstack )
{
if( this.invLayer == null )
{
return;
}
this.invLayer.setInventorySlotContents( slot, itemstack );
}
@Override
public String getName()
{
return "AEMultiPart";
}
@Override
public boolean hasCustomName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 64; // no options here.
}
@Override
public boolean isUseableByPlayer( final EntityPlayer entityplayer )
{
return false;
}
@Override
public void openInventory( final EntityPlayer player )
{
}
@Override
public void closeInventory( final EntityPlayer player )
{
}
@Override
public boolean isItemValidForSlot( final int slot, final ItemStack itemstack )
{
if( this.invLayer == null )
{
return false;
}
return this.invLayer.isItemValidForSlot( slot, itemstack );
}
@Override
public void markDirty()
{
if( this.invLayer != null )
{
this.invLayer.markDirty();
}
super.markForSave();
}
@Override
public int[] getSlotsForFace( final EnumFacing side )
{
if( this.invLayer != null )
{
return this.invLayer.getSlotsForFace( side );
}
return NULL_SIDES;
}
@Override
public boolean canInsertItem( final int slot, final ItemStack itemstack, final EnumFacing side )
{
if( this.invLayer == null )
{
return false;
}
return this.invLayer.canInsertItem( slot, itemstack, side );
}
@Override
public boolean canExtractItem( final int slot, final ItemStack itemstack, final EnumFacing side )
{
if( this.invLayer == null )
{
return false;
}
return this.invLayer.canExtractItem( slot, itemstack, side );
}
@Override
public int getField( final int id )
{
return 0;
}
@Override
public void setField( final int id, final int value )
{
}
@Override
public int getFieldCount()
{
return 0;
}
@Override
public void clear()
{
}
@Override
public ITextComponent getDisplayName()
{
return null;
}
}

View file

@ -1,49 +0,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 javax.annotation.Nullable;
//
//import net.minecraftforge.common.util.ForgeDirection;
//
//import pneumaticCraft.api.tileentity.IAirHandler;
//import pneumaticCraft.api.tileentity.ISidedPneumaticMachine;
//
//import appeng.api.parts.IPart;
//import appeng.api.parts.LayerBase;
//
//
//public class LayerPressure extends LayerBase implements ISidedPneumaticMachine
//{
//
// @Nullable
// @Override
// public IAirHandler getAirHandler( ForgeDirection side )
// {
// IPart part = this.getPart( side );
// if( part instanceof ISidedPneumaticMachine )
// {
// return ( (ISidedPneumaticMachine) part ).getAirHandler( side );
// }
//
// return null;
// }
//
// }

View file

@ -1,62 +0,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 javax.annotation.Nullable;
//
//import net.minecraftforge.fml.common.event.FMLInitializationEvent;
//import li.cil.oc.api.network.Node;
//import li.cil.oc.api.network.SidedEnvironment;
//import appeng.api.parts.IPart;
//import appeng.api.parts.LayerBase;
//import appeng.api.util.ForgeDirection;
//import appeng.core.Registration;
//import appeng.helpers.Reflected;
//
//
///**
// * Reflected in {@link Registration#initialize(FMLInitializationEvent)}
// */
//@Reflected
//public class LayerSidedEnvironment extends LayerBase implements SidedEnvironment
//{
// @Nullable
// @Override
// public Node sidedNode( ForgeDirection side )
// {
// final IPart part = this.getPart( side );
// if( part instanceof SidedEnvironment )
// {
// return ( (SidedEnvironment) part ).sidedNode( side );
// }
// return null;
// }
//
// @Override
// public boolean canConnect( ForgeDirection side )
// {
// final IPart part = this.getPart( side );
// if( part instanceof SidedEnvironment )
// {
// return ( (SidedEnvironment) part ).canConnect( side );
// }
// return false;
// }
// }

View file

@ -19,247 +19,245 @@
package appeng.parts.p2p; package appeng.parts.p2p;
//import java.util.LinkedList; import java.util.LinkedList;
// import java.util.List;
//import net.minecraft.init.Blocks;
//import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
//import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
//import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing;
//import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation;
//import net.minecraftforge.common.util.ForgeDirection;
// import ic2.api.energy.tile.IEnergyAcceptor;
//import cpw.mods.fml.relauncher.Side; import ic2.api.energy.tile.IEnergyEmitter;
//import cpw.mods.fml.relauncher.SideOnly; import ic2.api.energy.tile.IEnergySink;
// import ic2.api.energy.tile.IEnergySource;
//import appeng.api.config.PowerUnits;
//import appeng.integration.IntegrationType; import appeng.api.config.PowerUnits;
//import appeng.me.GridAccessException; import appeng.integration.IntegrationType;
//import appeng.me.cache.helpers.TunnelCollection; import appeng.items.parts.PartModels;
//import appeng.transformer.annotations.Integration.Interface; import appeng.me.GridAccessException;
//import appeng.transformer.annotations.Integration.InterfaceList; import appeng.me.cache.helpers.TunnelCollection;
//import appeng.util.Platform; import appeng.transformer.annotations.Integration.Interface;
// import appeng.transformer.annotations.Integration.InterfaceList;
// 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 ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
//{ @InterfaceList( value = {
// @Interface( iface = "ic2.api.energy.tile.IEnergySink", iname = IntegrationType.IC2 ),
// // two packet buffering... @Interface( iface = "ic2.api.energy.tile.IEnergySource", iname = IntegrationType.IC2 )
// double OutputEnergyA; } )
// double OutputEnergyB; public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements IEnergySink, IEnergySource
// // two packet buffering... {
// double OutputVoltageA;
// double OutputVoltageB; private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
// private static final String TAG_BUFFERED_ENERGY_2 = "bufferedEnergy2";
// public PartP2PIC2Power( ItemStack is ) private static final String TAG_BUFFERED_VOLTAGE_1 = "outputPacket1";
// { private static final String TAG_BUFFERED_VOLTAGE_2 = "outputPacket2";
// super( is );
// } private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_ic2" );
//
// @Override @PartModels
// @SideOnly( Side.CLIENT ) public static List<ResourceLocation> getModels()
// public IIcon getTypeTexture() {
// { return MODELS.getModels();
// return Blocks.diamond_block.getBlockTextureFromSide( 0 ); }
// }
// // Buffer the energy + voltage for two IC2 ENET packets
// @Override private double bufferedEnergy1;
// public void readFromNBT( NBTTagCompound tag ) private double bufferedVoltage1;
// { private double bufferedEnergy2;
// super.readFromNBT( tag ); private double bufferedVoltage2;
// this.OutputEnergyA = tag.getDouble( "OutputPacket" );
// this.OutputEnergyB = tag.getDouble( "OutputPacket2" ); public PartP2PIC2Power( ItemStack is )
// this.OutputVoltageA = tag.getDouble( "OutputVoltageA" ); {
// this.OutputVoltageB = tag.getDouble( "OutputVoltageB" ); super( is );
// } }
//
// @Override @Override
// public void writeToNBT( NBTTagCompound tag ) public void readFromNBT( NBTTagCompound tag )
// { {
// super.writeToNBT( tag ); super.readFromNBT( tag );
// tag.setDouble( "OutputPacket", this.OutputEnergyA ); this.bufferedEnergy1 = tag.getDouble( TAG_BUFFERED_ENERGY_1 );
// tag.setDouble( "OutputPacket2", this.OutputEnergyB ); this.bufferedEnergy2 = tag.getDouble( TAG_BUFFERED_ENERGY_2 );
// tag.setDouble( "OutputVoltageA", this.OutputVoltageA ); this.bufferedVoltage1 = tag.getDouble( TAG_BUFFERED_VOLTAGE_1 );
// tag.setDouble( "OutputVoltageB", this.OutputVoltageB ); this.bufferedVoltage2 = tag.getDouble( TAG_BUFFERED_VOLTAGE_2 );
// } }
//
// @Override @Override
// public void onTunnelConfigChange() public void writeToNBT( NBTTagCompound tag )
// { {
// this.getHost().partChanged(); super.writeToNBT( tag );
// } tag.setDouble( TAG_BUFFERED_ENERGY_1, this.bufferedEnergy1 );
// tag.setDouble( TAG_BUFFERED_ENERGY_2, this.bufferedEnergy2 );
// @Override tag.setDouble( TAG_BUFFERED_VOLTAGE_1, this.bufferedVoltage1 );
// public void onTunnelNetworkChange() tag.setDouble( TAG_BUFFERED_VOLTAGE_2, this.bufferedVoltage2 );
// { }
// this.getHost().notifyNeighbors();
// } @Override
// public void onTunnelConfigChange()
// @Override {
// public boolean acceptsEnergyFrom( TileEntity emitter, ForgeDirection direction ) this.getHost().partChanged();
// { }
// if( !this.output )
// { @Override
// return direction == this.side; public void onTunnelNetworkChange()
// } {
// return false; this.getHost().notifyNeighbors();
// } }
//
// @Override @Override
// public boolean emitsEnergyTo( TileEntity receiver, ForgeDirection direction ) public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing direction )
// { {
// if( this.output ) return !this.isOutput() && direction == this.getSide().getFacing();
// { }
// return direction == this.side;
// } @Override
// return false; public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing direction )
// } {
// return this.isOutput() && direction == this.getSide().getFacing();
// @Override }
// public double getDemandedEnergy()
// { @Override
// if( this.output ) public double getDemandedEnergy()
// { {
// return 0; if( this.isOutput() )
// } {
// return 0;
// try }
// {
// for( PartP2PIC2Power t : this.getOutputs() ) try
// { {
// if( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 ) for( PartP2PIC2Power t : this.getOutputs() )
// { {
// return 2048; if( t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001 )
// } {
// } return 2048;
// } }
// catch( GridAccessException e ) }
// { }
// return 0; catch( GridAccessException e )
// } {
// return 0;
// return 0; }
// }
// return 0;
// @Override }
// public int getSinkTier()
// { @Override
// return 4; public int getSinkTier()
// } {
// return 4;
// @Override }
// public double injectEnergy( ForgeDirection directionFrom, double amount, double voltage )
// { @Override
// TunnelCollection<PartP2PIC2Power> outs; public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
// try {
// { TunnelCollection<PartP2PIC2Power> outs;
// outs = this.getOutputs(); try
// } {
// catch( GridAccessException e ) outs = this.getOutputs();
// { }
// return amount; catch( GridAccessException e )
// } {
// return amount;
// if( outs.isEmpty() ) }
// {
// return amount; if( outs.isEmpty() )
// } {
// return amount;
// LinkedList<PartP2PIC2Power> options = new LinkedList<PartP2PIC2Power>(); }
// for( PartP2PIC2Power o : outs )
// { LinkedList<PartP2PIC2Power> options = new LinkedList<>();
// if( o.OutputEnergyA <= 0.01 ) for( PartP2PIC2Power o : outs )
// { {
// options.add( o ); if( o.bufferedEnergy1 <= 0.01 )
// } {
// } options.add( o );
// }
// if( options.isEmpty() ) }
// {
// for( PartP2PIC2Power o : outs ) if( options.isEmpty() )
// { {
// if( o.OutputEnergyB <= 0.01 ) for( PartP2PIC2Power o : outs )
// { {
// options.add( o ); if( o.bufferedEnergy2 <= 0.01 )
// } {
// } options.add( o );
// } }
// }
// if( options.isEmpty() ) }
// {
// for( PartP2PIC2Power o : outs ) if( options.isEmpty() )
// { {
// options.add( o ); for( PartP2PIC2Power o : outs )
// } {
// } options.add( o );
// }
// if( options.isEmpty() ) }
// {
// return amount; if( options.isEmpty() )
// } {
// return amount;
// PartP2PIC2Power x = Platform.pickRandom( options ); }
//
// if( x != null && x.OutputEnergyA <= 0.001 ) PartP2PIC2Power x = Platform.pickRandom( options );
// {
// this.queueTunnelDrain( PowerUnits.EU, amount ); if( x != null && x.bufferedEnergy1 <= 0.001 )
// x.OutputEnergyA = amount; {
// x.OutputVoltageA = voltage; this.queueTunnelDrain( PowerUnits.EU, amount );
// return 0; x.bufferedEnergy1 = amount;
// } x.bufferedVoltage1 = voltage;
// return 0;
// if( x != null && x.OutputEnergyB <= 0.001 ) }
// {
// this.queueTunnelDrain( PowerUnits.EU, amount ); if( x != null && x.bufferedEnergy2 <= 0.001 )
// x.OutputEnergyB = amount; {
// x.OutputVoltageB = voltage; this.queueTunnelDrain( PowerUnits.EU, amount );
// return 0; x.bufferedEnergy2 = amount;
// } x.bufferedVoltage2 = voltage;
// return 0;
// return amount; }
// }
// return amount;
// public float getPowerDrainPerTick() }
// {
// return 0.5f; @Override
// } public double getOfferedEnergy()
// {
// @Override if( this.isOutput() )
// public double getOfferedEnergy() {
// { return this.bufferedEnergy1;
// if( this.output ) }
// { return 0;
// return this.OutputEnergyA; }
// }
// return 0; @Override
// } public void drawEnergy( double amount )
// {
// @Override this.bufferedEnergy1 -= amount;
// public void drawEnergy( double amount ) if( this.bufferedEnergy1 < 0.001 )
// { {
// this.OutputEnergyA -= amount; this.bufferedEnergy1 = this.bufferedEnergy2;
// if( this.OutputEnergyA < 0.001 ) this.bufferedEnergy2 = 0;
// {
// this.OutputEnergyA = this.OutputEnergyB; this.bufferedVoltage1 = this.bufferedVoltage2;
// this.OutputEnergyB = 0; this.bufferedVoltage2 = 0;
// }
// this.OutputVoltageA = this.OutputVoltageB; }
// this.OutputVoltageB = 0;
// } @Override
// } public int getSourceTier()
// {
// @Override // Sadly IC2 doesn't support changing the tier once we're registered, so we
// public int getSourceTier() // go with the highest here... At this point it's somewhat unclear as to what effect
// { // this realistically has.
// if( this.output ) return 4;
// { }
// return this.calculateTierFromVoltage( this.OutputVoltageA );
// } @Override
// return 4; public List<ResourceLocation> getStaticModels()
// } {
// return MODELS.getModel( isPowered(), isActive() );
// private int calculateTierFromVoltage( double voltage ) }
// {
// return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage ); }
// }
// }

View file

@ -235,14 +235,9 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
newType = parts.p2PTunnelLiquids().maybeStack( 1 ).orElse( null ); newType = parts.p2PTunnelLiquids().maybeStack( 1 ).orElse( null );
break; break;
/* case IC2_POWER:
* case IC2_POWER: newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( null );
* for( ItemStack stack : parts.p2PTunnelEU().maybeStack( 1 ).asSet() ) break;
* {
* newType = stack;
* }
* break;
*/
case ITEM: case ITEM:
newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( null ); newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( null );

View file

@ -0,0 +1,6 @@
{
"parent": "appliedenergistics2:item/part/p2p_tunnel",
"textures": {
"type": "minecraft:blocks/diamond_block"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "appliedenergistics2:part/p2p/p2p_tunnel_base",
"textures": {
"type": "minecraft:blocks/diamond_block"
}
}