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
+16 -4
View File
@@ -16,6 +16,7 @@ import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.core.features.AEFeature;
import appeng.core.settings.TickRates;
import appeng.items.materials.MaterialType;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
@@ -94,7 +95,7 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo
public String grinderOres[] = {
// Vanilla Items
"Obsidian", "Ender", "Coal", "Iron", "Gold", "Charcoal", "NetherQuartz",
"Obsidian", "Ender", "EnderPearl", "Coal", "Iron", "Gold", "Charcoal", "NetherQuartz",
// Common Mod Ores
"Copper", "Tin", "Silver", "Lead", "Bronze",
// AE
@@ -260,9 +261,6 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo
featureFlags.add( feature );
}
if ( featureFlags.contains( AEFeature.WebsiteRecipes ) )
featureFlags.add( AEFeature.DuplicateItems );
if ( cpw.mods.fml.common.Loader.isModLoaded( "ImmibisMicroblocks" ) )
featureFlags.remove( AEFeature.AlphaPass );
@@ -302,6 +300,20 @@ public class AEConfig extends Configuration implements IConfigureableObject, ICo
updateable = true;
}
public boolean useAEVersion(MaterialType mt)
{
if ( isFeatureEnabled( AEFeature.WebsiteRecipes ) )
return true;
setCategoryComment(
"OreCamouflage",
"AE2 Automatically uses alternative ores present in your instance of MC to blend better with its surroundings, if you prefer you can disable this selectively using these flags; Its important to note, that some if these items even if enabled may not be craftable in game because other items are overriding their recipes." );
Property p = get( "OreCamouflage", mt.name(), true );
p.comment = "OreDictionary Names: " + mt.getOreName();
return !p.getBoolean( true );
}
private String getListComment(Enum value)
{
String comment = null;
+5 -1
View File
@@ -80,6 +80,7 @@ import appeng.core.features.AEFeatureHandler;
import appeng.core.features.ColoredItemDefinition;
import appeng.core.features.DamagedItemDefinition;
import appeng.core.features.IAEFeature;
import appeng.core.features.IStackSrc;
import appeng.core.features.ItemStackSrc;
import appeng.core.features.NullItemDefinition;
import appeng.core.features.WrappedDamageItemDefinition;
@@ -234,7 +235,7 @@ public class Registration
else
{
Field f = materialClass.getField( "material" + mat.name() );
ItemStackSrc is = ((ItemMultiMaterial) materialItem.item()).createMaterial( mat );
IStackSrc is = ((ItemMultiMaterial) materialItem.item()).createMaterial( mat );
if ( is != null )
f.set( materials, new DamagedItemDefinition( is ) );
else
@@ -509,6 +510,9 @@ public class Registration
public void Init(FMLInitializationEvent event)
{
// Perform ore camouflage!
ItemMultiMaterial.instance.unduplicate();
if ( AEConfig.instance.isFeatureEnabled( AEFeature.CustomRecipes ) )
recipeHandler.parseRecipes( new ConfigLoader( AppEng.instance.getConfigPath() ), "index.recipe" );
else
+1 -1
View File
@@ -46,7 +46,7 @@ public enum AEFeature
MassCannonBlockDamage("BlockFeatures"), TinyTNTBlockDamage("BlockFeatures"), Facades("Facades"),
DuplicateItems("Misc", false), Profiler("Services", false), VersionChecker("Services"), UnsupportedDeveloperTools("Misc", false), Creative("Misc"),
Profiler("Services", false), VersionChecker("Services"), UnsupportedDeveloperTools("Misc", false), Creative("Misc"),
GrinderLogging("Misc", false), Logging("Misc"), IntegrationLogging("Misc", false), CustomRecipes("Crafting", false), WebsiteRecipes("Misc", false),
+6 -19
View File
@@ -10,20 +10,10 @@ import appeng.api.util.AEItemDefinition;
public class DamagedItemDefinition implements AEItemDefinition
{
final Item baseItem;
final int damage;
final IStackSrc src;
public DamagedItemDefinition(ItemStackSrc is) {
if ( is == null )
{
baseItem = null;
damage = -1;
}
else
{
baseItem = is.item;
damage = is.damage;
}
public DamagedItemDefinition(IStackSrc is) {
src = is;
}
@Override
@@ -35,7 +25,7 @@ public class DamagedItemDefinition implements AEItemDefinition
@Override
public Item item()
{
return baseItem;
return src.getItem();
}
@Override
@@ -47,10 +37,7 @@ public class DamagedItemDefinition implements AEItemDefinition
@Override
public ItemStack stack(int stackSize)
{
if ( baseItem == null )
return null;
return new ItemStack( baseItem, stackSize, damage );
return src.stack( stackSize );
}
@Override
@@ -59,7 +46,7 @@ public class DamagedItemDefinition implements AEItemDefinition
if ( comparableItem == null )
return false;
return comparableItem.getItem() == baseItem && comparableItem.getItemDamage() == damage;
return comparableItem.getItem() == src.getItem() && comparableItem.getItemDamage() == src.getDamage();
}
@Override
+15
View File
@@ -0,0 +1,15 @@
package appeng.core.features;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public interface IStackSrc
{
ItemStack stack(int i);
Item getItem();
int getDamage();
}
+18 -2
View File
@@ -4,7 +4,7 @@ import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemStackSrc
public class ItemStackSrc implements IStackSrc
{
public final Item item;
@@ -23,11 +23,27 @@ public class ItemStackSrc
damage = dmg;
}
@Override
public ItemStack stack(int i)
{
if ( block != null )
return new ItemStack( block, i, damage );
return new ItemStack( item, i, damage );
if ( item != null )
return new ItemStack( item, i, damage );
return null;
}
@Override
public Item getItem()
{
return item;
}
@Override
public int getDamage()
{
return damage;
}
}
+36
View File
@@ -0,0 +1,36 @@
package appeng.core.features;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import appeng.items.materials.MaterialType;
public class MaterialStackSrc implements IStackSrc
{
MaterialType src;
public MaterialStackSrc(MaterialType src) {
this.src = src;
if ( src == null )
throw new RuntimeException( "Invalid Item Stack" );
}
@Override
public ItemStack stack(int stackSize)
{
return src.stack( stackSize );
}
@Override
public Item getItem()
{
return src.itemInstance;
}
@Override
public int getDamage()
{
return src.damageValue;
}
}
@@ -46,7 +46,9 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener
addIngot( "Iron", new ItemStack( Items.iron_ingot ) );
addOre( "Obsidian", new ItemStack( Blocks.obsidian ) );
addIngot( "Ender", new ItemStack( Items.ender_pearl ) );
addIngot( "EnderPearl", new ItemStack( Items.ender_pearl ) );
addIngot( "Wheat", new ItemStack( Items.wheat ) );
@@ -226,7 +228,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener
@Override
public void oreRegistered(String Name, ItemStack item)
{
if ( Name.startsWith( "ore" ) || Name.startsWith( "crystal" ) || Name.startsWith( "ingot" ) || Name.startsWith( "dust" ) )
if ( Name.startsWith( "ore" ) || Name.startsWith( "crystal" ) || Name.startsWith( "gem" ) || Name.startsWith( "ingot" ) || Name.startsWith( "dust" ) )
{
for (String ore : AEConfig.instance.grinderOres)
{
@@ -234,11 +236,7 @@ public class GrinderRecipeManager implements IGrinderRegistry, IOreListener
{
addOre( ore, item );
}
else if ( Name.equals( "crystal" + ore ) )
{
addIngot( ore, item );
}
else if ( Name.equals( "ingot" + ore ) )
else if ( Name.equals( "crystal" + ore ) || Name.equals( "ingot" + ore ) || Name.equals( "gem" + ore ) )
{
addIngot( ore, item );
}
@@ -55,9 +55,12 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
{
if ( (irecipe instanceof ShapedRecipe) )
{
CachedShapedRecipe recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe );
recipe.computeVisuals();
arecipes.add( recipe );
if ( ((ShapedRecipe) irecipe).isEnabled() )
{
CachedShapedRecipe recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe );
recipe.computeVisuals();
arecipes.add( recipe );
}
}
}
}
@@ -74,7 +77,7 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
{
if ( (irecipe instanceof ShapedRecipe) )
{
if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.getRecipeOutput(), result ) )
if ( ((ShapedRecipe) irecipe).isEnabled() && NEIServerUtils.areStacksSameTypeCrafting( irecipe.getRecipeOutput(), result ) )
{
CachedShapedRecipe recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe );
recipe.computeVisuals();
@@ -93,7 +96,7 @@ public class NEIAEShapedRecipeHandler extends TemplateRecipeHandler
{
CachedShapedRecipe recipe = new CachedShapedRecipe( (ShapedRecipe) irecipe );
if ( recipe.contains( recipe.ingredients, ingredient.getItem() ) )
if ( ((ShapedRecipe) irecipe).isEnabled() && recipe.contains( recipe.ingredients, ingredient.getItem() ) )
{
recipe.computeVisuals();
if ( recipe.contains( recipe.ingredients, ingredient ) )
@@ -55,9 +55,12 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
{
if ( (irecipe instanceof ShapelessRecipe) )
{
CachedShapelessRecipe recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe );
recipe.computeVisuals();
this.arecipes.add( recipe );
if ( ((ShapelessRecipe) irecipe).isEnabled() )
{
CachedShapelessRecipe recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe );
recipe.computeVisuals();
this.arecipes.add( recipe );
}
}
}
}
@@ -74,7 +77,7 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
{
if ( (irecipe instanceof ShapelessRecipe) )
{
if ( NEIServerUtils.areStacksSameTypeCrafting( irecipe.getRecipeOutput(), result ) )
if ( ((ShapelessRecipe) irecipe).isEnabled() && NEIServerUtils.areStacksSameTypeCrafting( irecipe.getRecipeOutput(), result ) )
{
CachedShapelessRecipe recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe );
recipe.computeVisuals();
@@ -93,7 +96,7 @@ public class NEIAEShapelessRecipeHandler extends TemplateRecipeHandler
{
CachedShapelessRecipe recipe = new CachedShapelessRecipe( (ShapelessRecipe) irecipe );
if ( recipe.contains( recipe.ingredients, ingredient.getItem() ) )
if ( ((ShapelessRecipe) irecipe).isEnabled() && recipe.contains( recipe.ingredients, ingredient.getItem() ) )
{
recipe.computeVisuals();
if ( recipe.contains( recipe.ingredients, ingredient ) )
+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()
+2 -1
View File
@@ -8,6 +8,7 @@ import appeng.api.recipes.ResolverResultSet;
import appeng.api.util.AEColor;
import appeng.api.util.AEColoredItemDefinition;
import appeng.core.AppEng;
import appeng.items.materials.ItemMultiMaterial;
import appeng.items.materials.MaterialType;
import appeng.items.misc.ItemCrystalSeed;
import appeng.items.parts.ItemMultiPart;
@@ -89,7 +90,7 @@ public class AEItemResolver implements ISubItemResolver
String materialName = itemName.substring( itemName.indexOf( "." ) + 1 );
MaterialType mt = MaterialType.valueOf( materialName );
// itemName = itemName.substring( 0, itemName.indexOf( "." ) );
if ( mt.damageValue >= 0 && mt.isRegistered() )
if ( mt.itemInstance == ItemMultiMaterial.instance && mt.damageValue >= 0 && mt.isRegistered() )
return new ResolverResult( "ItemMultiMaterial", mt.damageValue );
}
+26 -6
View File
@@ -24,6 +24,12 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
private int width = 0;
private int height = 0;
private boolean mirrored = true;
private boolean disable = false;
public boolean isEnabled()
{
return !disable;
}
public ShapedRecipe(ItemStack result, Object... recipe) {
output = result.copy();
@@ -130,6 +136,9 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
@Override
public boolean matches(InventoryCrafting inv, World world)
{
if ( disable )
return false;
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++)
{
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y)
@@ -152,6 +161,9 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
@SuppressWarnings("unchecked")
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
if ( disable )
return false;
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++)
{
for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++)
@@ -180,14 +192,14 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
try
{
for (ItemStack item : ((IIngredient) target).getItemStackSet() )
for (ItemStack item : ((IIngredient) target).getItemStackSet())
{
matched = matched || checkItemEquals( item, slot );
}
}
catch (RegistrationError e)
{
// :P
// :P
}
catch (MissingIngredientError e)
{
@@ -266,12 +278,20 @@ public class ShapedRecipe implements IRecipe, IRecipeBakeable
}
@Override
public void bake() throws RegistrationError, MissingIngredientError
public void bake() throws RegistrationError
{
for ( Object o : getInput() )
try
{
if ( o instanceof IIngredient )
((IIngredient)o).bake();
disable = false;
for (Object o : getInput())
{
if ( o instanceof IIngredient )
((IIngredient) o).bake();
}
}
catch (MissingIngredientError err)
{
disable = true;
}
}
+21 -4
View File
@@ -17,6 +17,12 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
private ItemStack output = null;
private ArrayList<Object> input = new ArrayList<Object>();
private boolean disable = false;
public boolean isEnabled()
{
return !disable;
}
public ShapelessRecipe(ItemStack result, Object... recipe) {
output = result.copy();
@@ -61,6 +67,9 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
@Override
public boolean matches(InventoryCrafting var1, World world)
{
if ( disable )
return false;
ArrayList<Object> required = new ArrayList<Object>( input );
for (int x = 0; x < var1.getSizeInventory(); x++)
@@ -82,7 +91,7 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
{
try
{
for (ItemStack item : ((IIngredient) next).getItemStackSet() )
for (ItemStack item : ((IIngredient) next).getItemStackSet())
{
match = match || checkItemEquals( item, slot );
}
@@ -135,10 +144,18 @@ public class ShapelessRecipe implements IRecipe, IRecipeBakeable
@Override
public void bake() throws RegistrationError, MissingIngredientError
{
for ( Object o : getInput() )
try
{
if ( o instanceof IIngredient )
((IIngredient)o).bake();
disable = false;
for (Object o : getInput())
{
if ( o instanceof IIngredient )
((IIngredient) o).bake();
}
}
catch (MissingIngredientError e)
{
disable = true;
}
}
}