Implemented vanilla block recipes for grinder

This commit is contained in:
Robert Seifert 2014-02-25 17:27:30 -05:00
parent 2c9966c632
commit 1291d760c7
3 changed files with 388 additions and 321 deletions

View file

@ -6,6 +6,8 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.api.recipe.RecipeResource.FluidStackResource;
@ -16,7 +18,11 @@ public final class MachineRecipes
{
public static enum RecipeType
{
CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL;
CRUSHER,
GRINDER,
MIXER,
SMELTER,
SAWMILL;
}
private final Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> recipes = new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>();
@ -36,6 +42,12 @@ public final class MachineRecipes
if (obj instanceof String)
return new OreDictResource((String) obj);
if (obj instanceof Block)
return new ItemStackResource(new ItemStack((Block) obj));
if (obj instanceof Item)
return new ItemStackResource(new ItemStack((Item) obj));
if (obj instanceof ItemStack)
return new ItemStackResource((ItemStack) obj);

View file

@ -39,20 +39,14 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Calclavia
*
*/
/** @author Calclavia */
public class ResourceGenerator
{
public static final ResourceGenerator INSTANCE = new ResourceGenerator();
public static final Set<String> oreDictBlackList = new HashSet<String>();
/**
* A list of material names. They are all camelCase reference of ore dictionary names without
* the
* "ore" or "ingot" prefix.
*/
/** A list of material names. They are all camelCase reference of ore dictionary names without
* the "ore" or "ingot" prefix. */
public static final List<String> materialNames = new ArrayList<String>();
public static final HashMap<String, Integer> materialColors = new HashMap<String, Integer>();
private static final HashMap<Icon, Integer> iconColorMap = new HashMap<Icon, Integer>();
@ -93,16 +87,25 @@ public class ResourceGenerator
OreDictionary.registerOre("oreIron", Block.oreIron);
OreDictionary.registerOre("oreLapis", Block.oreLapis);
//Vanilla fluid recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone));
//Vanilla crusher recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.cobblestone, Block.gravel);
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.stone, Block.cobblestone);
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER, Block.chest, new ItemStack(Block.planks, 7, 0));
//Vanilla grinder recipes
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.cobblestone, Block.sand);
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.gravel, Block.sand);
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, Block.glass, Block.sand);
for (String materialName : materialNames)
{
// Caps version of the name
String nameCaps = LanguageUtility.capitalizeFirst(materialName);
/**
* Generate molten fluids
*/
/** Generate molten fluids */
Fluid fluidMolten = new Fluid(materialNameToMolten(materialName));
fluidMolten.setDensity(7);
fluidMolten.setViscosity(5000);
@ -112,9 +115,7 @@ public class ResourceGenerator
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps);
ResonantInduction.blockMoltenFluid.add(blockFluidMaterial);
/**
* Generate dust mixture fluids
*/
/** Generate dust mixture fluids */
Fluid fluidMixture = new Fluid(materialNameToMixture(materialName));
FluidRegistry.registerFluid(fluidMixture);
Block blockFluidMixture = new BlockFluidMixture(fluidMixture);
@ -174,12 +175,10 @@ public class ResourceGenerator
}
}
/**
* Gets the average color of this item.
/** Gets the average color of this item.
*
* @param itemStack
* @return The RGB hexadecimal color code.
*/
* @return The RGB hexadecimal color code. */
@SideOnly(Side.CLIENT)
public static int getAverageColor(ItemStack itemStack)
{
@ -218,9 +217,7 @@ public class ResourceGenerator
{
Color rgb = new Color(bufferedimage.getRGB(x, y));
/**
* Ignore things that are too dark. Standard luma calculation.
*/
/** Ignore things that are too dark. Standard luma calculation. */
double luma = 0.2126 * rgb.getRed() + 0.7152 * rgb.getGreen() + 0.0722 * rgb.getBlue();
if (luma > 40)

View file

@ -1,7 +1,13 @@
package resonantinduction.core.resource.item;
import java.util.List;
import calclavia.lib.utility.LanguageUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import resonantinduction.core.Reference;
import resonantinduction.core.TabRI;
import resonantinduction.core.resource.ResourceGenerator;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -10,42 +16,94 @@ import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.oredict.OreDictionary;
/** Modified version of the MC bucket to meet the needs of a dynamic fluid registry system
*
* @author Darkguardsman */
public class ItemFluidBucket extends ItemBucket
{
private Fluid fluid;
public ItemFluidBucket(int id, Fluid fluid)
public ItemFluidBucket(int id)
{
super(id, fluid.getBlockID());
super(id, 0);
setContainerItem(Item.bucketEmpty);
setUnlocalizedName(Reference.PREFIX + "Bucket_" + fluid.getName());
setTextureName(Reference.PREFIX + "Bucket_" + fluid.getName());
setUnlocalizedName(Reference.PREFIX + "Bucket_Molten");
setTextureName(Reference.PREFIX + "Bucket_Molten");
setCreativeTab(CreativeTabs.tabMisc);
setHasSubtypes(true);
setMaxDamage(0);
}
@Override
public String getItemDisplayName(ItemStack is)
{
String dustName = getMaterialFromStack(is);
if (dustName != null)
{
List<ItemStack> list = OreDictionary.getOres("ingot" + dustName.substring(0, 1).toUpperCase() + dustName.substring(1));
if (list.size() > 0)
{
ItemStack type = list.get(0);
String name = type.getDisplayName().replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "");
return (LanguageUtility.getLocal(this.getUnlocalizedName() + ".name")).replace("%v", name).replace(" ", " ");
}
}
return "";
}
@Override
public ItemStack onItemRightClick(ItemStack bucket, World world, EntityPlayer player)
{
if (fluid == null || Block.blocksList[fluid.getBlockID()] == null)
{
return bucket;
}
return super.onItemRightClick(bucket, world, player);
}
@Override
public boolean tryPlaceContainedLiquid(World par1World, int par2, int par3, int par4)
{
if (fluid == null || Block.blocksList[fluid.getBlockID()] == null)
{
return false;
}
return super.tryPlaceContainedLiquid(par1World, par2, par3, par4);
}
public static String getMaterialFromStack(ItemStack itemStack)
{
if (ResourceGenerator.materialNames.size() > itemStack.getItemDamage())
return ResourceGenerator.materialNames.get(itemStack.getItemDamage());
return null;
}
public ItemStack getStackFromMaterial(String name)
{
ItemStack itemStack = new ItemStack(this);
itemStack.setItemDamage(ResourceGenerator.materialNames.indexOf(name));
return itemStack;
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (String materialName : ResourceGenerator.materialNames)
{
par3List.add(getStackFromMaterial(materialName));
}
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack itemStack, int par2)
{
/**
* Auto-color based on the texture of the ingot.
*/
String name = ItemOreResource.getMaterialFromStack(itemStack);
if (ResourceGenerator.materialColors.containsKey(name))
{
return ResourceGenerator.materialColors.get(name);
}
return 16777215;
}
}