Re-did DuplicateItems, into Ore Camo Feature, better logic, and better config.

This commit is contained in:
AlgorithmX2
2014-08-02 18:09:41 -05:00
parent 7ccb850037
commit 476d9a478a
15 changed files with 226 additions and 72 deletions
+49 -9
View File
@@ -1,5 +1,6 @@
package appeng.items.materials;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
@@ -37,7 +38,8 @@ import appeng.client.texture.MissingIcon;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.core.features.AEFeatureHandler;
import appeng.core.features.ItemStackSrc;
import appeng.core.features.IStackSrc;
import appeng.core.features.MaterialStackSrc;
import appeng.items.AEBaseItem;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
@@ -134,7 +136,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
}
}
public ItemStackSrc createMaterial(MaterialType mat)
public IStackSrc createMaterial(MaterialType mat)
{
if ( !mat.isRegistered() )
{
@@ -144,19 +146,17 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
if ( enabled )
{
mat.itemInstance = this;
int newMaterialNum = mat.damageValue;
mat.markReady();
ItemStackSrc output = new ItemStackSrc( this, newMaterialNum );
IStackSrc output = mat.stackSrc = new MaterialStackSrc( mat );
if ( dmgToMaterial.get( newMaterialNum ) == null )
dmgToMaterial.put( newMaterialNum, mat );
else
throw new RuntimeException( "Meta Overlap detected." );
if ( mat.getOreName() != null )
OreDictionary.registerOre( mat.getOreName(), output.stack( 1 ) );
return output;
}
@@ -166,9 +166,49 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
throw new RuntimeException( "Cannot create the same material twice..." );
}
public ItemStack getStackByType(MaterialType mt)
public void unduplicate()
{
return new ItemStack( this, 1, mt.damageValue );
for (MaterialType mt : dmgToMaterial.values())
{
if ( mt.getOreName() != null )
{
ItemStack replacement = null;
String names[] = mt.getOreName().split( "," );
for (String name : names)
{
if ( replacement != null )
break;
ArrayList<ItemStack> options = OreDictionary.getOres( name );
if ( options != null && options.size() > 0 )
{
for (ItemStack is : options)
{
if ( is != null && is.getItem() != null )
{
replacement = is.copy();
break;
}
}
}
}
if ( replacement == null || AEConfig.instance.useAEVersion( mt ) )
{
// continue using the AE2 item.
for (String name : names)
OreDictionary.registerOre( name, mt.stack( 1 ) );
}
else
{
mt.itemInstance = replacement.getItem();
mt.damageValue = replacement.getItemDamage();
}
}
}
}
public MaterialType getTypeByStack(ItemStack is)
@@ -364,7 +404,7 @@ public class ItemMultiMaterial extends AEBaseItem implements IStorageComponent,
for (MaterialType mat : types)
{
if ( mat.damageValue >= 0 && mat.isRegistered() )
if ( mat.damageValue >= 0 && mat.isRegistered() && mat.itemInstance == this )
cList.add( new ItemStack( this, 1, mat.damageValue ) );
}
}
+11 -9
View File
@@ -3,11 +3,12 @@ package appeng.items.materials;
import java.util.EnumSet;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.oredict.OreDictionary;
import appeng.core.AppEng;
import appeng.core.features.AEFeature;
import appeng.core.features.MaterialStackSrc;
import appeng.entity.EntityChargedQuartz;
import appeng.entity.EntityIds;
import appeng.entity.EntitySingularity;
@@ -59,7 +60,7 @@ public enum MaterialType
SkyDust(45, AEFeature.Core),
EnderDust(46, AEFeature.QuantumNetworkBridge, "dustEnder", EntitySingularity.class), Singularity(47, AEFeature.QuantumNetworkBridge,
EnderDust(46, AEFeature.QuantumNetworkBridge, "dustEnder,dustEnderPearl", EntitySingularity.class), Singularity(47, AEFeature.QuantumNetworkBridge,
EntitySingularity.class), QESingularity(48, AEFeature.QuantumNetworkBridge, EntitySingularity.class),
BlankPattern(52), CardCrafting(53);
@@ -71,9 +72,15 @@ public enum MaterialType
// IIcon for the material.
@SideOnly(Side.CLIENT)
public IIcon IIcon;
final public int damageValue;
public Item itemInstance;
public int damageValue;
private boolean isRegistered = false;
// stack!
public MaterialStackSrc stackSrc;
MaterialType(int metaValue) {
damageValue = metaValue;
features = EnumSet.of( AEFeature.Core );
@@ -96,9 +103,6 @@ public enum MaterialType
features = EnumSet.of( part );
damageValue = metaValue;
oreName = oreDictionary;
if ( OreDictionary.getOres( oreDictionary ).size() > 0 )
features.add( AEFeature.DuplicateItems );
droppedEntity = c;
EntityRegistry.registerModEntity( droppedEntity, droppedEntity.getSimpleName(), EntityIds.get( droppedEntity ), AppEng.instance, 16, 4, true );
}
@@ -107,13 +111,11 @@ public enum MaterialType
features = EnumSet.of( part );
damageValue = metaValue;
oreName = oreDictionary;
if ( OreDictionary.getOres( oreDictionary ).size() > 0 )
features.add( AEFeature.DuplicateItems );
}
public ItemStack stack(int size)
{
return new ItemStack( ItemMultiMaterial.instance, size, damageValue );
return new ItemStack( itemInstance, size, damageValue );
}
public EnumSet<AEFeature> getFeature()