From cc765887c00f70f156aefcd5aba13e346eaa0894 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 5 Jan 2014 15:58:38 +0800 Subject: [PATCH] Initial grinder working --- .../resonantinduction/ResonantInduction.java | 3 ++ .../machine/grinder/BlockGrinderWheel.java | 45 ++++++++++++++++++- .../machine/grinder/TileGrinderWheel.java | 27 +++++++++-- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/main/java/resonantinduction/ResonantInduction.java b/src/main/java/resonantinduction/ResonantInduction.java index b23ad579..937502db 100644 --- a/src/main/java/resonantinduction/ResonantInduction.java +++ b/src/main/java/resonantinduction/ResonantInduction.java @@ -31,6 +31,7 @@ import resonantinduction.machine.furnace.BlockAdvancedFurnace; import resonantinduction.machine.furnace.TileAdvancedFurnace; import resonantinduction.machine.grinder.BlockGrinderWheel; import resonantinduction.machine.grinder.ItemDust; +import resonantinduction.machine.grinder.TileGrinderWheel; import resonantinduction.machine.liquid.BlockFluidMixture; import resonantinduction.machine.liquid.TileFluidMixture; import resonantinduction.transport.battery.BlockBattery; @@ -229,6 +230,7 @@ public class ResonantInduction GameRegistry.registerItem(itemTransformer, itemTransformer.getUnlocalizedName()); GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName()); + GameRegistry.registerBlock(blockGrinderWheel, blockGrinderWheel.getUnlocalizedName()); GameRegistry.registerBlock(blockFluidMixture, blockFluidMixture.getUnlocalizedName()); GameRegistry.registerBlock(blockMachinePart, blockMachinePart.getUnlocalizedName()); GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName()); @@ -236,6 +238,7 @@ public class ResonantInduction GameRegistry.registerBlock(blockBattery, ItemBlockBattery.class, blockBattery.getUnlocalizedName()); // Tiles + GameRegistry.registerTileEntity(TileGrinderWheel.class, blockGrinderWheel.getUnlocalizedName()); GameRegistry.registerTileEntity(TileTesla.class, blockTesla.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEMLevitator.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerTileEntity(TileBattery.class, blockBattery.getUnlocalizedName()); diff --git a/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java index 1aadee6b..ccf34258 100644 --- a/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java +++ b/src/main/java/resonantinduction/machine/grinder/BlockGrinderWheel.java @@ -1,9 +1,12 @@ package resonantinduction.machine.grinder; import net.minecraft.block.ITileEntityProvider; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.DamageSource; import net.minecraft.world.World; -import resonantinduction.core.base.BlockBase; +import resonantinduction.core.base.BlockRotatableBase; /** * A block used to build machines. @@ -11,11 +14,49 @@ import resonantinduction.core.base.BlockBase; * @author Calclavia * */ -public class BlockGrinderWheel extends BlockBase implements ITileEntityProvider +public class BlockGrinderWheel extends BlockRotatableBase implements ITileEntityProvider { public BlockGrinderWheel(int id) { super("grindingWheel", id); + this.setBlockBounds(0.05f, 0.05f, 0.05f, 0.95f, 0.95f, 0.95f); + } + + @Override + public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) + { + if (entity instanceof EntityItem) + { + TileGrinderWheel tile = (TileGrinderWheel) world.getBlockTileEntity(x, y, z); + + if (tile.canGrind(((EntityItem) entity).getEntityItem())) + { + if (!tile.grinderTimer.containsKey((EntityItem) entity)) + { + tile.grinderTimer.put((EntityItem) entity, 10 * 20); + } + } + else + { + entity.moveEntity(0, -1, 0); + } + } + else + { + entity.attackEntityFrom(DamageSource.cactus, 1); + } + } + + @Override + public boolean isOpaqueCube() + { + return false; + } + + @Override + public boolean renderAsNormalBlock() + { + return false; } @Override diff --git a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java index b57cec35..75302102 100644 --- a/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java +++ b/src/main/java/resonantinduction/machine/grinder/TileGrinderWheel.java @@ -11,6 +11,7 @@ import resonantinduction.api.MachineRecipes; import resonantinduction.api.MachineRecipes.RecipeType; import resonantinduction.api.RecipeUtils.ItemStackResource; import resonantinduction.api.RecipeUtils.Resource; +import universalelectricity.api.energy.EnergyStorageHandler; import calclavia.lib.prefab.tile.TileElectrical; /** @@ -20,11 +21,23 @@ import calclavia.lib.prefab.tile.TileElectrical; public class TileGrinderWheel extends TileElectrical { /** A map of ItemStacks and their remaining grind-time left. */ - public static final HashMap map = new HashMap(); + public final HashMap grinderTimer = new HashMap(); + + public TileGrinderWheel() + { + this.energy = new EnergyStorageHandler(100000); + } + + @Override + public void updateEntity() + { + // TODO: Add electricity support. + doWork(); + } public void doWork() { - Iterator> it = map.entrySet().iterator(); + Iterator> it = grinderTimer.entrySet().iterator(); while (it.hasNext()) { @@ -35,10 +48,17 @@ public class TileGrinderWheel extends TileElectrical { this.doGrind(entry.getKey()); } + 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); + } } } - private boolean canGrind(ItemStack itemStack) + public boolean canGrind(ItemStack itemStack) { return MachineRecipes.INSTANCE.getRecipes(RecipeType.GRINDER).containsKey(itemStack); } @@ -54,6 +74,7 @@ public class TileGrinderWheel extends TileElectrical if (resource instanceof ItemStackResource) { entity.setEntityItemStack(((ItemStackResource) resource).itemStack); + entity.posY -= 1; } } }