From 474fb6d529bba1ce5f5baadc45b41f2ecab52896 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 5 Jan 2014 15:35:42 +0800 Subject: [PATCH] Added grinder wheel --- .../java/resonantinduction/ClientProxy.java | 2 +- .../resonantinduction/ResonantInduction.java | 6 +- .../machine/grinder/BlockGrinderWheel.java | 26 ++++++++ .../{crusher => grinder}/ItemDust.java | 2 +- .../machine/grinder/TileGrinderWheel.java | 60 +++++++++++++++++++ .../languages/en_US.properties | 1 + 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java rename src/main/java/resonantinduction/machine/{crusher => grinder}/ItemDust.java (99%) create mode 100644 src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java diff --git a/src/main/java/resonantinduction/ClientProxy.java b/src/main/java/resonantinduction/ClientProxy.java index 10c884e5b..81218e318 100644 --- a/src/main/java/resonantinduction/ClientProxy.java +++ b/src/main/java/resonantinduction/ClientProxy.java @@ -8,7 +8,7 @@ import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; import resonantinduction.core.render.BlockRenderingHandler; import resonantinduction.core.render.RenderRIItem; -import resonantinduction.machine.crusher.ItemDust; +import resonantinduction.machine.grinder.ItemDust; import resonantinduction.transport.battery.RenderBattery; import resonantinduction.transport.battery.TileBattery; import resonantinduction.transport.fx.FXElectricBolt; diff --git a/src/main/java/resonantinduction/ResonantInduction.java b/src/main/java/resonantinduction/ResonantInduction.java index 09a9cce82..b23ad5791 100644 --- a/src/main/java/resonantinduction/ResonantInduction.java +++ b/src/main/java/resonantinduction/ResonantInduction.java @@ -27,9 +27,10 @@ import org.modstats.ModstatInfo; import org.modstats.Modstats; import resonantinduction.machine.BlockMachinePart; -import resonantinduction.machine.crusher.ItemDust; import resonantinduction.machine.furnace.BlockAdvancedFurnace; import resonantinduction.machine.furnace.TileAdvancedFurnace; +import resonantinduction.machine.grinder.BlockGrinderWheel; +import resonantinduction.machine.grinder.ItemDust; import resonantinduction.machine.liquid.BlockFluidMixture; import resonantinduction.machine.liquid.TileFluidMixture; import resonantinduction.transport.battery.BlockBattery; @@ -164,7 +165,7 @@ public class ResonantInduction // Blocks public static Block blockTesla, blockEMContractor, blockBattery, blockAdvancedFurnace, - blockMachinePart, blockFluidMixture; + blockMachinePart, blockGrinderWheel, blockFluidMixture; public static Fluid MIXTURE; @@ -208,6 +209,7 @@ public class ResonantInduction blockEMContractor = new BlockLevitator(getNextBlockID()); blockBattery = new BlockBattery(getNextBlockID()); blockMachinePart = new BlockMachinePart(getNextBlockID()); + blockGrinderWheel = new BlockGrinderWheel(getNextBlockID()); MIXTURE = new Fluid("mixture"); FluidRegistry.registerFluid(MIXTURE); diff --git a/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java new file mode 100644 index 000000000..1aadee6be --- /dev/null +++ b/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java @@ -0,0 +1,26 @@ +package resonantinduction.machine.grinder; + +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import resonantinduction.core.base.BlockBase; + +/** + * A block used to build machines. + * + * @author Calclavia + * + */ +public class BlockGrinderWheel extends BlockBase implements ITileEntityProvider +{ + public BlockGrinderWheel(int id) + { + super("grindingWheel", id); + } + + @Override + public TileEntity createNewTileEntity(World world) + { + return new TileGrinderWheel(); + } +} diff --git a/src/main/java/resonantinduction/machine/crusher/ItemDust.java b/src/main/java/resonantinduction/machine/grinder/ItemDust.java similarity index 99% rename from src/main/java/resonantinduction/machine/crusher/ItemDust.java rename to src/main/java/resonantinduction/machine/grinder/ItemDust.java index 0d6cb0ee4..101020fa0 100644 --- a/src/main/java/resonantinduction/machine/crusher/ItemDust.java +++ b/src/main/java/resonantinduction/machine/grinder/ItemDust.java @@ -1,4 +1,4 @@ -package resonantinduction.machine.crusher; +package resonantinduction.machine.grinder; import java.awt.Color; import java.awt.image.BufferedImage; diff --git a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java new file mode 100644 index 000000000..b57cec35c --- /dev/null +++ b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java @@ -0,0 +1,60 @@ +package resonantinduction.machine.grinder; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import resonantinduction.api.MachineRecipes; +import resonantinduction.api.MachineRecipes.RecipeType; +import resonantinduction.api.RecipeUtils.ItemStackResource; +import resonantinduction.api.RecipeUtils.Resource; +import calclavia.lib.prefab.tile.TileElectrical; + +/** + * @author Calclavia + * + */ +public class TileGrinderWheel extends TileElectrical +{ + /** A map of ItemStacks and their remaining grind-time left. */ + public static final HashMap map = new HashMap(); + + public void doWork() + { + Iterator> it = map.entrySet().iterator(); + + while (it.hasNext()) + { + Entry entry = it.next(); + entry.setValue(entry.getValue() - 1); + + if (entry.getValue() <= 0) + { + this.doGrind(entry.getKey()); + } + } + } + + private boolean canGrind(ItemStack itemStack) + { + return MachineRecipes.INSTANCE.getRecipes(RecipeType.GRINDER).containsKey(itemStack); + } + + private void doGrind(EntityItem entity) + { + ItemStack itemStack = entity.getEntityItem(); + + List results = MachineRecipes.INSTANCE.getRecipes(RecipeType.GRINDER).get(itemStack); + + for (Resource resource : results) + { + if (resource instanceof ItemStackResource) + { + entity.setEntityItemStack(((ItemStackResource) resource).itemStack); + } + } + } +} diff --git a/src/main/resources/assets/resonantinduction/languages/en_US.properties b/src/main/resources/assets/resonantinduction/languages/en_US.properties index 781481d67..a6a3c49dd 100644 --- a/src/main/resources/assets/resonantinduction/languages/en_US.properties +++ b/src/main/resources/assets/resonantinduction/languages/en_US.properties @@ -14,6 +14,7 @@ tile.resonantinduction\:tesla.name=Tesla Coil tile.resonantinduction\:contractor.name=Electromagnetic Levitator tile.resonantinduction\:battery.name=Battery tile.resonantinduction\:machinePart.name=Machine Part +tile.resonantinduction\:grindingWheel.name=Grinding Wheel tile.resonantinduction\:filter.name=Filter ## Items