Added purifier rotor

This commit is contained in:
Calclavia 2014-01-07 21:49:26 +08:00
parent c4e0a03da8
commit b5a1f82db6
6 changed files with 255 additions and 9 deletions

View file

@ -31,9 +31,11 @@ import resonantinduction.machine.furnace.BlockAdvancedFurnace;
import resonantinduction.machine.furnace.TileAdvancedFurnace;
import resonantinduction.machine.grinder.BlockGrinderWheel;
import resonantinduction.machine.grinder.TileGrinderWheel;
import resonantinduction.machine.grinder.TilePurifier;
import resonantinduction.machine.item.ItemDust;
import resonantinduction.machine.liquid.BlockFluidMixture;
import resonantinduction.machine.liquid.TileFluidMixture;
import resonantinduction.machine.purifier.BlockPurifier;
import resonantinduction.transport.LinkEvent;
import resonantinduction.transport.battery.BlockBattery;
import resonantinduction.transport.battery.ItemBlockBattery;
@ -165,7 +167,7 @@ public class ResonantInduction
// Blocks
public static Block blockTesla, blockEMContractor, blockBattery, blockAdvancedFurnace,
blockMachinePart, blockGrinderWheel, blockFluidMixture;
blockMachinePart, blockGrinderWheel, blockPurifier, blockFluidMixture;
public static Fluid MIXTURE;
@ -209,6 +211,7 @@ public class ResonantInduction
blockBattery = new BlockBattery(getNextBlockID());
blockMachinePart = new BlockMachinePart(getNextBlockID());
blockGrinderWheel = new BlockGrinderWheel(getNextBlockID());
blockPurifier = new BlockPurifier(getNextBlockID());
MIXTURE = new Fluid("mixture");
FluidRegistry.registerFluid(MIXTURE);
@ -228,6 +231,7 @@ public class ResonantInduction
GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName());
GameRegistry.registerBlock(blockGrinderWheel, blockGrinderWheel.getUnlocalizedName());
GameRegistry.registerBlock(blockPurifier, blockPurifier.getUnlocalizedName());
GameRegistry.registerBlock(blockFluidMixture, blockFluidMixture.getUnlocalizedName());
GameRegistry.registerBlock(blockMachinePart, blockMachinePart.getUnlocalizedName());
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
@ -235,6 +239,7 @@ public class ResonantInduction
GameRegistry.registerBlock(blockBattery, ItemBlockBattery.class, blockBattery.getUnlocalizedName());
// Tiles
GameRegistry.registerTileEntity(TilePurifier.class, blockPurifier.getUnlocalizedName());
GameRegistry.registerTileEntity(TileGrinderWheel.class, blockGrinderWheel.getUnlocalizedName());
GameRegistry.registerTileEntity(TileTesla.class, blockTesla.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEMLevitator.class, blockEMContractor.getUnlocalizedName());

View file

@ -96,7 +96,7 @@ public class BlockGrinderWheel extends BlockRotatableBase implements ITileEntity
ForgeDirection dir = this.getDirection(world, x, y, z);
entity.motionX += dir.offsetX * 0.1;
entity.motionZ += dir.offsetZ * 0.1;
entity.motionY += 0.3;
entity.motionY += 0.1;
entity.isAirBorne = true;
}
}

View file

@ -21,16 +21,17 @@ import cpw.mods.fml.relauncher.Side;
*/
public class TileGrinderWheel extends TileElectrical
{
public static final long POWER = 500000;
public static final int DEFAULT_TIME = 20 * 20;
/** A map of ItemStacks and their remaining grind-time left. */
private static final HashMap<EntityItem, Integer> clientGrinderTimer = new HashMap<EntityItem, Integer>();
private static final HashMap<EntityItem, Integer> serverGrinderTimer = new HashMap<EntityItem, Integer>();
private static final HashMap<EntityItem, Integer> clientTimer = new HashMap<EntityItem, Integer>();
private static final HashMap<EntityItem, Integer> serverTimer = new HashMap<EntityItem, Integer>();
public EntityItem grindingItem = null;
public TileGrinderWheel()
{
this.energy = new EnergyStorageHandler(100000);
this.energy = new EnergyStorageHandler(POWER * 2);
}
@Override
@ -57,7 +58,7 @@ public class TileGrinderWheel extends TileElectrical
if (grindingItem != null)
{
if (getTimer().containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(new Vector3(grindingItem)) < 1)
if (getTimer().containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(grindingItem) < 1)
{
int timeLeft = getTimer().get(grindingItem) - 1;
getTimer().put(grindingItem, timeLeft);
@ -97,11 +98,12 @@ public class TileGrinderWheel extends TileElectrical
if (didWork)
{
// TODO: Consume energy.
if (this.ticks % 20 == 0)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "grinder", 0.5f, 1);
}
this.energy.extractEnergy(POWER / 20, true);
}
}
@ -141,9 +143,9 @@ public class TileGrinderWheel extends TileElectrical
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
return serverGrinderTimer;
return serverTimer;
}
return clientGrinderTimer;
return clientTimer;
}
}

View file

@ -0,0 +1,159 @@
package resonantinduction.machine.grinder;
import java.util.HashMap;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import resonantinduction.ResonantInduction;
import resonantinduction.api.MachineRecipes;
import resonantinduction.api.MachineRecipes.RecipeType;
import resonantinduction.api.RecipeUtils.ItemStackResource;
import resonantinduction.api.RecipeUtils.Resource;
import resonantinduction.machine.item.ItemDust;
import universalelectricity.api.energy.EnergyStorageHandler;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.tile.TileElectrical;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
/**
* @author Calclavia
*
*/
public class TilePurifier extends TileElectrical
{
public static final long POWER = 500000;
public static final int DEFAULT_TIME = 10 * 20;
/** A map of ItemStacks and their remaining grind-time left. */
private static final HashMap<EntityItem, Integer> clientTimer = new HashMap<EntityItem, Integer>();
private static final HashMap<EntityItem, Integer> serverTimer = new HashMap<EntityItem, Integer>();
public EntityItem processingItem = null;
public TilePurifier()
{
this.energy = new EnergyStorageHandler(POWER * 2);
}
@Override
public void updateEntity()
{
super.updateEntity();
if (canWork())
{
doWork();
}
}
/**
* Can this machine work this tick?
*
* @return
*/
public boolean canWork()
{
// TODO: Add electricity support.
return true;
}
public void doWork()
{
boolean didWork = false;
// Search for an item to "process"
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(this.xCoord - 1, this.yCoord, this.zCoord - 1, this.xCoord + 1, this.yCoord, this.zCoord + 1);
List<Entity> entities = this.worldObj.getEntitiesWithinAABB(Entity.class, aabb);
for (Entity entity : entities)
{
/**
* Rotate entities around purifier
*/
double speed = 0.1;
Vector3 originalPosition = new Vector3(this);
Vector3 relativePosition = originalPosition.clone().subtract(new Vector3(this));
relativePosition.rotate(speed, 0, 0);
Vector3 newPosition = new Vector3(this).add(relativePosition);
if (this.processingItem == null && entity instanceof EntityItem)
{
if (((EntityItem) entity).getEntityItem().getItem() instanceof ItemDust)
{
this.processingItem = (EntityItem) entity;
}
}
}
if (processingItem != null)
{
if (getTimer().containsKey(processingItem) && !processingItem.isDead && new Vector3(this).add(0.5).distance(processingItem) < 1)
{
int timeLeft = getTimer().get(processingItem) - 1;
getTimer().put(processingItem, timeLeft);
if (timeLeft <= 0)
{
if (this.doneWork(processingItem))
{
if (--processingItem.getEntityItem().stackSize <= 0)
{
processingItem.setDead();
getTimer().remove(processingItem);
processingItem = null;
}
else
{
processingItem.setEntityItemStack(processingItem.getEntityItem());
// Reset timer
getTimer().put(processingItem, DEFAULT_TIME);
}
}
}
else
{
processingItem.delayBeforeCanPickup = 20;
this.worldObj.spawnParticle("bubble", processingItem.posX, processingItem.posY, processingItem.posZ, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3);
}
didWork = true;
}
else
{
getTimer().remove(processingItem);
processingItem = null;
}
}
if (didWork)
{
if (this.ticks % 20 == 0)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "grinder", 0.5f, 1);
}
this.energy.extractEnergy(POWER / 20, true);
}
}
private boolean doneWork(EntityItem entity)
{
ItemStack itemStack = entity.getEntityItem();
entity.setDead();
return false;
}
public static HashMap<EntityItem, Integer> getTimer()
{
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
return serverTimer;
}
return clientTimer;
}
}

View file

@ -0,0 +1,79 @@
package resonantinduction.machine.purifier;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.base.BlockRotatableBase;
import resonantinduction.machine.grinder.TilePurifier;
import universalelectricity.api.vector.VectorWorld;
/**
* A block used to build machines.
*
* @author Calclavia
*
*/
public class BlockPurifier extends BlockRotatableBase implements ITileEntityProvider
{
public BlockPurifier(int id)
{
super("purifier", id);
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
this.checkConflicts(world, x, y, z);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int par5)
{
this.checkConflicts(world, x, y, z);
}
/**
* Checks for any conflicting directions with other grinders.
*/
private void checkConflicts(World world, int x, int y, int z)
{
ForgeDirection facing = this.getDirection(world, x, y, z);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != facing && dir != facing.getOpposite())
{
VectorWorld checkPos = (VectorWorld) new VectorWorld(world, x, y, z).modifyPositionFromSide(dir);
TileEntity tileEntity = checkPos.getTileEntity();
if (tileEntity instanceof TilePurifier)
{
if (this.getDirection(world, checkPos.intX(), checkPos.intY(), checkPos.intZ()) == facing)
{
this.dropBlockAsItem(world, x, y, z, 0, 0);
world.setBlockToAir(x, y, z);
}
}
}
}
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TilePurifier();
}
}

View file

@ -15,6 +15,7 @@ tile.resonantinduction\:levitator.name=Electromagnetic Levitator
tile.resonantinduction\:battery.name=Battery
tile.resonantinduction\:machinePart.name=Machine Part
tile.resonantinduction\:grindingWheel.name=Grinder Wheel
tile.resonantinduction\:purifier.name=Purifier Rotor
tile.resonantinduction\:filter.name=Filter
## Items