Merge branch 'development' of https://bitbucket.org/calclavia/resonant-induction into development

This commit is contained in:
tgame14 2014-03-28 18:28:49 +03:00
commit a1ad7358af
5 changed files with 123 additions and 63 deletions

View file

@ -192,7 +192,7 @@ public class PartGear extends PartMechanical implements IMultiBlockStructure<Par
* Can this gear be connected BY the source? * Can this gear be connected BY the source?
* *
* @param from - Direction source is coming from. * @param from - Direction source is coming from.
* @param source - The source of the connection. * @param with - The source of the connection.
* @return True is so. * @return True is so.
*/ */
@Override @Override

View file

@ -1,15 +1,5 @@
package resonantinduction.mechanical.energy.gear; package resonantinduction.mechanical.energy.gear;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.energy.grid.MechanicalNode;
import resonantinduction.mechanical.energy.grid.PartMechanical;
import calclavia.api.resonantinduction.IMechanicalNode; import calclavia.api.resonantinduction.IMechanicalNode;
import calclavia.lib.grid.INodeProvider; import calclavia.lib.grid.INodeProvider;
import codechicken.lib.raytracer.IndexedCuboid6; import codechicken.lib.raytracer.IndexedCuboid6;
@ -18,12 +8,21 @@ import codechicken.lib.vec.Vector3;
import codechicken.multipart.PartMap; import codechicken.multipart.PartMap;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.mechanical.energy.grid.MechanicalNode;
import resonantinduction.mechanical.energy.grid.PartMechanical;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/** /**
* We assume all the force acting on the gear is 90 degrees. * We assume all the force acting on the gear is 90 degrees.
* *
* @author Calclavia * @author Calclavia
*
*/ */
public class PartGearShaft extends PartMechanical public class PartGearShaft extends PartMechanical
{ {
@ -40,15 +39,6 @@ public class PartGearShaft extends PartMechanical
sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64)); sides[6] = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64));
} }
@Override
public void preparePlacement(int side, int itemDamage)
{
ForgeDirection dir = ForgeDirection.getOrientation((byte) (side ^ 1));
// Unwind rotation. We can only have "3" axis.
this.placementSide = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
tier = itemDamage;
}
public PartGearShaft() public PartGearShaft()
{ {
super(); super();
@ -132,13 +122,18 @@ public class PartGearShaft extends PartMechanical
@Override @Override
public boolean canConnect(ForgeDirection from, Object source) public boolean canConnect(ForgeDirection from, Object source)
{ {
if (source instanceof PartGear) if (source instanceof MechanicalNode)
{ {
PartGear gear = (PartGear) source; if (((MechanicalNode) source).parent instanceof PartGear)
{
PartGear gear = (PartGear) ((MechanicalNode) source).parent;
if (!(Math.abs(gear.placementSide.offsetX) == Math.abs(placementSide.offsetX) && Math.abs(gear.placementSide.offsetY) == Math.abs(placementSide.offsetY) && Math.abs(gear.placementSide.offsetZ) == Math.abs(placementSide.offsetZ))) if (!(Math.abs(gear.placementSide.offsetX) == Math.abs(placementSide.offsetX) && Math.abs(gear.placementSide.offsetY) == Math.abs(placementSide.offsetY) && Math.abs(gear.placementSide.offsetZ) == Math.abs(placementSide.offsetZ)))
{
return false; return false;
} }
}
}
return from == placementSide || from == placementSide.getOpposite(); return from == placementSide || from == placementSide.getOpposite();
} }
@ -156,6 +151,15 @@ public class PartGearShaft extends PartMechanical
}; };
} }
@Override
public void preparePlacement(int side, int itemDamage)
{
ForgeDirection dir = ForgeDirection.getOrientation((byte) (side ^ 1));
// Unwind rotation. We can only have "3" axis.
this.placementSide = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
tier = itemDamage;
}
@Override @Override
protected ItemStack getItem() protected ItemStack getItem()
{ {
@ -213,9 +217,11 @@ public class PartGearShaft extends PartMechanical
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{ {
if (side == placementSide || side == placementSide.getOpposite()) if (side == placementSide || side == placementSide.getOpposite())
{
subParts.add(currentSides[side.ordinal()]); subParts.add(currentSides[side.ordinal()]);
} }
} }
}
subParts.add(currentSides[6]); subParts.add(currentSides[6]);
return subParts; return subParts;

