Refactored RecipeUtils to RecipeResource

This commit is contained in:
Calclavia 2014-02-04 22:52:42 +08:00
parent e04b1d1004
commit 5ac68f9a8d
18 changed files with 62 additions and 125 deletions

View file

@ -7,9 +7,8 @@ import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import resonantinduction.api.recipe.RecipeUtils.ItemStackResource;
import resonantinduction.api.recipe.RecipeUtils.OreDictResource;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.api.recipe.RecipeResource.ItemStackResource;
import resonantinduction.api.recipe.RecipeResource.OreDictResource;
public final class MachineRecipes
{
@ -18,7 +17,7 @@ public final class MachineRecipes
CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL;
}
private final Map<RecipeType, Map<Resource[], Resource[]>> recipes = new HashMap<RecipeType, Map<Resource[], Resource[]>>();
private final Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> recipes = new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>();
public static final MachineRecipes INSTANCE = new MachineRecipes();
@ -26,11 +25,11 @@ public final class MachineRecipes
{
for (RecipeType machine : RecipeType.values())
{
this.recipes.put(machine, new HashMap<Resource[], Resource[]>());
this.recipes.put(machine, new HashMap<RecipeResource[], RecipeResource[]>());
}
}
public void addRecipe(RecipeType machine, Resource[] input, Resource[] output)
public void addRecipe(RecipeType machine, RecipeResource[] input, RecipeResource[] output)
{
this.recipes.get(machine).put(input, output);
}
@ -62,28 +61,28 @@ public final class MachineRecipes
this.addRecipe(machine, new OreDictResource[] { new OreDictResource(input) }, output);
}
public void removeRecipe(RecipeType machine, Resource[] input)
public void removeRecipe(RecipeType machine, RecipeResource[] input)
{
this.recipes.get(machine).remove(input);
}
public Map<Resource[], Resource[]> getRecipes(RecipeType machine)
public Map<RecipeResource[], RecipeResource[]> getRecipes(RecipeType machine)
{
return new HashMap<Resource[], Resource[]>(this.recipes.get(machine));
return new HashMap<RecipeResource[], RecipeResource[]>(this.recipes.get(machine));
}
public Map<RecipeType, Map<Resource[], Resource[]>> getRecipes()
public Map<RecipeType, Map<RecipeResource[], RecipeResource[]>> getRecipes()
{
return new HashMap<RecipeType, Map<Resource[], Resource[]>>(this.recipes);
return new HashMap<RecipeType, Map<RecipeResource[], RecipeResource[]>>(this.recipes);
}
public Resource[] getOutput(RecipeType machine, Resource... input)
public RecipeResource[] getOutput(RecipeType machine, RecipeResource... input)
{
Iterator<Entry<Resource[], Resource[]>> it = this.getRecipes(machine).entrySet().iterator();
Iterator<Entry<RecipeResource[], RecipeResource[]>> it = this.getRecipes(machine).entrySet().iterator();
while (it.hasNext())
{
Entry<Resource[], Resource[]> entry = it.next();
Entry<RecipeResource[], RecipeResource[]> entry = it.next();
if (Arrays.equals(entry.getKey(), input))
{
@ -91,12 +90,12 @@ public final class MachineRecipes
}
}
return new Resource[] {};
return new RecipeResource[] {};
}
public Resource[] getOutput(RecipeType machine, ItemStack... inputs)
public RecipeResource[] getOutput(RecipeType machine, ItemStack... inputs)
{
Resource[] resourceInputs = new Resource[inputs.length];
RecipeResource[] resourceInputs = new RecipeResource[inputs.length];
for (int i = 0; i < inputs.length; i++)
{
@ -106,9 +105,9 @@ public final class MachineRecipes
return this.getOutput(machine, resourceInputs);
}
public Resource[] getOutput(RecipeType machine, String... oreDictNames)
public RecipeResource[] getOutput(RecipeType machine, String... oreDictNames)
{
Resource[] resourceInputs = new Resource[oreDictNames.length];
RecipeResource[] resourceInputs = new RecipeResource[oreDictNames.length];
for (int i = 0; i < oreDictNames.length; i++)
{

View file

@ -4,39 +4,36 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipeUtils
public abstract class RecipeResource
{
public static abstract class Resource
public final boolean hasChance;
public final float chance;
protected RecipeResource()
{
public final boolean hasChance;
public final float chance;
protected Resource()
{
this.hasChance = false;
this.chance = 100;
}
protected Resource(float chance)
{
this.hasChance = true;
this.chance = chance;
}
public boolean hasChance()
{
return this.hasChance;
}
public float getChance()
{
return this.chance;
}
public abstract ItemStack getItemStack();
this.hasChance = false;
this.chance = 100;
}
public static class ItemStackResource extends Resource
protected RecipeResource(float chance)
{
this.hasChance = true;
this.chance = chance;
}
public boolean hasChance()
{
return this.hasChance;
}
public float getChance()
{
return this.chance;
}
public abstract ItemStack getItemStack();
public static class ItemStackResource extends RecipeResource
{
public final ItemStack itemStack;
@ -70,7 +67,7 @@ public class RecipeUtils
}
}
public static class OreDictResource extends Resource
public static class OreDictResource extends RecipeResource
{
public final String name;
@ -114,7 +111,7 @@ public class RecipeUtils
}
}
public static class FluidStackResource extends Resource
public static class FluidStackResource extends RecipeResource
{
public final FluidStack fluidStack;

View file

@ -7,7 +7,7 @@ import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.core.Reference;
import resonantinduction.core.prefab.item.ItemRI;
import universalelectricity.api.vector.Vector3;
@ -40,9 +40,9 @@ public class ItemHammer extends ItemRI
{
if (!world.isRemote && world.rand.nextFloat() < 0.04)
{
Resource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER, oreName);
RecipeResource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER, oreName);
for (Resource resource : outputs)
for (RecipeResource resource : outputs)
{
ItemStack outputStack = resource.getItemStack().copy();

View file

@ -1,7 +1,5 @@
package resonantinduction.archaic.firebox;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -24,7 +22,6 @@ import resonantinduction.core.resource.TileMaterial;
import universalelectricity.api.energy.EnergyStorageHandler;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.IPacketSender;
import calclavia.lib.network.Synced;
import calclavia.lib.prefab.tile.TileElectricalInventory;
import calclavia.lib.thermal.BoilEvent;

View file

@ -6,7 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.core.ResonantInduction;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.network.IPacketReceiver;
@ -29,13 +29,13 @@ public class TileMillstone extends TileExternalInventory implements IPacketRecei
public void doGrind(Vector3 spawnPos)
{
Resource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER, getStackInSlot(0));
RecipeResource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER, getStackInSlot(0));
if (outputs.length > 0)
{
if (++grindCount > 20)
{
for (Resource res : outputs)
for (RecipeResource res : outputs)
{
InventoryUtility.dropItemStack(worldObj, spawnPos, res.getItemStack().copy());
}

View file

@ -1,15 +1,11 @@
package resonantinduction.core;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;
import net.minecraft.block.Block;
import net.minecraft.util.Icon;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.fluids.Fluid;
import org.modstats.ModstatInfo;
@ -41,8 +37,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* The core module of Resonant Induction

View file

@ -3,14 +3,9 @@ package resonantinduction.core.prefab.part;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.IconTransformation;
import codechicken.lib.render.RenderUtils;
import codechicken.lib.vec.Translation;
import codechicken.multipart.IRedstonePart;
import codechicken.multipart.TMultiPart;

View file

@ -11,10 +11,8 @@ import java.util.Set;
import javax.imageio.ImageIO;
import calclavia.lib.utility.LanguageUtility;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.Language;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
@ -33,6 +31,7 @@ import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.resource.fluid.BlockFluidMaterial;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import calclavia.lib.utility.LanguageUtility;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

View file

@ -1,9 +1,7 @@
package resonantinduction.core.resource.fluid;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;

View file

@ -3,23 +3,14 @@ package resonantinduction.core.resource.fluid;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.TileMaterial;
import calclavia.lib.network.IPacketReceiver;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* NO-OP. Not yet properly implemented. We're not using TEs for now.

View file

@ -11,7 +11,7 @@ import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.prefab.item.ItemRI;
import resonantinduction.core.resource.ResourceGenerator;
@ -147,7 +147,7 @@ public class ItemOreResource extends ItemRI
/**
* Manually wash dust into refined dust.
*/
Resource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, stack);
RecipeResource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, stack);
if (outputs.length > 0)
{
@ -161,7 +161,7 @@ public class ItemOreResource extends ItemRI
{
if (world.rand.nextFloat() > 0.9)
{
for (Resource res : outputs)
for (RecipeResource res : outputs)
{
InventoryUtility.dropItemStack(world, new Vector3(player), res.getItemStack().copy(), 0);
}

View file

@ -1,10 +1,7 @@
package resonantinduction.electrical.armbot;
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -13,16 +10,12 @@ import net.minecraft.world.World;
import resonantinduction.core.prefab.block.BlockRI;
import resonantinduction.core.render.RIBlockRenderingHandler;
import calclavia.components.CalclaviaLoader;
import calclavia.lib.content.IBlockInfo;
import calclavia.lib.multiblock.fake.IBlockActivate;
import calclavia.lib.multiblock.fake.IMultiBlock;
import com.builtbroken.common.Pair;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockArmbot extends BlockRI implements IBlockInfo
public class BlockArmbot extends BlockRI
{
public BlockArmbot()
{
@ -86,19 +79,6 @@ public class BlockArmbot extends BlockRI implements IBlockInfo
return 0;
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
list.add(new Pair("ALArmbot", TileArmbot.class));
}
@Override
@SideOnly(Side.CLIENT)
public void getClientTileEntityRenderers(List<Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>> list)
{
list.add(new Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>(TileArmbot.class, new RenderArmbot()));
}
@Override
public TileEntity createNewTileEntity(World var1)
{

View file

@ -11,7 +11,6 @@ import org.lwjgl.opengl.GL11;
import resonantinduction.archaic.Archaic;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.handler.TextureHookHandler;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;

View file

@ -1,8 +1,5 @@
package resonantinduction.mechanical.fluid.pipe;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

View file

@ -4,17 +4,13 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.core.ResonantInduction;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.core.prefab.block.BlockRI;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import resonantinduction.core.resource.fluid.TileFluidMixture;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.LanguageUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
@ -67,7 +63,7 @@ public class BlockFilter extends BlockRI implements ITileEntityProvider
/**
* Drop item from fluid.
*/
for (Resource resoure : MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, "dust" + LanguageUtility.capitalizeFirst(fluidBlock.getFluid().getName().replace("mixture", ""))))
for (RecipeResource resoure : MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER, "dust" + LanguageUtility.capitalizeFirst(fluidBlock.getFluid().getName().replace("mixture", ""))))
{
InventoryUtility.dropItemStack(world, checkAbove.clone().add(0.5), resoure.getItemStack().copy());
}

View file

@ -9,7 +9,7 @@ import org.apache.commons.lang3.ArrayUtils;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeUtils.Resource;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.network.TileMechanical;
@ -125,9 +125,9 @@ public class TileGrinderWheel extends TileMechanical implements IRotatable
ItemStack itemStack = entity.getEntityItem();
// TODO: Remove this later on when crusher if complete.
Resource[] results = ArrayUtils.addAll(MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER, itemStack), MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER, itemStack));
RecipeResource[] results = ArrayUtils.addAll(MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER, itemStack), MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER, itemStack));
for (Resource resource : results)
for (RecipeResource resource : results)
{
ItemStack outputStack = resource.getItemStack();

View file

@ -8,7 +8,6 @@ import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.recipe.MachineRecipes;
@ -16,7 +15,6 @@ import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import resonantinduction.core.resource.fluid.TileFluidMixture;
import resonantinduction.mechanical.network.TileMechanical;
import universalelectricity.api.vector.Vector3;

View file

@ -4,9 +4,6 @@ import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.BiomeGenOcean;
import net.minecraft.world.biome.BiomeGenPlains;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.ResonantInduction;
import resonantinduction.mechanical.gear.PartGearShaft;