Initial grinder working

This commit is contained in:
Calclavia 2014-01-05 15:58:38 +08:00
parent 474fb6d529
commit cc765887c0
3 changed files with 70 additions and 5 deletions

View file

@ -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());

View file

@ -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

View file

@ -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<EntityItem, Integer> map = new HashMap<EntityItem, Integer>();
public final HashMap<EntityItem, Integer> grinderTimer = new HashMap<EntityItem, Integer>();
public TileGrinderWheel()
{
this.energy = new EnergyStorageHandler(100000);
}
@Override
public void updateEntity()
{
// TODO: Add electricity support.
doWork();
}
public void doWork()
{
Iterator<Entry<EntityItem, Integer>> it = map.entrySet().iterator();
Iterator<Entry<EntityItem, Integer>> 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;
}
}
}