View file

@ -1,37 +1,38 @@
package resonantinduction.mechanical.energy.grid; package resonantinduction.mechanical.energy.grid;
import java.util.Iterator; import calclavia.api.resonantinduction.IMechanicalNode;
import java.util.Map.Entry; import calclavia.lib.grid.INodeProvider;
import calclavia.lib.grid.Node;
import calclavia.lib.grid.TickingGrid;
import codechicken.multipart.TMultiPart;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.ResonantInduction; import resonantinduction.core.ResonantInduction;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
import calclavia.api.resonantinduction.IMechanicalNode;
import calclavia.lib.grid.INodeProvider; import java.util.Iterator;
import calclavia.lib.grid.Node; import java.util.Map.Entry;
import calclavia.lib.grid.TickingGrid;
import codechicken.multipart.TMultiPart;
/** /**
* A mechanical node for mechanical energy. * A mechanical node for mechanical energy.
* * <p/>
* Useful Formula: * Useful Formula:
* * <p/>
* Power is the work per unit time. * Power is the work per unit time.
* Power (W) = Torque (Strength of the rotation, Newton Meters) x Speed (Angular Velocity, RADIAN * Power (W) = Torque (Strength of the rotation, Newton Meters) x Speed (Angular Velocity, RADIAN
* PER SECOND). * PER SECOND).
* *OR* * *OR*
* Power = Torque / Time * Power = Torque / Time
* * <p/>
* Torque = r (Radius) * F (Force) * sin0 (Direction/Angle of the force applied. 90 degrees if * Torque = r (Radius) * F (Force) * sin0 (Direction/Angle of the force applied. 90 degrees if
* optimal.) * optimal.)
* *
* @author Calclavia * @author Calclavia
*/ */
public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalNode> implements IMechanicalNode public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalNode>
implements IMechanicalNode
{ {
public double torque = 0; public double torque = 0;
public double prevAngularVelocity, angularVelocity = 0; public double prevAngularVelocity, angularVelocity = 0;
@ -71,7 +72,9 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
prevAngularVelocity = angularVelocity; prevAngularVelocity = angularVelocity;
if (!ResonantInduction.proxy.isPaused()) if (!ResonantInduction.proxy.isPaused())
{
angle += angularVelocity * deltaTime; angle += angularVelocity * deltaTime;
}
if (angle % (Math.PI * 2) != angle) if (angle % (Math.PI * 2) != angle)
{ {
@ -89,16 +92,24 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
double torqueLoss = Math.min(Math.abs(getTorque()), (Math.abs(getTorque() * getTorqueLoad()) + getTorqueLoad() / 10) * deltaTime); double torqueLoss = Math.min(Math.abs(getTorque()), (Math.abs(getTorque() * getTorqueLoad()) + getTorqueLoad() / 10) * deltaTime);
if (torque > 0) if (torque > 0)
{
torque -= torqueLoss; torque -= torqueLoss;
}
else else
{
torque += torqueLoss; torque += torqueLoss;
}
double velocityLoss = Math.min(Math.abs(getAngularVelocity()), (Math.abs(getAngularVelocity() * getAngularVelocityLoad()) + getAngularVelocityLoad() / 10) * deltaTime); double velocityLoss = Math.min(Math.abs(getAngularVelocity()), (Math.abs(getAngularVelocity() * getAngularVelocityLoad()) + getAngularVelocityLoad() / 10) * deltaTime);
if (angularVelocity > 0) if (angularVelocity > 0)
{
angularVelocity -= velocityLoss; angularVelocity -= velocityLoss;
}
else else
{
angularVelocity += velocityLoss; angularVelocity += velocityLoss;
}
power = getEnergy() / deltaTime; power = getEnergy() / deltaTime;
@ -121,11 +132,27 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
int inversion = inverseRotation ? -1 : 1; int inversion = inverseRotation ? -1 : 1;
if (Math.abs(torque + inversion * (adjacentMech.getTorque() / ratio * acceleration)) < Math.abs(adjacentMech.getTorque() / ratio)) double applyTorque = inversion * adjacentMech.getTorque() / ratio * acceleration;
torque = torque + inversion * (adjacentMech.getTorque() / ratio * acceleration);
if (Math.abs(angularVelocity + inversion * (adjacentMech.getAngularVelocity() * ratio * acceleration)) < Math.abs(adjacentMech.getAngularVelocity() * ratio)) if (Math.abs(torque + applyTorque) < Math.abs(adjacentMech.getTorque() / ratio))
angularVelocity = angularVelocity + (inversion * adjacentMech.getAngularVelocity() * ratio * acceleration); {
torque += applyTorque;
}
else
{
torque -= applyTorque;
}
double applyVelocity = inversion * adjacentMech.getAngularVelocity() * ratio * acceleration;
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(adjacentMech.getAngularVelocity() * ratio))
{
angularVelocity += applyVelocity;
}
else
{
angularVelocity -= applyVelocity;
}
/** /**
* Set all current rotations * Set all current rotations

View file

@ -1,10 +1,10 @@
package resonantinduction.mechanical.process.purifier; package resonantinduction.mechanical.process.purifier;
import java.util.LinkedHashSet; import calclavia.api.recipe.MachineRecipes;
import java.util.List; import calclavia.api.resonantinduction.IMechanicalNode;
import java.util.Set; import calclavia.lib.utility.inventory.InventoryUtility;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFluid;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
@ -13,6 +13,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock;
import resonantinduction.core.Reference; import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction.RecipeType; import resonantinduction.core.ResonantInduction.RecipeType;
import resonantinduction.core.Timer; import resonantinduction.core.Timer;
@ -20,13 +21,13 @@ import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.fluid.BlockFluidMixture; import resonantinduction.core.resource.fluid.BlockFluidMixture;
import resonantinduction.mechanical.energy.grid.TileMechanical; import resonantinduction.mechanical.energy.grid.TileMechanical;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
import calclavia.api.recipe.MachineRecipes;
import calclavia.api.resonantinduction.IMechanicalNode; import java.util.LinkedHashSet;
import calclavia.lib.utility.inventory.InventoryUtility; import java.util.List;
import java.util.Set;
/** /**
* @author Calclavia * @author Calclavia
*
*/ */
public class TileMixer extends TileMechanical implements IInventory public class TileMixer extends TileMechanical implements IInventory
{ {
@ -57,6 +58,28 @@ public class TileMixer extends TileMechanical implements IInventory
@Override @Override
public void updateEntity() public void updateEntity()
{ {
if (!world().isRemote && ticks % 20 == 0)
{
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
if (x != 0 && z != 0)
{
int id = position().translate(x, 0, z).getBlockID(world());
Block block = Block.blocksList[id];
if (block != null && !(block instanceof IFluidBlock) && !(block instanceof BlockFluid))
{
block.dropBlockAsItem(world(), x(), y(), z(), 0, 0);
position().setBlock(0);
return;
}
}
}
}
}
super.updateEntity(); super.updateEntity();
if (canWork()) if (canWork())
@ -163,6 +186,9 @@ public class TileMixer extends TileMechanical implements IInventory
private boolean doneWork(EntityItem entity) private boolean doneWork(EntityItem entity)
{ {
Vector3 mixPosition = new Vector3(entity.posX, yCoord, entity.posZ); Vector3 mixPosition = new Vector3(entity.posX, yCoord, entity.posZ);
if (mixPosition.getBlockID(world()) != blockID())
{
Block block = Block.blocksList[mixPosition.getBlockID(worldObj)]; Block block = Block.blocksList[mixPosition.getBlockID(worldObj)];
if (block instanceof BlockFluidMixture) if (block instanceof BlockFluidMixture)
@ -179,6 +205,7 @@ public class TileMixer extends TileMechanical implements IInventory
{ {
mixPosition.setBlock(worldObj, ResourceGenerator.getMixture(ResourceGenerator.getName(entity.getEntityItem())).blockID); mixPosition.setBlock(worldObj, ResourceGenerator.getMixture(ResourceGenerator.getName(entity.getEntityItem())).blockID);
} }
}
return false; return false;
} }

@ -1 +1 @@
Subproject commit ba1590e0a3bcde55dd1ed7d382567757db92fb50 Subproject commit 63935dce34b6ef16188fe2c7b3250c2158c2b574