From d9a251905df0cbd13585398c751fa572f09e288f Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 5 Jan 2014 18:57:49 +0800 Subject: [PATCH] Grinding now working --- .../resonantinduction/api/MachineRecipes.java | 12 +++++++ .../machine/grinder/BlockGrinderWheel.java | 10 +++++- .../machine/grinder/ItemDust.java | 9 +++-- .../machine/grinder/TileGrinderWheel.java | 36 +++++++++++++------ 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/main/java/resonantinduction/api/MachineRecipes.java b/src/main/java/resonantinduction/api/MachineRecipes.java index 9a6d909b..1cd438a7 100644 --- a/src/main/java/resonantinduction/api/MachineRecipes.java +++ b/src/main/java/resonantinduction/api/MachineRecipes.java @@ -88,4 +88,16 @@ public final class MachineRecipes return this.getOutput(machine, resourceInputs); } + + public Resource[] getRecipe(RecipeType machine, String... oreDictNames) + { + Resource[] resourceInputs = new Resource[oreDictNames.length]; + + for (int i = 0; i < oreDictNames.length; i++) + { + resourceInputs[i] = new OreDictResource(oreDictNames[i]); + } + + return this.getOutput(machine, resourceInputs); + } } diff --git a/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java index 3695d748..9087b50b 100644 --- a/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java +++ b/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java @@ -6,6 +6,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.DamageSource; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import resonantinduction.core.base.BlockRotatableBase; /** @@ -43,8 +44,15 @@ public class BlockGrinderWheel extends BlockRotatableBase implements ITileEntity } else { - entity.attackEntityFrom(DamageSource.cactus, 1); + entity.attackEntityFrom(DamageSource.cactus, 2); } + + // Move entity based on the direction of the block. + ForgeDirection dir = this.getDirection(world, x, y, z); + entity.motionX += dir.offsetX * 0.1; + entity.motionZ += dir.offsetZ * 0.1; + + entity.motionY += Math.random() * 0.3; } @Override diff --git a/src/main/java/resonantinduction/machine/grinder/ItemDust.java b/src/main/java/resonantinduction/machine/grinder/ItemDust.java index f234f45c..b1706939 100644 --- a/src/main/java/resonantinduction/machine/grinder/ItemDust.java +++ b/src/main/java/resonantinduction/machine/grinder/ItemDust.java @@ -84,11 +84,11 @@ public class ItemDust extends ItemBase } public static void generateDusts() - { + { for (String materialName : materialNames) { String name = materialName.substring(0, 1).toUpperCase() + materialName.substring(1); - + if (OreDictionary.getOres("ore" + name).size() > 0) { if (OreDictionary.getOres("dust" + name).size() == 0) @@ -99,7 +99,10 @@ public class ItemDust extends ItemBase } // Add to machine recipes - MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "ore" + name, OreDictionary.getOres("dust" + name).get(0)); + + ItemStack dust = OreDictionary.getOres("dust" + name).get(0).copy(); + dust.stackSize = 2; + MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER, "ore" + name, dust); } } } diff --git a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java index 42fdcd32..498cffa8 100644 --- a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java +++ b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java @@ -46,14 +46,19 @@ public class TileGrinderWheel extends TileElectrical if (entry.getValue() <= 0) { - this.doGrind(entry.getKey()); + + if (this.doGrind(entry.getKey())) + { + entry.getKey().setDead(); + it.remove(); + } } else { // Make the entity not be able to be picked up. EntityItem entity = entry.getKey(); entity.delayBeforeCanPickup = 20; - this.worldObj.spawnParticle("smoke", entity.posX, entity.posY, entity.posZ, 0, 0, 0); + this.worldObj.spawnParticle("crit", entity.posX, entity.posY, entity.posZ, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3); } } } @@ -63,19 +68,28 @@ public class TileGrinderWheel extends TileElectrical return MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack) == null ? false : MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack).length > 0; } - private void doGrind(EntityItem entity) + private boolean doGrind(EntityItem entity) { - ItemStack itemStack = entity.getEntityItem(); - - Resource[] results = MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack); - - for (Resource resource : results) + if (!this.worldObj.isRemote) { - if (resource instanceof ItemStackResource) + ItemStack itemStack = entity.getEntityItem(); + + Resource[] results = MachineRecipes.INSTANCE.getRecipe(RecipeType.GRINDER, itemStack); + + for (Resource resource : results) { - entity.setEntityItemStack(((ItemStackResource) resource).itemStack); - entity.setPosition(entity.posX, entity.posY - 1.2, entity.posZ); + if (resource instanceof ItemStackResource) + { + EntityItem entityItem = new EntityItem(this.worldObj, entity.posX, entity.posY, entity.posZ, ((ItemStackResource) resource).itemStack.copy()); + entityItem.delayBeforeCanPickup = 20; + entityItem.motionX = 0; + entityItem.motionY = 0; + entityItem.motionZ = 0; + this.worldObj.spawnEntityInWorld(entityItem); + } } } + + return true; } }