Added skystone, skystone block, skystone brick, skystone small brick, certus quartz, certus quartz pillar, chiseled certus quartz and fluix stars

To integrate these into the current system, some changes to the background had to be done, especially to the feature handler. It now uses an interface to work against which you can implement to get your own feature handler instead modifying the base one and add several special cases code
This commit is contained in:
thatsIch
2014-11-18 16:47:30 +01:00
parent 1572351a54
commit 56aad10ffe
46 changed files with 2624 additions and 1401 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,60 @@
/*
* 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.block;
import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import appeng.core.features.AEFeature;
import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.StairBlockFeatureHandler;
public abstract class AEBaseStairBlock extends BlockStairs implements IAEFeature
{
private final IFeatureHandler features;
protected AEBaseStairBlock( Block block, int meta, EnumSet<AEFeature> features )
{
super( block, meta );
this.features = new StairBlockFeatureHandler( features, this, Optional.<String> absent() );
this.setBlockName( block.getUnlocalizedName() );
this.setLightOpacity( 0 );
}
@Override
public IFeatureHandler handler()
{
return this.features;
}
@Override
public void postInit()
{
// Override to do stuff
}
}
@@ -18,21 +18,17 @@
package appeng.block; package appeng.block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
public class AEDecorativeBlock extends AEBaseBlock public class AEDecorativeBlock extends AEBaseBlock
{ {
public AEDecorativeBlock( Class<? extends AEBaseBlock> c, Material mat )
protected AEDecorativeBlock(Class<?> c, Material mat) {
super( c, mat );
}
@Override
public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s)
{ {
return super.unmappedGetIcon( w, x, y, z, s ); super( c, mat );
} }
@Override @Override
@@ -41,4 +37,9 @@ public class AEDecorativeBlock extends AEBaseBlock
return 0; return 0;
} }
@Override
public IIcon getIcon( IBlockAccess w, int x, int y, int z, int s )
{
return super.unmappedGetIcon( w, x, y, z, s );
}
} }
@@ -18,18 +18,20 @@
package appeng.block.solids; package appeng.block.solids;
import java.util.EnumSet; import java.util.EnumSet;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import appeng.block.AEDecorativeBlock; import appeng.block.AEDecorativeBlock;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
public class BlockFluix extends AEDecorativeBlock public class BlockFluix extends AEDecorativeBlock
{ {
public BlockFluix()
public BlockFluix() { {
super( BlockFluix.class, Material.rock ); super( BlockFluix.class, Material.rock );
setFeature( EnumSet.of( AEFeature.DecorativeQuartzBlocks ) ); setFeature( EnumSet.of( AEFeature.DecorativeQuartzBlocks ) );
} }
} }
@@ -0,0 +1,35 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import appeng.block.AEBaseStairBlock;
import appeng.block.solids.BlockQuartzChiseled;
import appeng.core.features.AEFeature;
public class ChiseledQuartzStairBlock extends AEBaseStairBlock
{
public ChiseledQuartzStairBlock( BlockQuartzChiseled block )
{
super( block, 0, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,36 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import net.minecraft.block.Block;
import appeng.block.AEBaseStairBlock;
import appeng.core.features.AEFeature;
public class FluixStairBlock extends AEBaseStairBlock
{
public FluixStairBlock( Block block )
{
super( block, 0, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,35 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import appeng.block.AEBaseStairBlock;
import appeng.block.solids.BlockQuartzPillar;
import appeng.core.features.AEFeature;
public class QuartzPillarStairBlock extends AEBaseStairBlock
{
public QuartzPillarStairBlock( BlockQuartzPillar block )
{
super( block, 0, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,35 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import appeng.block.AEBaseStairBlock;
import appeng.block.solids.BlockQuartz;
import appeng.core.features.AEFeature;
public class QuartzStairBlock extends AEBaseStairBlock
{
public QuartzStairBlock( BlockQuartz block )
{
super( block, 0, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,36 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import net.minecraft.block.Block;
import appeng.block.AEBaseStairBlock;
import appeng.core.features.AEFeature;
public class SkyStoneBlockStairBlock extends AEBaseStairBlock
{
public SkyStoneBlockStairBlock( Block block, Integer meta )
{
super( block, meta, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,36 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import net.minecraft.block.Block;
import appeng.block.AEBaseStairBlock;
import appeng.core.features.AEFeature;
public class SkyStoneBrickStairBlock extends AEBaseStairBlock
{
public SkyStoneBrickStairBlock( Block block, Integer meta )
{
super( block, meta, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,36 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import net.minecraft.block.Block;
import appeng.block.AEBaseStairBlock;
import appeng.core.features.AEFeature;
public class SkyStoneSmallBrickStairBlock extends AEBaseStairBlock
{
public SkyStoneSmallBrickStairBlock( Block block, int meta )
{
super( block, meta, EnumSet.of( AEFeature.Core ) );
}
}
@@ -0,0 +1,36 @@
/*
* 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.block.stair;
import java.util.EnumSet;
import net.minecraft.block.Block;
import appeng.block.AEBaseStairBlock;
import appeng.core.features.AEFeature;
public class SkyStoneStairBlock extends AEBaseStairBlock
{
public SkyStoneStairBlock( Block block, Integer meta )
{
super( block, meta, EnumSet.of( AEFeature.Core ) );
}
}
+75 -117
View File
@@ -18,9 +18,13 @@
package appeng.core; package appeng.core;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import com.google.common.base.Optional;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
@@ -29,6 +33,14 @@ import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.RecipeSorter.Category; import net.minecraftforge.oredict.RecipeSorter.Category;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.VillagerRegistry;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Upgrades; import appeng.api.config.Upgrades;
import appeng.api.definitions.Blocks; import appeng.api.definitions.Blocks;
@@ -90,6 +102,14 @@ import appeng.block.solids.OreQuartzCharged;
import appeng.block.spatial.BlockMatrixFrame; import appeng.block.spatial.BlockMatrixFrame;
import appeng.block.spatial.BlockSpatialIOPort; import appeng.block.spatial.BlockSpatialIOPort;
import appeng.block.spatial.BlockSpatialPylon; import appeng.block.spatial.BlockSpatialPylon;
import appeng.block.stair.ChiseledQuartzStairBlock;
import appeng.block.stair.FluixStairBlock;
import appeng.block.stair.QuartzPillarStairBlock;
import appeng.block.stair.QuartzStairBlock;
import appeng.block.stair.SkyStoneBlockStairBlock;
import appeng.block.stair.SkyStoneBrickStairBlock;
import appeng.block.stair.SkyStoneSmallBrickStairBlock;
import appeng.block.stair.SkyStoneStairBlock;
import appeng.block.storage.BlockChest; import appeng.block.storage.BlockChest;
import appeng.block.storage.BlockDrive; import appeng.block.storage.BlockDrive;
import appeng.block.storage.BlockIOPort; import appeng.block.storage.BlockIOPort;
@@ -184,17 +204,9 @@ import appeng.recipes.ores.OreDictionaryHandler;
import appeng.spatial.BiomeGenStorage; import appeng.spatial.BiomeGenStorage;
import appeng.spatial.StorageWorldProvider; import appeng.spatial.StorageWorldProvider;
import appeng.tile.AEBaseTile; import appeng.tile.AEBaseTile;
import appeng.util.ClassInstantiation;
import appeng.util.Platform; import appeng.util.Platform;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.VillagerRegistry;
public class Registration public class Registration
{ {
@@ -202,6 +214,7 @@ public class Registration
final public static Registration instance = new Registration(); final public static Registration instance = new Registration();
public final RecipeHandler recipeHandler; public final RecipeHandler recipeHandler;
final private Multimap<AEFeature, Class> featuresToEntities = ArrayListMultimap.create();
public BiomeGenBase storageBiome; public BiomeGenBase storageBiome;
private Registration() private Registration()
@@ -209,8 +222,6 @@ public class Registration
recipeHandler = new RecipeHandler(); recipeHandler = new RecipeHandler();
} }
final private Multimap<AEFeature, Class> featuresToEntities = ArrayListMultimap.create();
public void PreInit( FMLPreInitializationEvent event ) public void PreInit( FMLPreInitializationEvent event )
{ {
registerSpatial( false ); registerSpatial( false );
@@ -433,6 +444,17 @@ public class Registration
} }
} }
// stairs
this.addFeature( SkyStoneStairBlock.class, blocks.blockSkyStone.block(), 0 );
this.addFeature( SkyStoneBlockStairBlock.class, blocks.blockSkyStone.block(), 1 );
this.addFeature( SkyStoneBrickStairBlock.class, blocks.blockSkyStone.block(), 2 );
this.addFeature( SkyStoneSmallBrickStairBlock.class, blocks.blockSkyStone.block(), 3 );
this.addFeature( FluixStairBlock.class, blocks.blockFluix.block() );
this.addFeature( QuartzStairBlock.class, blocks.blockQuartz.block() );
this.addFeature( ChiseledQuartzStairBlock.class, blocks.blockQuartzChiseled.block() );
this.addFeature( QuartzPillarStairBlock.class, blocks.blockQuartzPillar.block() );
// unsupported developer tools
addFeature( ToolEraser.class ); addFeature( ToolEraser.class );
addFeature( ToolMeteoritePlacer.class ); addFeature( ToolMeteoritePlacer.class );
addFeature( ToolDebugCard.class ); addFeature( ToolDebugCard.class );
@@ -443,95 +465,70 @@ public class Registration
addFeature( BlockCubeGenerator.class ); addFeature( BlockCubeGenerator.class );
} }
private AEItemDefinition addFeature(Class c, Object... Args) private void registerSpatial( boolean force )
{ {
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.SpatialIO ) )
return;
try AEConfig config = AEConfig.instance;
{
java.lang.reflect.Constructor[] con = c.getConstructors();
Object obj = null;
for (Constructor conItem : con) if ( storageBiome == null )
{ {
Class paramTypes[] = conItem.getParameterTypes(); if ( force && config.storageBiomeID == -1 )
if ( paramTypes.length == Args.length )
{ {
boolean valid = true; config.storageBiomeID = Platform.findEmpty( BiomeGenBase.getBiomeGenArray() );
if ( config.storageBiomeID == -1 )
throw new RuntimeException( "Biome Array is full, please free up some Biome ID's or disable spatial." );
for (int idx = 0; idx < paramTypes.length; idx++) storageBiome = new BiomeGenStorage( config.storageBiomeID );
{ config.save();
Class cz = Args[idx].getClass();
if ( !isClassMatch( paramTypes[idx], cz, Args[idx] ) )
valid = false;
} }
if ( valid ) if ( !force && config.storageBiomeID != -1 )
storageBiome = new BiomeGenStorage( config.storageBiomeID );
}
if ( config.storageProviderID != -1 )
{ {
obj = conItem.newInstance( Args ); DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false );
break;
}
}
} }
if ( obj instanceof IAEFeature ) if ( config.storageProviderID == -1 && force )
{ {
IAEFeature feature = (IAEFeature) obj; config.storageProviderID = -11;
for (AEFeature f : feature.feature().getFeatures()) while ( !DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false ) )
featuresToEntities.put( f, c ); config.storageProviderID--;
feature.feature().register(); config.save();
}
}
private AEItemDefinition addFeature( Class<? extends IAEFeature> featureClass, Object... args )
{
ClassInstantiation<IAEFeature> instantiation = new ClassInstantiation<IAEFeature>( featureClass, args );
Optional<IAEFeature> instance = instantiation.get();
if ( instance.isPresent() )
{
IAEFeature feature = instance.get();
for ( AEFeature f : feature.handler().getFeatures() )
{
this.featuresToEntities.put( f, featureClass );
}
feature.handler().register();
feature.postInit(); feature.postInit();
return feature.feature(); return feature.handler().getDefinition();
} }
else if ( obj == null )
throw new RuntimeException( "No valid constructor found." );
else else
throw new RuntimeException( "Non AE Feature Registered" );
}
catch (Throwable e)
{ {
throw new RuntimeException( "Error with Feature: " + c.getName(), e ); throw new RuntimeException( "Error with Feature: " + featureClass.getName() );
} }
} }
private boolean isClassMatch(Class expected, Class got, Object value)
{
if ( value == null && !expected.isPrimitive() )
return true;
expected = condense( expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
got = condense( got, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
if ( expected == got || expected.isAssignableFrom( got ) )
return true;
return false;
}
private Class condense(Class expected, Class... wrappers)
{
if ( expected.isPrimitive() )
{
for (Class clz : wrappers)
{
try
{
if ( expected == clz.getField( "TYPE" ).get( null ) )
return clz;
}
catch (Throwable t)
{
AELog.error( t );
}
}
}
return expected;
}
public void Init( FMLInitializationEvent event ) public void Init( FMLInitializationEvent event )
{ {
// Perform ore camouflage! // Perform ore camouflage!
@@ -761,43 +758,4 @@ public class Registration
OreDictionaryHandler.instance.bakeRecipes(); OreDictionaryHandler.instance.bakeRecipes();
} }
private void registerSpatial(boolean force)
{
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.SpatialIO ) )
return;
AEConfig config = AEConfig.instance;
if ( storageBiome == null )
{
if ( force && config.storageBiomeID == -1 )
{
config.storageBiomeID = Platform.findEmpty( BiomeGenBase.getBiomeGenArray() );
if ( config.storageBiomeID == -1 )
throw new RuntimeException( "Biome Array is full, please free up some Biome ID's or disable spatial." );
storageBiome = new BiomeGenStorage( config.storageBiomeID );
config.save();
}
if ( !force && config.storageBiomeID != -1 )
storageBiome = new BiomeGenStorage( config.storageBiomeID );
}
if ( config.storageProviderID != -1 )
{
DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false );
}
if ( config.storageProviderID == -1 && force )
{
config.storageProviderID = -11;
while (!DimensionManager.registerProviderType( config.storageProviderID, StorageWorldProvider.class, false ))
config.storageProviderID--;
config.save();
}
}
} }
@@ -0,0 +1,43 @@
/*
* 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.core.features;
import net.minecraft.tileentity.TileEntity;
import appeng.block.AEBaseBlock;
public class AEBlockDefinition extends BlockDefinition
{
private final AEBaseBlock block;
public AEBlockDefinition( AEBaseBlock block, boolean enabled )
{
super( block, enabled );
this.block = block;
}
@Override
public Class<? extends TileEntity> entity()
{
return this.block.getTileEntityClass();
}
}
@@ -0,0 +1,91 @@
/*
* 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.core.features;
import java.util.EnumSet;
import com.google.common.base.Optional;
import cpw.mods.fml.common.registry.GameRegistry;
import appeng.api.util.AEItemDefinition;
import appeng.block.AEBaseBlock;
import appeng.block.AEBaseItemBlock;
import appeng.core.CommonHelper;
import appeng.core.CreativeTab;
import appeng.util.Platform;
public class AEBlockFeatureHandler implements IFeatureHandler
{
private final EnumSet<AEFeature> features;
private final AEBaseBlock featured;
private final FeatureNameExtractor extractor;
private final boolean enabled;
private final AEBlockDefinition definition;
public AEBlockFeatureHandler( EnumSet<AEFeature> features, AEBaseBlock featured, Optional<String> subName )
{
this.features = features;
this.featured = featured;
this.extractor = new FeatureNameExtractor( featured.getClass(), subName );
this.enabled = new FeaturedActiveChecker( features ).get();
this.definition = new AEBlockDefinition( featured, this.enabled );
}
@Override
public boolean isFeatureAvailable()
{
return this.enabled;
}
@Override
public EnumSet<AEFeature> getFeatures()
{
return this.features;
}
@Override
public AEItemDefinition getDefinition()
{
return this.definition;
}
@Override
public void register()
{
if ( this.enabled )
{
String name = this.extractor.get();
this.featured.setCreativeTab( CreativeTab.instance );
this.featured.setBlockName( /* "tile." */"appliedenergistics2." + name );
this.featured.setBlockTextureName( "appliedenergistics2:" + name );
if ( Platform.isClient() )
{
CommonHelper.proxy.bindTileEntitySpecialRenderer( this.featured.getTileEntityClass(), this.featured );
}
Class<? extends AEBaseItemBlock> itemBlockClass = this.featured.getItemBlockClass();
GameRegistry.registerBlock( this.featured, itemBlockClass, "tile." + name );
}
}
}
@@ -18,13 +18,18 @@
package appeng.core.features; package appeng.core.features;
import java.util.EnumSet; import java.util.EnumSet;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.common.registry.GameRegistry;
import appeng.api.util.AEItemDefinition; import appeng.api.util.AEItemDefinition;
import appeng.block.AEBaseBlock; import appeng.block.AEBaseBlock;
import appeng.block.AEBaseItemBlock; import appeng.block.AEBaseItemBlock;
@@ -34,7 +39,7 @@ import appeng.core.CreativeTab;
import appeng.core.CreativeTabFacade; import appeng.core.CreativeTabFacade;
import appeng.items.parts.ItemFacade; import appeng.items.parts.ItemFacade;
import appeng.util.Platform; import appeng.util.Platform;
import cpw.mods.fml.common.registry.GameRegistry;
public class AEFeatureHandler implements AEItemDefinition public class AEFeatureHandler implements AEItemDefinition
{ {
@@ -46,8 +51,10 @@ public class AEFeatureHandler implements AEItemDefinition
private Item ItemData; private Item ItemData;
private Block BlockData; private Block BlockData;
private BlockStairs stairData;
public AEFeatureHandler(EnumSet<AEFeature> features, IAEFeature feature, String subName) { public AEFeatureHandler( EnumSet<AEFeature> features, IAEFeature feature, String subName )
{
this.features = features; this.features = features;
this.feature = feature; this.feature = feature;
this.subName = subName; this.subName = subName;
@@ -58,11 +65,84 @@ public class AEFeatureHandler implements AEItemDefinition
if ( isFeatureAvailable() ) if ( isFeatureAvailable() )
{ {
if ( feature instanceof Item ) if ( feature instanceof Item )
{
initItem( ( Item ) feature ); initItem( ( Item ) feature );
if ( feature instanceof Block ) }
else if ( this.feature instanceof BlockStairs )
{
this.initStairBlock( ( BlockStairs ) this.feature );
}
else if ( feature instanceof Block )
{
initBlock( ( Block ) feature ); initBlock( ( Block ) feature );
} }
} }
}
public boolean isFeatureAvailable()
{
boolean enabled = true;
for ( AEFeature f : features )
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
return enabled;
}
private void initItem( Item i )
{
ItemData = i;
String name = getName( i.getClass(), subName );
i.setTextureName( "appliedenergistics2:" + name );
i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name );
if ( i instanceof ItemFacade )
i.setCreativeTab( CreativeTabFacade.instance );
else
i.setCreativeTab( CreativeTab.instance );
if ( name.equals( "ItemMaterial" ) )
name = "ItemMultiMaterial";
else if ( name.equals( "ItemPart" ) )
name = "ItemMultiPart";
GameRegistry.registerItem( i, "item." + name );
}
private void initStairBlock( BlockStairs stair )
{
this.stairData = stair;
String name = getName( stair.getClass(), subName );
stair.setCreativeTab( CreativeTab.instance );
stair.setBlockName( /* "tile." */"appliedenergistics2." + name );
stair.setBlockTextureName( "appliedenergistics2:" + name );
GameRegistry.registerBlock( stair, "tile." + name );
}
private void initBlock( Block b )
{
BlockData = b;
String name = getName( b.getClass(), subName );
b.setCreativeTab( CreativeTab.instance );
b.setBlockName( /* "tile." */"appliedenergistics2." + name );
b.setBlockTextureName( "appliedenergistics2:" + name );
if ( Platform.isClient() && BlockData instanceof AEBaseBlock )
{
AEBaseBlock bb = ( AEBaseBlock ) b;
CommonHelper.proxy.bindTileEntitySpecialRenderer( bb.getTileEntityClass(), bb );
}
Class<? extends AEBaseItemBlock> itemBlock = AEBaseItemBlock.class;
if ( b instanceof AEBaseBlock )
itemBlock = ( ( AEBaseBlock ) b ).getItemBlockClass();
GameRegistry.registerBlock( b, itemBlock, "tile." + name );
}
public static String getName( Class o, String subName ) public static String getName( Class o, String subName )
{ {
@@ -91,70 +171,36 @@ public class AEFeatureHandler implements AEItemDefinition
return name; return name;
} }
private void initItem(Item i)
{
ItemData = i;
String name = getName( i.getClass(), subName );
i.setTextureName( "appliedenergistics2:" + name );
i.setUnlocalizedName( /* "item." */"appliedenergistics2." + name );
if ( i instanceof ItemFacade )
i.setCreativeTab( CreativeTabFacade.instance );
else
i.setCreativeTab( CreativeTab.instance );
if ( name.equals( "ItemMaterial" ) )
name = "ItemMultiMaterial";
else if ( name.equals( "ItemPart" ) )
name = "ItemMultiPart";
GameRegistry.registerItem( i, "item." + name );
}
private void initBlock(Block b)
{
BlockData = b;
String name = getName( b.getClass(), subName );
b.setCreativeTab( CreativeTab.instance );
b.setBlockName( /* "tile." */"appliedenergistics2." + name );
b.setBlockTextureName( "appliedenergistics2:" + name );
if ( Platform.isClient() && BlockData instanceof AEBaseBlock )
{
AEBaseBlock bb = (AEBaseBlock) b;
CommonHelper.proxy.bindTileEntitySpecialRenderer( bb.getTileEntityClass(), bb );
}
Class<? extends AEBaseItemBlock> itemBlock = AEBaseItemBlock.class;
if ( b instanceof AEBaseBlock )
itemBlock = ((AEBaseBlock) b).getItemBlockClass();
GameRegistry.registerBlock( b, itemBlock, "tile." + name );
}
public EnumSet<AEFeature> getFeatures() public EnumSet<AEFeature> getFeatures()
{ {
return features.clone(); return features.clone();
} }
public boolean isFeatureAvailable()
{
boolean enabled = true;
for (AEFeature f : features)
enabled = enabled && AEConfig.instance.isFeatureEnabled( f );
return enabled;
}
@Override @Override
public Block block() public Block block()
{ {
return BlockData; return BlockData;
} }
@Override
public Item item()
{
if ( this.ItemData != null )
{
return this.ItemData;
}
else if ( this.BlockData != null )
{
return Item.getItemFromBlock( this.BlockData );
}
else if ( this.stairData != null )
{
return Item.getItemFromBlock( this.stairData );
}
return null;
}
@Override @Override
public Class<? extends TileEntity> entity() public Class<? extends TileEntity> entity()
{ {
@@ -167,14 +213,6 @@ public class AEFeatureHandler implements AEItemDefinition
return null; return null;
} }
@Override
public Item item()
{
if ( ItemData == null && BlockData != null )
return Item.getItemFromBlock( BlockData );
return ItemData;
}
@Override @Override
public ItemStack stack( int stackSize ) public ItemStack stack( int stackSize )
{ {
@@ -190,6 +228,7 @@ public class AEFeatureHandler implements AEItemDefinition
rv.stackSize = stackSize; rv.stackSize = stackSize;
return rv; return rv;
} }
return null; return null;
} }
@@ -0,0 +1,83 @@
/*
* 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.core.features;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import appeng.api.util.AEItemDefinition;
import appeng.util.Platform;
public class BlockDefinition implements AEItemDefinition
{
private final Block block;
private final boolean enabled;
public BlockDefinition( Block block, boolean enabled )
{
this.block = block;
this.enabled = enabled;
}
@Override
public Block block()
{
return this.block;
}
@Override
public Item item()
{
return Item.getItemFromBlock( this.block );
}
@Override
public Class<? extends TileEntity> entity()
{
return null;
}
@Override
public ItemStack stack( int stackSize )
{
if ( this.enabled )
{
return new ItemStack( this.block );
}
return null;
}
@Override
public boolean sameAsStack( ItemStack comparableItem )
{
return this.enabled && Platform.isSameItemType( comparableItem, this.stack( 1 ) );
}
@Override
public boolean sameAsBlock( IBlockAccess world, int x, int y, int z )
{
return this.enabled && world.getBlock( x, y, z ) == this.block;
}
}
@@ -0,0 +1,72 @@
/*
* 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.core.features;
import com.google.common.base.Optional;
public class FeatureNameExtractor
{
private Class<?> clazz;
private Optional<String> subName;
public FeatureNameExtractor( Class<?> clazz, Optional<String> subName )
{
this.clazz = clazz;
this.subName = subName;
}
public String get()
{
String name = this.clazz.getSimpleName();
if ( name.startsWith( "ItemMultiPart" ) )
{
name = name.replace( "ItemMultiPart", "ItemPart" );
}
else if ( name.startsWith( "ItemMultiMaterial" ) )
{
name = name.replace( "ItemMultiMaterial", "ItemMaterial" );
}
if ( this.subName.isPresent() )
{
final String subName = this.subName.get();
// simple hack to allow me to do get nice names for these without
// mode code outside of AEBaseItem
if ( subName.startsWith( "P2PTunnel" ) )
{
return "ItemPart.P2PTunnel";
}
else if ( subName.equals( "CertusQuartzTools" ) )
{
return name.replace( "Quartz", "CertusQuartz" );
}
else if ( subName.equals( "NetherQuartzTools" ) )
{
return name.replace( "Quartz", "NetherQuartz" );
}
name += "." + subName;
}
return name;
}
}
@@ -0,0 +1,48 @@
/*
* 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.core.features;
import java.util.EnumSet;
import appeng.core.AEConfig;
public class FeaturedActiveChecker
{
private EnumSet<AEFeature> features;
public FeaturedActiveChecker( EnumSet<AEFeature> features )
{
this.features = features;
}
public boolean get()
{
for ( AEFeature f : this.features )
{
if ( !AEConfig.instance.isFeatureEnabled( f ) )
{
return false;
}
}
return true;
}
}
@@ -18,11 +18,10 @@
package appeng.core.features; package appeng.core.features;
public interface IAEFeature public interface IAEFeature
{ {
IFeatureHandler handler();
public AEFeatureHandler feature();
void postInit(); void postInit();
} }
@@ -0,0 +1,36 @@
/*
* 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.core.features;
import java.util.EnumSet;
import appeng.api.util.AEItemDefinition;
public interface IFeatureHandler
{
boolean isFeatureAvailable();
EnumSet<AEFeature> getFeatures();
AEItemDefinition getDefinition();
void register();
}
@@ -0,0 +1,85 @@
/*
* 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.core.features;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import appeng.api.util.AEItemDefinition;
import appeng.util.Platform;
public class ItemDefinition implements AEItemDefinition
{
private final Item item;
private final boolean enabled;
public ItemDefinition( Item item, boolean enabled )
{
this.item = item;
this.enabled = enabled;
}
@Override
public Block block()
{
return null;
}
@Override
public Item item()
{
return this.item;
}
@Override
public Class<? extends TileEntity> entity()
{
return null;
}
@Override
public ItemStack stack( int stackSize )
{
if ( this.enabled )
{
return new ItemStack( this.item );
}
else
{
return null;
}
}
@Override
public boolean sameAsStack( ItemStack comparableItem )
{
return this.enabled && Platform.isSameItemType( comparableItem, this.stack( 1 ) );
}
@Override
public boolean sameAsBlock( IBlockAccess world, int x, int y, int z )
{
return false;
}
}
@@ -0,0 +1,98 @@
/*
* 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.core.features;
import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.item.Item;
import cpw.mods.fml.common.registry.GameRegistry;
import appeng.api.util.AEItemDefinition;
import appeng.core.CreativeTab;
import appeng.core.CreativeTabFacade;
import appeng.items.parts.ItemFacade;
public class ItemFeatureHandler implements IFeatureHandler
{
private final EnumSet<AEFeature> features;
private final Item item;
private final FeatureNameExtractor extractor;
private final boolean enabled;
private final ItemDefinition definition;
public ItemFeatureHandler( EnumSet<AEFeature> features, Item item, IAEFeature featured, Optional<String> subName )
{
this.features = features;
this.item = item;
this.extractor = new FeatureNameExtractor( featured.getClass(), subName );
this.enabled = new FeaturedActiveChecker( features ).get();
this.definition = new ItemDefinition( item, this.enabled );
}
@Override
public boolean isFeatureAvailable()
{
return this.enabled;
}
@Override
public EnumSet<AEFeature> getFeatures()
{
return this.features;
}
@Override
public AEItemDefinition getDefinition()
{
return this.definition;
}
@Override
public void register()
{
String name = this.extractor.get();
this.item.setTextureName( "appliedenergistics2:" + name );
this.item.setUnlocalizedName( /* "item." */"appliedenergistics2." + name );
if ( this.item instanceof ItemFacade )
{
this.item.setCreativeTab( CreativeTabFacade.instance );
}
else
{
this.item.setCreativeTab( CreativeTab.instance );
}
if ( name.equals( "ItemMaterial" ) )
{
name = "ItemMultiMaterial";
}
else if ( name.equals( "ItemPart" ) )
{
name = "ItemMultiPart";
}
GameRegistry.registerItem( this.item, "item." + name );
}
}
@@ -0,0 +1,79 @@
/*
* 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.core.features;
import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.block.BlockStairs;
import cpw.mods.fml.common.registry.GameRegistry;
import appeng.api.util.AEItemDefinition;
import appeng.core.CreativeTab;
public class StairBlockFeatureHandler implements IFeatureHandler
{
private final EnumSet<AEFeature> features;
private final BlockStairs stairs;
private final FeatureNameExtractor extractor;
private final boolean enabled;
private final BlockDefinition definition;
public StairBlockFeatureHandler( EnumSet<AEFeature> features, BlockStairs stairs, Optional<String> subName )
{
this.features = features;
this.stairs = stairs;
this.extractor = new FeatureNameExtractor( stairs.getClass(), subName );
this.enabled = new FeaturedActiveChecker( features ).get();
this.definition = new BlockDefinition( stairs, this.enabled );
}
@Override
public boolean isFeatureAvailable()
{
return this.enabled;
}
@Override
public EnumSet<AEFeature> getFeatures()
{
return this.features;
}
@Override
public AEItemDefinition getDefinition()
{
return this.definition;
}
@Override
public void register()
{
String name = this.extractor.get();
this.stairs.setCreativeTab( CreativeTab.instance );
this.stairs.setBlockName( "appliedenergistics2." + name );
this.stairs.setBlockTextureName( "appliedenergistics2:" + name );
GameRegistry.registerBlock( this.stairs, "tile." + name );
}
}
+34 -30
View File
@@ -22,54 +22,47 @@ package appeng.items;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler; import appeng.core.features.FeatureNameExtractor;
import appeng.core.features.IAEFeature; import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.ItemFeatureHandler;
public class AEBaseItem extends Item implements IAEFeature public class AEBaseItem extends Item implements IAEFeature
{ {
final String featureFullName; private final String fullName;
final String featureSubName; private final Optional<String> subName;
AEFeatureHandler feature; private IFeatureHandler feature;
public AEBaseItem( Class c )
{
this( c, Optional.<String> absent() );
canRepair = false;
}
public AEBaseItem( Class<?> c, Optional<String> subName )
{
this.subName = subName;
this.fullName = new FeatureNameExtractor( c, subName ).get();
}
@Override @Override
public String toString() public String toString()
{ {
return featureFullName; return this.fullName;
} }
@Override @Override
public AEFeatureHandler feature() public IFeatureHandler handler()
{ {
return feature; return this.feature;
}
public void setFeature( EnumSet<AEFeature> f )
{
feature = new AEFeatureHandler( f, this, featureSubName );
}
public AEBaseItem( Class c )
{
this( c, null );
canRepair = false;
}
public AEBaseItem( Class c, String subName )
{
featureSubName = subName;
featureFullName = AEFeatureHandler.getName( c, subName );
}
@Override
public boolean isBookEnchantable( ItemStack itemstack1, ItemStack itemstack2 )
{
return false;
} }
@Override @Override
@@ -78,6 +71,11 @@ public class AEBaseItem extends Item implements IAEFeature
// override! // override!
} }
public void setFeature( EnumSet<AEFeature> f )
{
this.feature = new ItemFeatureHandler( f, this, this, this.subName );
}
@Override @Override
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
public final void addInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation ) public final void addInformation( ItemStack stack, EntityPlayer player, List lines, boolean displayAdditionalInformation )
@@ -85,6 +83,12 @@ public class AEBaseItem extends Item implements IAEFeature
this.addCheckedInformation( stack, player, lines, displayAdditionalInformation ); this.addCheckedInformation( stack, player, lines, displayAdditionalInformation );
} }
@Override
public boolean isBookEnchantable( ItemStack itemstack1, ItemStack itemstack2 )
{
return false;
}
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation ) public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
{ {
super.addInformation( stack, player, lines, displayAdditionalInformation ); super.addInformation( stack, player, lines, displayAdditionalInformation );
@@ -23,6 +23,8 @@ import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@@ -59,13 +61,13 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
final int perType; final int perType;
final double idleDrain; final double idleDrain;
public ItemBasicStorageCell( MaterialType whichCell, int Kilobytes ) public ItemBasicStorageCell( MaterialType whichCell, int kilobytes )
{ {
super( ItemBasicStorageCell.class, Kilobytes + "k" ); super( ItemBasicStorageCell.class, Optional.of( kilobytes + "k" ) );
this.setFeature( EnumSet.of( AEFeature.StorageCells ) ); this.setFeature( EnumSet.of( AEFeature.StorageCells ) );
this.setMaxStackSize( 1 ); this.setMaxStackSize( 1 );
this.totalBytes = Kilobytes * 1024; this.totalBytes = kilobytes * 1024;
this.component = whichCell; this.component = whichCell;
switch ( this.component ) switch ( this.component )
@@ -169,6 +171,18 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
return this.idleDrain; return this.idleDrain;
} }
@Override
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( ItemStack is )
{
return true;
}
@Override @Override
public IInventory getUpgradesInventory( ItemStack is ) public IInventory getUpgradesInventory( ItemStack is )
{ {
@@ -202,15 +216,10 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
} }
@Override @Override
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is ) public ItemStack onItemRightClick( ItemStack stack, World world, EntityPlayer player )
{ {
return GuiText.StorageCells.getUnlocalized(); disassembleDrive( stack, world, player );
} return stack;
@Override
public boolean isEditable( ItemStack is )
{
return true;
} }
private boolean disassembleDrive( ItemStack stack, World world, EntityPlayer player ) private boolean disassembleDrive( ItemStack stack, World world, EntityPlayer player )
@@ -248,28 +257,21 @@ public class ItemBasicStorageCell extends AEBaseItem implements IStorageCell, II
return false; return false;
} }
@Override
public ItemStack onItemRightClick( ItemStack stack, World world, EntityPlayer player )
{
disassembleDrive( stack, world, player );
return stack;
}
@Override @Override
public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
{ {
return disassembleDrive( stack, world, player ); return disassembleDrive( stack, world, player );
} }
@Override
public boolean hasContainerItem( ItemStack stack )
{
return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting );
}
@Override @Override
public ItemStack getContainerItem( ItemStack itemStack ) public ItemStack getContainerItem( ItemStack itemStack )
{ {
return AEApi.instance().materials().materialEmptyStorageCell.stack( 1 ); return AEApi.instance().materials().materialEmptyStorageCell.stack( 1 );
} }
@Override
public boolean hasContainerItem( ItemStack stack )
{
return AEConfig.instance.isFeatureEnabled( AEFeature.enableDisassemblyCrafting );
}
} }
@@ -18,14 +18,18 @@
package appeng.items.storage; package appeng.items.storage;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
import appeng.api.implementations.TransitionResult; import appeng.api.implementations.TransitionResult;
import appeng.api.implementations.items.ISpatialStorageCell; import appeng.api.implementations.items.ISpatialStorageCell;
import appeng.api.util.WorldCoord; import appeng.api.util.WorldCoord;
@@ -38,14 +42,16 @@ import appeng.spatial.StorageHelper;
import appeng.spatial.StorageWorldProvider; import appeng.spatial.StorageWorldProvider;
import appeng.util.Platform; import appeng.util.Platform;
public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorageCell
{ {
final MaterialType component; final MaterialType component;
final int maxRegion; final int maxRegion;
public ItemSpatialStorageCell(MaterialType whichCell, int spatialScale) { public ItemSpatialStorageCell( MaterialType whichCell, int spatialScale )
super( ItemSpatialStorageCell.class, spatialScale + "Cubed" ); {
super( ItemSpatialStorageCell.class, Optional.of( spatialScale + "Cubed" ) );
setFeature( EnumSet.of( AEFeature.SpatialIO ) ); setFeature( EnumSet.of( AEFeature.SpatialIO ) );
setMaxStackSize( 1 ); setMaxStackSize( 1 );
maxRegion = spatialScale; maxRegion = spatialScale;
@@ -97,19 +103,6 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
return null; return null;
} }
private void setStoredSize(ItemStack is, int targetX, int targetY, int targetZ)
{
if ( is.hasTagCompound() )
{
NBTTagCompound c = is.getTagCompound();
int dim = c.getInteger( "StorageDim" );
c.setInteger( "sizeX", targetX );
c.setInteger( "sizeY", targetY );
c.setInteger( "sizeZ", targetZ );
WorldSettings.getInstance().setStoredSize( dim, targetX, targetY, targetZ );
}
}
@Override @Override
public WorldCoord getStoredSize( ItemStack is ) public WorldCoord getStoredSize( ItemStack is )
{ {
@@ -157,16 +150,6 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
return new WorldCoord( 0, 0, 0 ); return new WorldCoord( 0, 0, 0 );
} }
public World createNewWorld(ItemStack is)
{
NBTTagCompound c = Platform.openNbtData( is );
int newDim = DimensionManager.getNextFreeDimId();
c.setInteger( "StorageDim", newDim );
WorldSettings.getInstance().addStorageCellDim( newDim );
DimensionManager.initDimension( newDim );
return DimensionManager.getWorld( newDim );
}
@Override @Override
public TransitionResult doSpatialTransition( ItemStack is, World w, WorldCoord min, WorldCoord max, boolean doTransition ) public TransitionResult doSpatialTransition( ItemStack is, World w, WorldCoord min, WorldCoord max, boolean doTransition )
{ {
@@ -198,4 +181,27 @@ public class ItemSpatialStorageCell extends AEBaseItem implements ISpatialStorag
return new TransitionResult( false, 0 ); return new TransitionResult( false, 0 );
} }
public World createNewWorld( ItemStack is )
{
NBTTagCompound c = Platform.openNbtData( is );
int newDim = DimensionManager.getNextFreeDimId();
c.setInteger( "StorageDim", newDim );
WorldSettings.getInstance().addStorageCellDim( newDim );
DimensionManager.initDimension( newDim );
return DimensionManager.getWorld( newDim );
}
private void setStoredSize( ItemStack is, int targetX, int targetY, int targetZ )
{
if ( is.hasTagCompound() )
{
NBTTagCompound c = is.getTagCompound();
int dim = c.getInteger( "StorageDim" );
c.setInteger( "sizeX", targetX );
c.setInteger( "sizeY", targetY );
c.setInteger( "sizeZ", targetZ );
WorldSettings.getInstance().setStoredSize( dim, targetX, targetY, targetZ );
}
}
} }
@@ -18,8 +18,11 @@
package appeng.items.tools; package appeng.items.tools;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -28,6 +31,9 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.tools.IToolWrench;
import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.items.IAEWrench; import appeng.api.implementations.items.IAEWrench;
@@ -46,14 +52,15 @@ import appeng.items.AEBaseItem;
import appeng.items.contents.NetworkToolViewer; import appeng.items.contents.NetworkToolViewer;
import appeng.transformer.annotations.integration.Interface; import appeng.transformer.annotations.integration.Interface;
import appeng.util.Platform; import appeng.util.Platform;
import buildcraft.api.tools.IToolWrench;
@Interface( iface = "buildcraft.api.tools.IToolWrench", iname = "BC" ) @Interface( iface = "buildcraft.api.tools.IToolWrench", iname = "BC" )
public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench
{ {
public ToolNetworkTool() { public ToolNetworkTool()
super( ToolNetworkTool.class, null ); {
super( ToolNetworkTool.class, Optional.<String> absent() );
this.setFeature( EnumSet.of( AEFeature.NetworkTool ) ); this.setFeature( EnumSet.of( AEFeature.NetworkTool ) );
this.setMaxStackSize( 1 ); this.setMaxStackSize( 1 );
@@ -118,6 +125,12 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench,
return true; return true;
} }
@Override
public boolean doesSneakBypassUse( World world, int x, int y, int z, EntityPlayer player )
{
return true;
}
public boolean serverSideToolLogic( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) public boolean serverSideToolLogic( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
{ {
if ( side >= 0 ) if ( side >= 0 )
@@ -163,12 +176,6 @@ public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench,
return false; return false;
} }
@Override
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player)
{
return true;
}
@Override @Override
public boolean canWrench( ItemStack is, EntityPlayer player, int x, int y, int z ) public boolean canWrench( ItemStack is, EntityPlayer player, int x, int y, int z )
{ {
@@ -18,11 +18,15 @@
package appeng.items.tools.powered; package appeng.items.tools.powered;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.sync.packets.PacketLightning; import appeng.core.sync.packets.PacketLightning;
@@ -30,11 +34,13 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.server.ServerHelper; import appeng.server.ServerHelper;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolChargedStaff extends AEBasePoweredItem public class ToolChargedStaff extends AEBasePoweredItem
{ {
public ToolChargedStaff() { public ToolChargedStaff()
super( ToolChargedStaff.class, null ); {
super( ToolChargedStaff.class, Optional.<String> absent() );
setFeature( EnumSet.of( AEFeature.ChargedStaff, AEFeature.PoweredTools ) ); setFeature( EnumSet.of( AEFeature.ChargedStaff, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.chargedStaffBattery; maxStoredPower = AEConfig.instance.chargedStaffBattery;
} }
@@ -28,6 +28,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.google.common.base.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser; import net.minecraft.block.BlockDispenser;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@@ -97,7 +99,7 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
public ToolColorApplicator() public ToolColorApplicator()
{ {
super( ToolColorApplicator.class, null ); super( ToolColorApplicator.class, Optional.<String> absent() );
setFeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.PoweredTools ) ); setFeature( EnumSet.of( AEFeature.ColorApplicator, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.colorApplicatorBattery; maxStoredPower = AEConfig.instance.colorApplicatorBattery;
if ( Platform.isClient() ) if ( Platform.isClient() )
@@ -111,125 +113,6 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
} }
public ItemStack getColor( ItemStack is )
{
NBTTagCompound c = is.getTagCompound();
if ( c != null && c.hasKey( "color" ) )
{
NBTTagCompound color = c.getCompoundTag( "color" );
ItemStack oldColor = ItemStack.loadItemStackFromNBT( color );
if ( oldColor != null )
return oldColor;
}
return findNextColor( is, null, 0 );
}
public AEColor getColorFromItem( ItemStack paintBall )
{
if ( paintBall == null )
return null;
if ( paintBall.getItem() instanceof ItemSnowball )
return AEColor.Transparent;
if ( paintBall.getItem() instanceof ItemPaintBall )
{
ItemPaintBall ipb = ( ItemPaintBall ) paintBall.getItem();
return ipb.getColor( paintBall );
}
else
{
int[] id = OreDictionary.getOreIDs( paintBall );
for ( int oreID : id )
{
if ( oreToColor.containsKey( oreID ) )
return oreToColor.get( oreID );
}
}
return null;
}
public AEColor getActiveColor( ItemStack tol )
{
return getColorFromItem( getColor( tol ) );
}
private ItemStack findNextColor( ItemStack is, ItemStack anchor, int scrollOffset )
{
ItemStack newColor = null;
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( inv != null )
{
IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
if ( anchor == null )
{
IAEItemStack firstItem = itemList.getFirstItem();
if ( firstItem != null )
newColor = firstItem.getItemStack();
}
else
{
LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>();
for ( IAEItemStack i : itemList )
list.add( i );
Collections.sort( list, new Comparator<IAEItemStack>(){
@Override
public int compare( IAEItemStack a, IAEItemStack b )
{
return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() );
}
} );
if ( list.size() <= 0 )
return null;
IAEItemStack where = list.getFirst();
int cycles = 1 + list.size();
while ( cycles > 0 && !where.equals( anchor ) )
{
list.addLast( list.removeFirst() );
cycles--;
where = list.getFirst();
}
if ( scrollOffset > 0 )
list.addLast( list.removeFirst() );
if ( scrollOffset < 0 )
list.addFirst( list.removeLast() );
return list.get( 0 ).getItemStack();
}
}
if ( newColor != null )
setColor( is, newColor );
return newColor;
}
public void setColor( ItemStack is, ItemStack newColor )
{
NBTTagCompound data = Platform.openNbtData( is );
if ( newColor == null )
data.removeTag( "color" );
else
{
NBTTagCompound color = new NBTTagCompound();
newColor.writeToNBT( color );
data.setTag( "color", color );
}
}
@Override @Override
public boolean onItemUse( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ ) public boolean onItemUse( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
{ {
@@ -309,6 +192,138 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
return false; return false;
} }
@Override
public String getItemStackDisplayName( ItemStack par1ItemStack )
{
String extra = GuiText.Empty.getLocal();
AEColor selected = getActiveColor( par1ItemStack );
if ( selected != null && Platform.isClient() )
extra = Platform.gui_localize( selected.unlocalizedName );
return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra;
}
public AEColor getActiveColor( ItemStack tol )
{
return getColorFromItem( getColor( tol ) );
}
public AEColor getColorFromItem( ItemStack paintBall )
{
if ( paintBall == null )
return null;
if ( paintBall.getItem() instanceof ItemSnowball )
return AEColor.Transparent;
if ( paintBall.getItem() instanceof ItemPaintBall )
{
ItemPaintBall ipb = ( ItemPaintBall ) paintBall.getItem();
return ipb.getColor( paintBall );
}
else
{
int[] id = OreDictionary.getOreIDs( paintBall );
for ( int oreID : id )
{
if ( oreToColor.containsKey( oreID ) )
return oreToColor.get( oreID );
}
}
return null;
}
public ItemStack getColor( ItemStack is )
{
NBTTagCompound c = is.getTagCompound();
if ( c != null && c.hasKey( "color" ) )
{
NBTTagCompound color = c.getCompoundTag( "color" );
ItemStack oldColor = ItemStack.loadItemStackFromNBT( color );
if ( oldColor != null )
return oldColor;
}
return findNextColor( is, null, 0 );
}
private ItemStack findNextColor( ItemStack is, ItemStack anchor, int scrollOffset )
{
ItemStack newColor = null;
IMEInventory<IAEItemStack> inv = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
if ( inv != null )
{
IItemList<IAEItemStack> itemList = inv.getAvailableItems( AEApi.instance().storage().createItemList() );
if ( anchor == null )
{
IAEItemStack firstItem = itemList.getFirstItem();
if ( firstItem != null )
newColor = firstItem.getItemStack();
}
else
{
LinkedList<IAEItemStack> list = new LinkedList<IAEItemStack>();
for ( IAEItemStack i : itemList )
list.add( i );
Collections.sort( list, new Comparator<IAEItemStack>(){
@Override
public int compare( IAEItemStack a, IAEItemStack b )
{
return ItemSorters.compareInt( a.getItemDamage(), b.getItemDamage() );
}
} );
if ( list.size() <= 0 )
return null;
IAEItemStack where = list.getFirst();
int cycles = 1 + list.size();
while ( cycles > 0 && !where.equals( anchor ) )
{
list.addLast( list.removeFirst() );
cycles--;
where = list.getFirst();
}
if ( scrollOffset > 0 )
list.addLast( list.removeFirst() );
if ( scrollOffset < 0 )
list.addFirst( list.removeLast() );
return list.get( 0 ).getItemStack();
}
}
if ( newColor != null )
setColor( is, newColor );
return newColor;
}
public void setColor( ItemStack is, ItemStack newColor )
{
NBTTagCompound data = Platform.openNbtData( is );
if ( newColor == null )
data.removeTag( "color" );
else
{
NBTTagCompound color = new NBTTagCompound();
newColor.writeToNBT( color );
data.setTag( "color", color );
}
}
private boolean recolourBlock( Block blk, ForgeDirection side, World w, int x, int y, int z, ForgeDirection orientation, AEColor newColor, EntityPlayer p ) private boolean recolourBlock( Block blk, ForgeDirection side, World w, int x, int y, int z, ForgeDirection orientation, AEColor newColor, EntityPlayer p )
{ {
if ( blk == Blocks.carpet ) if ( blk == Blocks.carpet )
@@ -376,19 +391,6 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
} }
@Override
public String getItemStackDisplayName( ItemStack par1ItemStack )
{
String extra = GuiText.Empty.getLocal();
AEColor selected = getActiveColor( par1ItemStack );
if ( selected != null && Platform.isClient() )
extra = Platform.gui_localize( selected.unlocalizedName );
return super.getItemStackDisplayName( par1ItemStack ) + " - " + extra;
}
@Override @Override
public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation ) public void addCheckedInformation( ItemStack stack, EntityPlayer player, List<String> lines, boolean displayAdditionalInformation )
{ {
@@ -458,6 +460,24 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
return true; return true;
} }
@Override
public double getIdleDrain()
{
return 0.5;
}
@Override
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( ItemStack is )
{
return true;
}
@Override @Override
public IInventory getUpgradesInventory( ItemStack is ) public IInventory getUpgradesInventory( ItemStack is )
{ {
@@ -484,30 +504,12 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
} }
} }
@Override
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override @Override
public void setFuzzyMode( ItemStack is, FuzzyMode fzMode ) public void setFuzzyMode( ItemStack is, FuzzyMode fzMode )
{ {
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
} }
@Override
public boolean isEditable( ItemStack is )
{
return true;
}
@Override
public double getIdleDrain()
{
return 0.5;
}
@Override @Override
public void onWheel( ItemStack is, boolean up ) public void onWheel( ItemStack is, boolean up )
{ {
@@ -18,11 +18,14 @@
package appeng.items.tools.powered; package appeng.items.tools.powered;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser; import net.minecraft.block.BlockDispenser;
import net.minecraft.block.BlockTNT; import net.minecraft.block.BlockTNT;
@@ -39,6 +42,7 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import appeng.api.util.DimensionalCoord; import appeng.api.util.DimensionalCoord;
import appeng.block.misc.BlockTinyTNT; import appeng.block.misc.BlockTinyTNT;
import appeng.core.AEConfig; import appeng.core.AEConfig;
@@ -49,42 +53,45 @@ import appeng.items.tools.powered.powersink.AEBasePoweredItem;
import appeng.util.InWorldToolOperationResult; import appeng.util.InWorldToolOperationResult;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool
{ {
static class Combo
{
final public Block blk;
final public int meta;
public Combo(Block b, int m) {
blk = b;
meta = m;
}
@Override
public int hashCode()
{
return blk.hashCode() ^ meta;
}
@Override
public boolean equals(Object obj)
{
if ( obj == null )
return false;
if ( getClass() != obj.getClass() )
return false;
Combo other = (Combo) obj;
return blk == other.blk && meta == other.meta;
}
}
static private Hashtable<Combo, InWorldToolOperationResult> heatUp; static private Hashtable<Combo, InWorldToolOperationResult> heatUp;
static private Hashtable<Combo, InWorldToolOperationResult> coolDown; static private Hashtable<Combo, InWorldToolOperationResult> coolDown;
public ToolEntropyManipulator()
{
super( ToolEntropyManipulator.class, Optional.<String> absent() );
setFeature( EnumSet.of( AEFeature.EntropyManipulator, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.entropyManipulatorBattery;
coolDown = new Hashtable<Combo, InWorldToolOperationResult>();
coolDown.put( new Combo( Blocks.stone, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.cobblestone ) ) );
coolDown.put( new Combo( Blocks.stonebrick, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.stonebrick, 1, 2 ) ) );
coolDown.put( new Combo( Blocks.lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
coolDown.put( new Combo( Blocks.flowing_lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
coolDown.put( new Combo( Blocks.grass, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.dirt ) ) );
List<ItemStack> snowBalls = new ArrayList<ItemStack>();
snowBalls.add( new ItemStack( Items.snowball ) );
coolDown.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( null, snowBalls ) );
coolDown.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.ice ) ) );
heatUp = new Hashtable<Combo, InWorldToolOperationResult>();
heatUp.put( new Combo( Blocks.ice, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.water ) ) );
heatUp.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
heatUp.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
heatUp.put( new Combo( Blocks.snow, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.flowing_water ) ) );
}
@Override
public void postInit()
{
super.postInit();
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
}
static public void heat( Block BlockID, int Metadata, World w, int x, int y, int z ) static public void heat( Block BlockID, int Metadata, World w, int x, int y, int z )
{ {
InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) ); InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) );
@@ -109,6 +116,37 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
} }
} }
static class Combo
{
final public Block blk;
final public int meta;
public Combo( Block b, int m )
{
blk = b;
meta = m;
}
@Override
public int hashCode()
{
return blk.hashCode() ^ meta;
}
@Override
public boolean equals( Object obj )
{
if ( obj == null )
return false;
if ( getClass() != obj.getClass() )
return false;
Combo other = ( Combo ) obj;
return blk == other.blk && meta == other.meta;
}
}
static public boolean canHeat( Block BlockID, int Metadata ) static public boolean canHeat( Block BlockID, int Metadata )
{ {
InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) ); InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) );
@@ -157,37 +195,6 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
return r != null; return r != null;
} }
public ToolEntropyManipulator() {
super( ToolEntropyManipulator.class, null );
setFeature( EnumSet.of( AEFeature.EntropyManipulator, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.entropyManipulatorBattery;
coolDown = new Hashtable<Combo, InWorldToolOperationResult>();
coolDown.put( new Combo( Blocks.stone, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.cobblestone ) ) );
coolDown.put( new Combo( Blocks.stonebrick, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.stonebrick, 1, 2 ) ) );
coolDown.put( new Combo( Blocks.lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
coolDown.put( new Combo( Blocks.flowing_lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
coolDown.put( new Combo( Blocks.grass, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.dirt ) ) );
List<ItemStack> snowBalls = new ArrayList<ItemStack>();
snowBalls.add( new ItemStack( Items.snowball ) );
coolDown.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( null, snowBalls ) );
coolDown.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.ice ) ) );
heatUp = new Hashtable<Combo, InWorldToolOperationResult>();
heatUp.put( new Combo( Blocks.ice, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.water ) ) );
heatUp.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
heatUp.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
heatUp.put( new Combo( Blocks.snow, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.flowing_water ) ) );
}
@Override
public void postInit()
{
super.postInit();
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
}
@Override @Override
public boolean hitEntity( ItemStack item, EntityLivingBase target, EntityLivingBase hitter ) public boolean hitEntity( ItemStack item, EntityLivingBase target, EntityLivingBase hitter )
{ {
@@ -18,9 +18,12 @@
package appeng.items.tools.powered; package appeng.items.tools.powered;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser; import net.minecraft.block.BlockDispenser;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -39,6 +42,7 @@ import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
@@ -73,11 +77,13 @@ import appeng.me.storage.CellInventoryHandler;
import appeng.tile.misc.TilePaint; import appeng.tile.misc.TilePaint;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
{ {
public ToolMassCannon() { public ToolMassCannon()
super( ToolMassCannon.class, null ); {
super( ToolMassCannon.class, Optional.<String> absent() );
setFeature( EnumSet.of( AEFeature.MatterCannon, AEFeature.PoweredTools ) ); setFeature( EnumSet.of( AEFeature.MatterCannon, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.matterCannonBattery; maxStoredPower = AEConfig.instance.matterCannonBattery;
} }
@@ -434,23 +440,11 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
} }
@Override @Override
public boolean storableInStorageCell() public boolean isEditable( ItemStack is )
{ {
return true; return true;
} }
@Override
public boolean isStorageCell(ItemStack i)
{
return true;
}
@Override
public double getIdleDrain()
{
return 0.5;
}
@Override @Override
public IInventory getUpgradesInventory( ItemStack is ) public IInventory getUpgradesInventory( ItemStack is )
{ {
@@ -483,12 +477,6 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
} }
@Override
public boolean isEditable(ItemStack is)
{
return true;
}
@Override @Override
public int getBytes( ItemStack cellItem ) public int getBytes( ItemStack cellItem )
{ {
@@ -519,4 +507,22 @@ public class ToolMassCannon extends AEBasePoweredItem implements IStorageCell
return true; return true;
} }
@Override
public boolean storableInStorageCell()
{
return true;
}
@Override
public boolean isStorageCell( ItemStack i )
{
return true;
}
@Override
public double getIdleDrain()
{
return 0.5;
}
} }
@@ -23,6 +23,8 @@ import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -56,7 +58,7 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
{ {
public ToolPortableCell() public ToolPortableCell()
{ {
super( ToolPortableCell.class, null ); super( ToolPortableCell.class, Optional.<String> absent() );
setFeature( EnumSet.of( AEFeature.PortableCell, AEFeature.StorageCells, AEFeature.PoweredTools ) ); setFeature( EnumSet.of( AEFeature.PortableCell, AEFeature.StorageCells, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.portableCellBattery; maxStoredPower = AEConfig.instance.portableCellBattery;
} }
@@ -128,6 +130,18 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
return 0.5; return 0.5;
} }
@Override
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override
public boolean isEditable( ItemStack is )
{
return true;
}
@Override @Override
public IInventory getUpgradesInventory( ItemStack is ) public IInventory getUpgradesInventory( ItemStack is )
{ {
@@ -154,24 +168,12 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
} }
} }
@Override
public String getUnlocalizedGroupName( Set<ItemStack> others, ItemStack is )
{
return GuiText.StorageCells.getUnlocalized();
}
@Override @Override
public void setFuzzyMode( ItemStack is, FuzzyMode fzMode ) public void setFuzzyMode( ItemStack is, FuzzyMode fzMode )
{ {
Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() );
} }
@Override
public boolean isEditable( ItemStack is )
{
return true;
}
@Override @Override
public IGuiItemObject getGuiObject( ItemStack is, World w, int x, int y, int z ) public IGuiItemObject getGuiObject( ItemStack is, World w, int x, int y, int z )
{ {
@@ -18,14 +18,18 @@
package appeng.items.tools.powered; package appeng.items.tools.powered;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import net.minecraft.world.World; import net.minecraft.world.World;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.Settings; import appeng.api.config.Settings;
import appeng.api.config.SortDir; import appeng.api.config.SortDir;
@@ -41,11 +45,13 @@ import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost; import appeng.util.IConfigManagerHost;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler public class ToolWirelessTerminal extends AEBasePoweredItem implements IWirelessTermHandler
{ {
public ToolWirelessTerminal() { public ToolWirelessTerminal()
super( ToolWirelessTerminal.class, null ); {
super( ToolWirelessTerminal.class, Optional.<String> absent() );
setFeature( EnumSet.of( AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools ) ); setFeature( EnumSet.of( AEFeature.WirelessAccessTerminal, AEFeature.PoweredTools ) );
maxStoredPower = AEConfig.instance.wirelessTerminalBattery; maxStoredPower = AEConfig.instance.wirelessTerminalBattery;
} }
@@ -97,21 +103,6 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
return getAECurrentPower( is ) >= amt; return getAECurrentPower( is ) >= amt;
} }
@Override
public String getEncryptionKey(ItemStack item)
{
NBTTagCompound tag = Platform.openNbtData( item );
return tag.getString( "encryptionKey" );
}
@Override
public void setEncryptionKey(ItemStack item, String encKey, String name)
{
NBTTagCompound tag = Platform.openNbtData( item );
tag.setString( "encryptionKey", encKey );
tag.setString( "name", name );
}
@Override @Override
public IConfigManager getConfigManager( final ItemStack target ) public IConfigManager getConfigManager( final ItemStack target )
{ {
@@ -134,4 +125,19 @@ public class ToolWirelessTerminal extends AEBasePoweredItem implements IWireless
return out; return out;
} }
@Override
public String getEncryptionKey( ItemStack item )
{
NBTTagCompound tag = Platform.openNbtData( item );
return tag.getString( "encryptionKey" );
}
@Override
public void setEncryptionKey( ItemStack item, String encKey, String name )
{
NBTTagCompound tag = Platform.openNbtData( item );
tag.setString( "encryptionKey", encKey );
tag.setString( "name", name );
}
} }
@@ -18,11 +18,17 @@
package appeng.items.tools.powered.powersink; package appeng.items.tools.powered.powersink;
import com.google.common.base.Optional;
public class AEBasePoweredItem extends RedstoneFlux public class AEBasePoweredItem extends RedstoneFlux
{ {
public AEBasePoweredItem(Class c, String subName) { public AEBasePoweredItem( Class c, Optional<String> subName )
{
super( c, subName ); super( c, subName );
setMaxStackSize( 1 );
this.setMaxStackSize( 1 );
} }
} }
@@ -18,14 +18,18 @@
package appeng.items.tools.powered.powersink; package appeng.items.tools.powered.powersink;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.PowerUnits; import appeng.api.config.PowerUnits;
import appeng.api.implementations.items.IAEItemPowerStorage; import appeng.api.implementations.items.IAEItemPowerStorage;
@@ -33,17 +37,15 @@ import appeng.core.localization.GuiText;
import appeng.items.AEBaseItem; import appeng.items.AEBaseItem;
import appeng.util.Platform; import appeng.util.Platform;
public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
{ {
private enum batteryOperation final String EnergyVar = "internalCurrentPower";
{
STORAGE, INJECT, EXTRACT
}
public double maxStoredPower = 200000; public double maxStoredPower = 200000;
public AERootPoweredItem(Class c, String subName) { public AERootPoweredItem( Class c, Optional<String> subName )
{
super( c, subName ); super( c, subName );
setMaxDamage( 32 ); setMaxDamage( 32 );
hasSubtypes = false; hasSubtypes = false;
@@ -75,9 +77,15 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
} }
@Override @Override
public boolean isDamaged(ItemStack stack) public void getSubItems( Item id, CreativeTabs tab, List list )
{ {
return true; super.getSubItems( id, tab, list );
ItemStack charged = new ItemStack( this, 1 );
NBTTagCompound tag = Platform.openNbtData( charged );
tag.setDouble( "internalCurrentPower", getAEMaxPower( charged ) );
tag.setDouble( "internalMaxPower", getAEMaxPower( charged ) );
list.add( charged );
} }
@Override @Override
@@ -86,13 +94,54 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
return false; return false;
} }
@Override
public double getDurabilityForDisplay( ItemStack is )
{
return 1 - getAECurrentPower( is ) / getAEMaxPower( is );
}
@Override
public boolean isDamaged( ItemStack stack )
{
return true;
}
@Override @Override
public void setDamage( ItemStack stack, int damage ) public void setDamage( ItemStack stack, int damage )
{ {
} }
final String EnergyVar = "internalCurrentPower"; /**
* inject external
*/
double injectExternalPower( PowerUnits input, ItemStack is, double amount, boolean simulate )
{
if ( simulate )
{
int requiredEU = ( int ) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) );
if ( amount < requiredEU )
return 0;
return amount - requiredEU;
}
else
{
double powerRemainder = injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder );
}
}
@Override
public double injectAEPower( ItemStack is, double amt )
{
return getInternalBattery( is, batteryOperation.INJECT, amt );
}
@Override
public double extractAEPower( ItemStack is, double amt )
{
return getInternalBattery( is, batteryOperation.EXTRACT, amt );
}
private double getInternalBattery( ItemStack is, batteryOperation op, double adjustment ) private double getInternalBattery( ItemStack is, batteryOperation op, double adjustment )
{ {
@@ -129,37 +178,6 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
return currentStorage; return currentStorage;
} }
/**
* inject external
*/
double injectExternalPower(PowerUnits input, ItemStack is, double amount, boolean simulate)
{
if ( simulate )
{
int requiredEU = (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( is ) - getAECurrentPower( is ) );
if ( amount < requiredEU )
return 0;
return amount - requiredEU;
}
else
{
double powerRemainder = injectAEPower( is, PowerUnits.EU.convertTo( PowerUnits.AE, amount ) );
return PowerUnits.AE.convertTo( PowerUnits.EU, powerRemainder );
}
}
@Override
public double injectAEPower(ItemStack is, double amt)
{
return getInternalBattery( is, batteryOperation.INJECT, amt );
}
@Override
public double extractAEPower(ItemStack is, double amt)
{
return getInternalBattery( is, batteryOperation.EXTRACT, amt );
}
@Override @Override
public double getAEMaxPower( ItemStack is ) public double getAEMaxPower( ItemStack is )
{ {
@@ -178,22 +196,9 @@ public class AERootPoweredItem extends AEBaseItem implements IAEItemPowerStorage
return AccessRestriction.WRITE; return AccessRestriction.WRITE;
} }
@Override private enum batteryOperation
public double getDurabilityForDisplay(ItemStack is)
{ {
return 1 - getAECurrentPower( is ) / getAEMaxPower( is ); STORAGE, INJECT, EXTRACT
}
@Override
public void getSubItems(Item id, CreativeTabs tab, List list)
{
super.getSubItems( id, tab, list );
ItemStack charged = new ItemStack( this, 1 );
NBTTagCompound tag = Platform.openNbtData( charged );
tag.setDouble( "internalCurrentPower", getAEMaxPower( charged ) );
tag.setDouble( "internalMaxPower", getAEMaxPower( charged ) );
list.add( charged );
} }
} }
@@ -18,22 +18,29 @@
package appeng.items.tools.powered.powersink; package appeng.items.tools.powered.powersink;
import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem; import com.google.common.base.Optional;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem;
import appeng.api.config.PowerUnits; import appeng.api.config.PowerUnits;
import appeng.transformer.annotations.integration.Interface; import appeng.transformer.annotations.integration.Interface;
import appeng.transformer.annotations.integration.InterfaceList; import appeng.transformer.annotations.integration.InterfaceList;
import appeng.transformer.annotations.integration.Method; import appeng.transformer.annotations.integration.Method;
@InterfaceList( value = { @Interface( iface = "ic2.api.item.ISpecialElectricItem", iname = "IC2" ), @InterfaceList( value = { @Interface( iface = "ic2.api.item.ISpecialElectricItem", iname = "IC2" ),
@Interface( iface = "ic2.api.item.IElectricItemManager", iname = "IC2" ) } ) @Interface( iface = "ic2.api.item.IElectricItemManager", iname = "IC2" ) } )
public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpecialElectricItem
{ {
public IC2(Class c, String subName) { public IC2( Class c, Optional<String> subName )
{
super( c, subName ); super( c, subName );
} }
@@ -18,16 +18,23 @@
package appeng.items.tools.powered.powersink; package appeng.items.tools.powered.powersink;
import com.google.common.base.Optional;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import cofh.api.energy.IEnergyContainerItem;
import appeng.api.config.PowerUnits; import appeng.api.config.PowerUnits;
import appeng.transformer.annotations.integration.Interface; import appeng.transformer.annotations.integration.Interface;
import cofh.api.energy.IEnergyContainerItem;
@Interface( iface = "cofh.api.energy.IEnergyContainerItem", iname = "RFItem" ) @Interface( iface = "cofh.api.energy.IEnergyContainerItem", iname = "RFItem" )
public class RedstoneFlux extends IC2 implements IEnergyContainerItem public class RedstoneFlux extends IC2 implements IEnergyContainerItem
{ {
public RedstoneFlux(Class c, String subName) { public RedstoneFlux( Class c, Optional<String> subName )
{
super( c, subName ); super( c, subName );
} }
@@ -18,36 +18,36 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.item.ItemAxe; import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.core.features.IAEFeature; import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.ItemFeatureHandler;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolQuartzAxe extends ItemAxe implements IAEFeature public class ToolQuartzAxe extends ItemAxe implements IAEFeature
{ {
private final AEFeature type;
private final IFeatureHandler feature;
final AEFeature type; public ToolQuartzAxe( AEFeature Type )
final AEFeatureHandler feature;
@Override
public AEFeatureHandler feature()
{ {
return feature;
}
@Override
public boolean getIsRepairable(ItemStack a, ItemStack b)
{
return Platform.canRepair( type, a, b );
}
public ToolQuartzAxe(AEFeature Type) {
super( ToolMaterial.IRON ); super( ToolMaterial.IRON );
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzAxe ), this, Type.name() ); this.feature = new ItemFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzAxe ), this, this, Optional.of( Type.name() ) );
}
@Override
public IFeatureHandler handler()
{
return this.feature;
} }
@Override @Override
@@ -55,4 +55,10 @@ public class ToolQuartzAxe extends ItemAxe implements IAEFeature
{ {
// override! // override!
} }
@Override
public boolean getIsRepairable( ItemStack a, ItemStack b )
{
return Platform.canRepair( type, a, b );
}
} }
@@ -18,12 +18,16 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.guiobjects.IGuiItem; import appeng.api.implementations.guiobjects.IGuiItem;
import appeng.api.implementations.guiobjects.IGuiItemObject; import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
@@ -32,18 +36,44 @@ import appeng.items.AEBaseItem;
import appeng.items.contents.QuartzKnifeObj; import appeng.items.contents.QuartzKnifeObj;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
{ {
final AEFeature type; final AEFeature type;
public ToolQuartzCuttingKnife(AEFeature Type) { public ToolQuartzCuttingKnife( AEFeature Type )
super( ToolQuartzCuttingKnife.class, Type.name() ); {
super( ToolQuartzCuttingKnife.class, Optional.of( Type.name() ) );
setFeature( EnumSet.of( type = Type, AEFeature.QuartzKnife ) ); setFeature( EnumSet.of( type = Type, AEFeature.QuartzKnife ) );
setMaxDamage( 50 ); setMaxDamage( 50 );
setMaxStackSize( 1 ); setMaxStackSize( 1 );
} }
@Override
public boolean onItemUse( ItemStack is, EntityPlayer p, World w, int x, int y, int z, int s, float hitX, float hitY, float hitZ )
{
if ( Platform.isServer() )
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE );
return true;
}
@Override
public ItemStack onItemRightClick( ItemStack it, World w, EntityPlayer p )
{
if ( Platform.isServer() )
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE );
p.swingItem();
return it;
}
@Override
public boolean doesContainerItemLeaveCraftingGrid( ItemStack par1ItemStack )
{
return false;
}
@Override @Override
public boolean getIsRepairable( ItemStack a, ItemStack b ) public boolean getIsRepairable( ItemStack a, ItemStack b )
{ {
@@ -57,9 +87,10 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
} }
@Override @Override
public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack) public ItemStack getContainerItem( ItemStack itemStack )
{ {
return false; itemStack.setItemDamage( itemStack.getItemDamage() + 1 );
return itemStack;
} }
@Override @Override
@@ -68,30 +99,6 @@ public class ToolQuartzCuttingKnife extends AEBaseItem implements IGuiItem
return true; return true;
} }
@Override
public ItemStack onItemRightClick(ItemStack it, World w, EntityPlayer p)
{
if ( Platform.isServer() )
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE );
p.swingItem();
return it;
}
@Override
public boolean onItemUse(ItemStack is, EntityPlayer p, World w, int x, int y, int z, int s, float hitX, float hitY, float hitZ)
{
if ( Platform.isServer() )
Platform.openGUI( p, null, ForgeDirection.UNKNOWN, GuiBridge.GUI_QUARTZ_KNIFE );
return true;
}
@Override
public ItemStack getContainerItem(ItemStack itemStack)
{
itemStack.setItemDamage( itemStack.getItemDamage() + 1 );
return itemStack;
}
@Override @Override
public IGuiItemObject getGuiObject( ItemStack is, World world, int x, int y, int z ) public IGuiItemObject getGuiObject( ItemStack is, World world, int x, int y, int z )
{ {
@@ -18,36 +18,38 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.core.features.IAEFeature; import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.ItemFeatureHandler;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolQuartzHoe extends ItemHoe implements IAEFeature public class ToolQuartzHoe extends ItemHoe implements IAEFeature
{ {
private final AEFeature feature;
private final IFeatureHandler handler;
final AEFeature type; public ToolQuartzHoe( AEFeature feature )
final AEFeatureHandler feature;
@Override
public AEFeatureHandler feature()
{ {
return feature;
}
@Override
public boolean getIsRepairable(ItemStack a, ItemStack b)
{
return Platform.canRepair( type, a, b );
}
public ToolQuartzHoe(AEFeature Type) {
super( ToolMaterial.IRON ); super( ToolMaterial.IRON );
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzHoe ), this, Type.name() );
this.feature = feature;
this.handler = new ItemFeatureHandler( EnumSet.of( feature, AEFeature.QuartzHoe ), this, this, Optional.of( feature.name() ) );
}
@Override
public IFeatureHandler handler()
{
return handler;
} }
@Override @Override
@@ -55,4 +57,10 @@ public class ToolQuartzHoe extends ItemHoe implements IAEFeature
{ {
// override! // override!
} }
@Override
public boolean getIsRepairable( ItemStack a, ItemStack b )
{
return Platform.canRepair( feature, a, b );
}
} }
@@ -18,36 +18,38 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.core.features.IAEFeature; import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.ItemFeatureHandler;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolQuartzPickaxe extends ItemPickaxe implements IAEFeature public class ToolQuartzPickaxe extends ItemPickaxe implements IAEFeature
{ {
private final AEFeature type;
private final IFeatureHandler feature;
final AEFeature type; public ToolQuartzPickaxe( AEFeature Type )
final AEFeatureHandler feature;
@Override
public AEFeatureHandler feature()
{ {
return feature;
}
@Override
public boolean getIsRepairable(ItemStack a, ItemStack b)
{
return Platform.canRepair( type, a, b );
}
public ToolQuartzPickaxe(AEFeature Type) {
super( ToolMaterial.IRON ); super( ToolMaterial.IRON );
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzPickaxe ), this, Type.name() );
this.type = Type;
this.feature = new ItemFeatureHandler( EnumSet.of( Type, AEFeature.QuartzPickaxe ), this, this, Optional.of( Type.name() ) );
}
@Override
public IFeatureHandler handler()
{
return this.feature;
} }
@Override @Override
@@ -55,4 +57,10 @@ public class ToolQuartzPickaxe extends ItemPickaxe implements IAEFeature
{ {
// override! // override!
} }
@Override
public boolean getIsRepairable( ItemStack a, ItemStack b )
{
return Platform.canRepair( type, a, b );
}
} }
@@ -18,36 +18,37 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.item.ItemSpade; import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.core.features.IAEFeature; import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.ItemFeatureHandler;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolQuartzSpade extends ItemSpade implements IAEFeature public class ToolQuartzSpade extends ItemSpade implements IAEFeature
{ {
private final AEFeature type;
private final IFeatureHandler handler;
final AEFeature type; public ToolQuartzSpade( AEFeature Type )
final AEFeatureHandler feature;
@Override
public AEFeatureHandler feature()
{ {
return feature;
}
@Override
public boolean getIsRepairable(ItemStack a, ItemStack b)
{
return Platform.canRepair( type, a, b );
}
public ToolQuartzSpade(AEFeature Type) {
super( ToolMaterial.IRON ); super( ToolMaterial.IRON );
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSpade ), this, Type.name() );
this.handler = new ItemFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSpade ), this, this, Optional.of( Type.name() ) );
}
@Override
public IFeatureHandler handler()
{
return handler;
} }
@Override @Override
@@ -55,4 +56,10 @@ public class ToolQuartzSpade extends ItemSpade implements IAEFeature
{ {
// override! // override!
} }
@Override
public boolean getIsRepairable( ItemStack a, ItemStack b )
{
return Platform.canRepair( type, a, b );
}
} }
@@ -18,41 +18,47 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword; import net.minecraft.item.ItemSword;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.core.features.IAEFeature; import appeng.core.features.IAEFeature;
import appeng.core.features.IFeatureHandler;
import appeng.core.features.ItemFeatureHandler;
import appeng.util.Platform; import appeng.util.Platform;
public class ToolQuartzSword extends ItemSword implements IAEFeature public class ToolQuartzSword extends ItemSword implements IAEFeature
{ {
private final AEFeature type;
private final IFeatureHandler feature;
final AEFeature type; public ToolQuartzSword( AEFeature Type )
final AEFeatureHandler feature; {
super( ToolMaterial.IRON );
feature = new ItemFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSword ), this, this, Optional.of( Type.name() ) );
}
@Override @Override
public AEFeatureHandler feature() public IFeatureHandler handler()
{ {
return feature; return feature;
} }
@Override
public boolean getIsRepairable(ItemStack a, ItemStack b)
{
return Platform.canRepair( type, a, b );
}
public ToolQuartzSword(AEFeature Type) {
super( ToolMaterial.IRON );
feature = new AEFeatureHandler( EnumSet.of( type = Type, AEFeature.QuartzSword ), this, Type.name() );
}
@Override @Override
public void postInit() public void postInit()
{ {
// override! // override!
} }
@Override
public boolean getIsRepairable( ItemStack a, ItemStack b )
{
return Platform.canRepair( type, a, b );
}
} }
@@ -18,27 +18,34 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import java.util.EnumSet; import java.util.EnumSet;
import com.google.common.base.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.tools.IToolWrench;
import appeng.api.implementations.items.IAEWrench; import appeng.api.implementations.items.IAEWrench;
import appeng.api.util.DimensionalCoord; import appeng.api.util.DimensionalCoord;
import appeng.core.features.AEFeature; import appeng.core.features.AEFeature;
import appeng.items.AEBaseItem; import appeng.items.AEBaseItem;
import appeng.transformer.annotations.integration.Interface; import appeng.transformer.annotations.integration.Interface;
import appeng.util.Platform; import appeng.util.Platform;
import buildcraft.api.tools.IToolWrench;
@Interface( iface = "buildcraft.api.tools.IToolWrench", iname = "BC" ) @Interface( iface = "buildcraft.api.tools.IToolWrench", iname = "BC" )
public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWrench public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWrench
{ {
public ToolQuartzWrench(AEFeature type) { public ToolQuartzWrench( AEFeature type )
super( ToolQuartzWrench.class, type.name() ); {
super( ToolQuartzWrench.class, Optional.of( type.name() ) );
this.setFeature( EnumSet.of( type, AEFeature.QuartzWrench ) ); this.setFeature( EnumSet.of( type, AEFeature.QuartzWrench ) );
this.setMaxStackSize( 1 ); this.setMaxStackSize( 1 );
@@ -0,0 +1,116 @@
/*
* 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.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import com.google.common.base.Optional;
import appeng.core.AELog;
public class ClassInstantiation<T>
{
private final Class<? extends T> template;
private final Object[] args;
public ClassInstantiation( Class<? extends T> template, Object... args )
{
this.template = template;
this.args = args;
}
public Optional<T> get()
{
@SuppressWarnings( "unchecked" )
Constructor<T>[] constructors = ( Constructor<T>[] ) this.template.getConstructors();
for ( Constructor<T> constructor : constructors )
{
Class<?>[] paramTypes = constructor.getParameterTypes();
if ( paramTypes.length == args.length )
{
boolean valid = true;
for ( int idx = 0; idx < paramTypes.length; idx++ )
{
Class<?> cz = args[idx].getClass();
if ( !isClassMatch( paramTypes[idx], cz, args[idx] ) )
valid = false;
}
if ( valid )
{
try
{
return Optional.of( constructor.newInstance( args ) );
}
catch ( InstantiationException e )
{
e.printStackTrace();
}
catch ( IllegalAccessException e )
{
e.printStackTrace();
}
catch ( InvocationTargetException e )
{
e.printStackTrace();
}
break;
}
}
}
return Optional.absent();
}
private boolean isClassMatch( Class<?> expected, Class<?> got, Object value )
{
if ( value == null && !expected.isPrimitive() )
return true;
expected = condense( expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
got = condense( got, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
return expected == got || expected.isAssignableFrom( got );
}
private Class<?> condense( Class<?> expected, Class<?>... wrappers )
{
if ( expected.isPrimitive() )
{
for ( Class clz : wrappers )
{
try
{
if ( expected == clz.getField( "TYPE" ).get( null ) )
return clz;
}
catch ( Throwable t )
{
AELog.error( t );
}
}
}
return expected;
}
}