Materials now share an ItemID, seemed silly other wise.
This commit is contained in:
parent
b94dfb2415
commit
587fb893b4
4 changed files with 232 additions and 15 deletions
|
@ -6,6 +6,7 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import net.minecraft.inventory.ISidedInventory;
|
import net.minecraft.inventory.ISidedInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.WeightedRandomChestContent;
|
import net.minecraft.util.WeightedRandomChestContent;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
import net.minecraftforge.common.ChestGenHooks;
|
import net.minecraftforge.common.ChestGenHooks;
|
||||||
|
@ -61,6 +62,8 @@ 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;
|
||||||
import appeng.core.features.AEFeature;
|
import appeng.core.features.AEFeature;
|
||||||
|
import appeng.core.features.AEFeatureHandler;
|
||||||
|
import appeng.core.features.DamagedItemDefinition;
|
||||||
import appeng.core.features.IAEFeature;
|
import appeng.core.features.IAEFeature;
|
||||||
import appeng.core.features.registries.entries.BasicCellHandler;
|
import appeng.core.features.registries.entries.BasicCellHandler;
|
||||||
import appeng.core.features.registries.entries.CreativeCellHandler;
|
import appeng.core.features.registries.entries.CreativeCellHandler;
|
||||||
|
@ -68,6 +71,7 @@ import appeng.core.localization.GuiText;
|
||||||
import appeng.core.localization.PlayerMessages;
|
import appeng.core.localization.PlayerMessages;
|
||||||
import appeng.core.sync.GuiBridge;
|
import appeng.core.sync.GuiBridge;
|
||||||
import appeng.debug.ToolDebugCard;
|
import appeng.debug.ToolDebugCard;
|
||||||
|
import appeng.debug.ToolReplicatorCard;
|
||||||
import appeng.helpers.AETrading;
|
import appeng.helpers.AETrading;
|
||||||
import appeng.helpers.PartPlacement;
|
import appeng.helpers.PartPlacement;
|
||||||
import appeng.helpers.QuartzWorldGen;
|
import appeng.helpers.QuartzWorldGen;
|
||||||
|
@ -137,13 +141,16 @@ public class Registration
|
||||||
Parts parts = AEApi.instance().parts();
|
Parts parts = AEApi.instance().parts();
|
||||||
Blocks blocks = AEApi.instance().blocks();
|
Blocks blocks = AEApi.instance().blocks();
|
||||||
|
|
||||||
|
AEItemDefinition materialItem = (AEFeatureHandler) addFeature( ItemMaterial.class );
|
||||||
|
|
||||||
Class materialClass = materials.getClass();
|
Class materialClass = materials.getClass();
|
||||||
for (MaterialType mat : MaterialType.values())
|
for (MaterialType mat : MaterialType.values())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Field f = materialClass.getField( "material" + mat.name() );
|
Field f = materialClass.getField( "material" + mat.name() );
|
||||||
f.set( materials, addFeature( ItemMaterial.class, mat ) );
|
ItemStack is = ((ItemMaterial) materialItem.item()).createMaterial( mat );
|
||||||
|
f.set( materials, new DamagedItemDefinition( is ) );
|
||||||
}
|
}
|
||||||
catch (Throwable err)
|
catch (Throwable err)
|
||||||
{
|
{
|
||||||
|
@ -253,6 +260,7 @@ public class Registration
|
||||||
items.itemFacade = addFeature( ItemFacade.class );
|
items.itemFacade = addFeature( ItemFacade.class );
|
||||||
|
|
||||||
addFeature( ToolDebugCard.class );
|
addFeature( ToolDebugCard.class );
|
||||||
|
addFeature( ToolReplicatorCard.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
private AEItemDefinition addFeature(Class c, Object... Args)
|
private AEItemDefinition addFeature(Class c, Object... Args)
|
||||||
|
@ -265,8 +273,24 @@ public class Registration
|
||||||
|
|
||||||
for (Constructor conItem : con)
|
for (Constructor conItem : con)
|
||||||
{
|
{
|
||||||
if ( conItem.getParameterTypes().length == Args.length )
|
Class paramTypes[] = conItem.getParameterTypes();
|
||||||
obj = conItem.newInstance( Args );
|
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 )
|
||||||
|
{
|
||||||
|
obj = conItem.newInstance( Args );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( obj instanceof IAEFeature )
|
if ( obj instanceof IAEFeature )
|
||||||
|
@ -293,6 +317,40 @@ public class Registration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expected;
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(FMLInitializationEvent event)
|
public void Init(FMLInitializationEvent event)
|
||||||
{
|
{
|
||||||
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIEnergySink", IEnergySink.class );
|
AEApi.instance().partHelper().registerNewLayer( "appeng.api.parts.layers.LayerIEnergySink", IEnergySink.class );
|
||||||
|
|
64
core/features/DamagedItemDefinition.java
Normal file
64
core/features/DamagedItemDefinition.java
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
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 appeng.api.util.AEItemDefinition;
|
||||||
|
|
||||||
|
public class DamagedItemDefinition implements AEItemDefinition
|
||||||
|
{
|
||||||
|
|
||||||
|
final Item baseItem;
|
||||||
|
final int damage;
|
||||||
|
|
||||||
|
public DamagedItemDefinition(ItemStack is) {
|
||||||
|
if ( is == null )
|
||||||
|
{
|
||||||
|
baseItem = null;
|
||||||
|
damage = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseItem = is.getItem();
|
||||||
|
damage = is.getItemDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Block block()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item item()
|
||||||
|
{
|
||||||
|
return baseItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends TileEntity> entity()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack stack(int stackSize)
|
||||||
|
{
|
||||||
|
if ( baseItem == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new ItemStack( baseItem, 1, damage );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean sameAs(ItemStack comparableItem)
|
||||||
|
{
|
||||||
|
if ( comparableItem == null )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return comparableItem.getItem() == baseItem && comparableItem.getItemDamage() == damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,37 +1,100 @@
|
||||||
package appeng.items.materials;
|
package appeng.items.materials;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.IconRegister;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
import appeng.api.config.Upgrades;
|
||||||
import appeng.api.implementations.IStorageComponent;
|
import appeng.api.implementations.IStorageComponent;
|
||||||
|
import appeng.api.implementations.IUpgradeModule;
|
||||||
|
import appeng.core.Configuration;
|
||||||
|
import appeng.core.features.AEFeature;
|
||||||
|
import appeng.core.features.AEFeatureHandler;
|
||||||
import appeng.items.AEBaseItem;
|
import appeng.items.AEBaseItem;
|
||||||
|
|
||||||
public class ItemMaterial extends AEBaseItem implements IStorageComponent
|
public class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||||
{
|
{
|
||||||
|
|
||||||
final MaterialType material;
|
private int currentMaterial = 0;
|
||||||
|
private final MaterialType material[] = new MaterialType[MaterialType.values().length];
|
||||||
|
|
||||||
public ItemMaterial(MaterialType type) {
|
public ItemMaterial() {
|
||||||
super( ItemMaterial.class, type.name() );
|
super( ItemMaterial.class );
|
||||||
setfeature( type.getFeature() );
|
setfeature( EnumSet.of( AEFeature.Core ) );
|
||||||
material = type;
|
}
|
||||||
|
|
||||||
if ( type.getOreName() != null )
|
public ItemStack createMaterial(MaterialType mat)
|
||||||
OreDictionary.registerOre( type.getOreName(), this );
|
{
|
||||||
|
if ( mat.damageValue == -1 )
|
||||||
|
{
|
||||||
|
boolean enabled = true;
|
||||||
|
for (AEFeature f : mat.getFeature())
|
||||||
|
enabled = enabled && Configuration.instance.isFeatureEnabled( f );
|
||||||
|
|
||||||
|
if ( enabled )
|
||||||
|
{
|
||||||
|
material[currentMaterial] = mat;
|
||||||
|
mat.damageValue = currentMaterial;
|
||||||
|
ItemStack output = new ItemStack( this );
|
||||||
|
output.setItemDamage( currentMaterial );
|
||||||
|
currentMaterial++;
|
||||||
|
|
||||||
|
if ( mat.getOreName() != null )
|
||||||
|
OreDictionary.registerOre( mat.getOreName(), this );
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new RuntimeException( "Cannot create the same material twice..." );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaterialType getTypeByStack(ItemStack is)
|
||||||
|
{
|
||||||
|
return material[is.getItemDamage()];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getIconFromDamage(int dmg)
|
||||||
|
{
|
||||||
|
return material[dmg].icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnlocalizedName(ItemStack is)
|
||||||
|
{
|
||||||
|
return AEFeatureHandler.getName( ItemMaterial.class, getTypeByStack( is ).name() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerIcons(IconRegister par1IconRegister)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < currentMaterial; x++)
|
||||||
|
{
|
||||||
|
String tex = "appliedenergistics2:" + getUnlocalizedName( new ItemStack( this, 1, x ) );
|
||||||
|
material[x].icon = par1IconRegister.registerIcon( tex );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomEntity(ItemStack is)
|
public boolean hasCustomEntity(ItemStack is)
|
||||||
{
|
{
|
||||||
return material.hasCustomEntity();
|
return getTypeByStack( is ).hasCustomEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entity createEntity(World w, Entity location, ItemStack itemstack)
|
public Entity createEntity(World w, Entity location, ItemStack itemstack)
|
||||||
{
|
{
|
||||||
Class<? extends Entity> droppedEntity = material.getCustomEntityClass();
|
Class<? extends Entity> droppedEntity = getTypeByStack( itemstack ).getCustomEntityClass();
|
||||||
Entity eqi;
|
Entity eqi;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -57,7 +120,7 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent
|
||||||
@Override
|
@Override
|
||||||
public int getBytes(ItemStack is)
|
public int getBytes(ItemStack is)
|
||||||
{
|
{
|
||||||
switch (material)
|
switch (getTypeByStack( is ))
|
||||||
{
|
{
|
||||||
case Cell1kPart:
|
case Cell1kPart:
|
||||||
return 1024;
|
return 1024;
|
||||||
|
@ -75,7 +138,7 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent
|
||||||
@Override
|
@Override
|
||||||
public boolean isStorageComponent(ItemStack is)
|
public boolean isStorageComponent(ItemStack is)
|
||||||
{
|
{
|
||||||
switch (material)
|
switch (getTypeByStack( is ))
|
||||||
{
|
{
|
||||||
case Cell1kPart:
|
case Cell1kPart:
|
||||||
case Cell4kPart:
|
case Cell4kPart:
|
||||||
|
@ -87,4 +150,28 @@ public class ItemMaterial extends AEBaseItem implements IStorageComponent
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Upgrades getType(ItemStack itemstack)
|
||||||
|
{
|
||||||
|
switch (getTypeByStack( itemstack ))
|
||||||
|
{
|
||||||
|
case CardCapacity:
|
||||||
|
return Upgrades.CAPACITY;
|
||||||
|
case CardFuzzy:
|
||||||
|
return Upgrades.FUZZY;
|
||||||
|
case CardRedstone:
|
||||||
|
return Upgrades.REDSTONE;
|
||||||
|
case CardSpeed:
|
||||||
|
return Upgrades.SPEED;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List cList)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < currentMaterial; x++)
|
||||||
|
cList.add( new ItemStack( this, 1, x ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package appeng.items.materials;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import appeng.client.render.entity.EntityIds;
|
import appeng.client.render.entity.EntityIds;
|
||||||
import appeng.core.AppEng;
|
import appeng.core.AppEng;
|
||||||
|
@ -10,6 +11,8 @@ import appeng.core.features.AEFeature;
|
||||||
import appeng.entity.EntityChargedQuartz;
|
import appeng.entity.EntityChargedQuartz;
|
||||||
import appeng.entity.EntitySingularity;
|
import appeng.entity.EntitySingularity;
|
||||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public enum MaterialType
|
public enum MaterialType
|
||||||
{
|
{
|
||||||
|
@ -52,6 +55,11 @@ public enum MaterialType
|
||||||
private EnumSet<AEFeature> features;
|
private EnumSet<AEFeature> features;
|
||||||
private Class<? extends Entity> droppedEntity;
|
private Class<? extends Entity> droppedEntity;
|
||||||
|
|
||||||
|
// icon for the material.
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public Icon icon;
|
||||||
|
public int damageValue = -1;
|
||||||
|
|
||||||
MaterialType() {
|
MaterialType() {
|
||||||
features = EnumSet.of( AEFeature.Core );
|
features = EnumSet.of( AEFeature.Core );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue