Resolved #432, #317 - Wind turbines now can be powered to blow items

This commit is contained in:
Calclavia 2014-03-12 19:52:16 +08:00
parent edff518b72
commit 8f14af4bb7
7 changed files with 93 additions and 11 deletions

View file

@ -33,7 +33,7 @@ public class RenderWindTurbine extends TileEntitySpecialRenderer implements ISim
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
GL11.glTranslatef(0, -0.35f, 0);
GL11.glRotatef((float) Math.toDegrees(tile.rotation), 0, 1, 0);
GL11.glRotatef((float) Math.toDegrees(tile.renderAngle), 0, 1, 0);
render(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());

View file

@ -8,13 +8,18 @@ import resonantinduction.core.grid.INode;
import resonantinduction.core.grid.INodeProvider;
import resonantinduction.mechanical.energy.grid.MechanicalNode;
import universalelectricity.api.energy.EnergyStorageHandler;
import calclavia.lib.network.Synced;
import calclavia.lib.network.Synced.SyncedInput;
import calclavia.lib.network.Synced.SyncedOutput;
import calclavia.lib.prefab.turbine.TileTurbine;
//TODO: MC 1.7, merge turbines in.
public class TileMechanicalTurbine extends TileTurbine implements INodeProvider
{
protected MechanicalNode mechanicalNode;
@Synced(1)
protected double renderAngularVelocity;
protected double renderAngle;
public TileMechanicalTurbine()
{
@ -70,11 +75,37 @@ public class TileMechanicalTurbine extends TileTurbine implements INodeProvider
super.invalidate();
}
@Override
public void updateEntity()
{
if (!worldObj.isRemote)
{
renderAngularVelocity = (double) mechanicalNode.angularVelocity;
}
else
{
renderAngle = (renderAngle + renderAngularVelocity / 20) % (Math.PI * 2);
// TODO: Make this neater
onProduce();
}
super.updateEntity();
}
@Override
public void onProduce()
{
mechanicalNode.torque += (torque - mechanicalNode.torque) / 10;
mechanicalNode.angularVelocity += (angularVelocity - mechanicalNode.angularVelocity) / 10;
if (!worldObj.isRemote)
{
if (mechanicalNode.torque < 0)
torque = -torque;
if (mechanicalNode.angularVelocity < 0)
angularVelocity = -angularVelocity;
mechanicalNode.apply((torque - mechanicalNode.torque) / 10, (angularVelocity - mechanicalNode.angularVelocity) / 10);
}
}
@Override

View file

@ -1,6 +1,9 @@
package resonantinduction.mechanical.energy.turbine;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
@ -8,6 +11,7 @@ import net.minecraft.world.biome.BiomeGenOcean;
import net.minecraft.world.biome.BiomeGenPlains;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.vector.Cuboid;
import calclavia.lib.utility.inventory.InventoryUtility;
/**
@ -49,7 +53,7 @@ public class TileWindTurbine extends TileMechanicalTurbine
*/
if (getDirection().offsetY == 0)
{
maxPower = 120;
maxPower = 3000;
if (ticks % 20 == 0 && !worldObj.isRemote)
computePower();
@ -58,17 +62,65 @@ public class TileWindTurbine extends TileMechanicalTurbine
}
else
{
maxPower = 1000;
maxPower = 10000;
}
if (getMultiBlock().isConstructed())
torque = (long) (defaultTorque / (2.5f / multiBlockRadius));
torque = (long) (defaultTorque / (.52f / multiBlockRadius));
else
torque = defaultTorque / 12;
super.updateEntity();
}
@Override
public void onProduce()
{
super.onProduce();
/**
* Blow entities if greater than max power.
*/
double velocity = !worldObj.isRemote ? mechanicalNode.getAngularVelocity() : renderAngularVelocity;
if (velocity != 0)
{
ForgeDirection dir = getDirection();
double affectRange = Math.abs(velocity * 2);
Cuboid effect = Cuboid.full().translate(new Vector3(this).translate(dir));
if (getMultiBlock().isConstructed())
{
double xMulti = dir.offsetX != 0 ? affectRange : 1;
double yMulti = dir.offsetY != 0 ? affectRange : 1;
double zMulti = dir.offsetZ != 0 ? affectRange : 1;
effect.expand(new Vector3(multiBlockRadius * xMulti, multiBlockRadius * yMulti, multiBlockRadius * zMulti));
}
else
{
double xMulti = dir.offsetX != 0 ? affectRange : 0;
double yMulti = dir.offsetY != 0 ? affectRange : 0;
double zMulti = dir.offsetZ != 0 ? affectRange : 0;
effect.expand(new Vector3(xMulti, yMulti, zMulti));
}
List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, effect.toAABB());
velocity = Math.min(Math.max(velocity, -0.3), 0.3);
for (Entity entity : entities)
{
entity.motionX += dir.offsetX * velocity / 20;
entity.motionY += dir.offsetY * velocity / 20;
entity.motionZ += dir.offsetZ * velocity / 20;
}
}
}
private void computePower()
{
int checkSize = 10;
@ -116,6 +168,6 @@ public class TileWindTurbine extends TileMechanicalTurbine
boolean hasBonus = biome instanceof BiomeGenOcean || biome instanceof BiomeGenPlains || biome == BiomeGenBase.river;
float windSpeed = (worldObj.rand.nextFloat() / 8) + (yCoord / 256f) * (hasBonus ? 1.2f : 1) + worldObj.getRainStrength(1.5f);
windPower = (long) (materialMultiplier * multiblockMultiplier * windSpeed * efficiency * 0.01f) * maxPower;
windPower = (long) Math.min(materialMultiplier * multiblockMultiplier * windSpeed * efficiency, maxPower);
}
}

View file

@ -170,7 +170,6 @@ public class RenderPipe implements ISimpleItemRenderer
public void renderInventoryItem(ItemStack itemStack)
{
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
render(itemStack.getItemDamage(), -1, Byte.parseByte("001100", 2));
GL11.glPopMatrix();
}

View file

@ -14,9 +14,9 @@ import resonantinduction.api.IMechanicalNode;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.api.recipe.RecipeResource;
import resonantinduction.archaic.filter.Timer;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.Timer;
import resonantinduction.mechanical.energy.grid.TileMechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.tile.IRotatable;

View file

@ -15,8 +15,8 @@ import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.IMechanicalNode;
import resonantinduction.api.recipe.MachineRecipes;
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
import resonantinduction.archaic.filter.Timer;
import resonantinduction.core.Reference;
import resonantinduction.core.Timer;
import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import resonantinduction.mechanical.energy.grid.TileMechanical;

View file

@ -1,4 +1,4 @@
package resonantinduction.archaic.filter;
package resonantinduction.core;
import java.util.HashMap;