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?
*
* @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.
*/
@Override

View file

@ -1,15 +1,5 @@
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.lib.grid.INodeProvider;
import codechicken.lib.raytracer.IndexedCuboid6;
@ -18,12 +8,21 @@ import codechicken.lib.vec.Vector3;
import codechicken.multipart.PartMap;
import cpw.mods.fml.relauncher.Side;
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.
*
*
* @author Calclavia
*
*/
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));
}
@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()
{
super();
@ -132,12 +122,17 @@ public class PartGearShaft extends PartMechanical
@Override
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)))
return false;
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 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
protected ItemStack getItem()
{
@ -213,7 +217,9 @@ public class PartGearShaft extends PartMechanical
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if (side == placementSide || side == placementSide.getOpposite())
{
subParts.add(currentSides[side.ordinal()]);
}
}
}

View file

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

View file

@ -1,10 +1,10 @@
package resonantinduction.mechanical.process.purifier;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import calclavia.api.recipe.MachineRecipes;
import calclavia.api.resonantinduction.IMechanicalNode;
import calclavia.lib.utility.inventory.InventoryUtility;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFluid;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
@ -13,6 +13,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidBlock;
import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInduction.RecipeType;
import resonantinduction.core.Timer;
@ -20,13 +21,13 @@ import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import resonantinduction.mechanical.energy.grid.TileMechanical;
import universalelectricity.api.vector.Vector3;
import calclavia.api.recipe.MachineRecipes;
import calclavia.api.resonantinduction.IMechanicalNode;
import calclavia.lib.utility.inventory.InventoryUtility;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* @author Calclavia
*
*/
public class TileMixer extends TileMechanical implements IInventory
{
@ -57,6 +58,28 @@ public class TileMixer extends TileMechanical implements IInventory
@Override
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();
if (canWork())
@ -67,7 +90,7 @@ public class TileMixer extends TileMechanical implements IInventory
/**
* Can this machine work this tick?
*
*
* @return
*/
public boolean canWork()
@ -163,21 +186,25 @@ public class TileMixer extends TileMechanical implements IInventory
private boolean doneWork(EntityItem entity)
{
Vector3 mixPosition = new Vector3(entity.posX, yCoord, entity.posZ);
Block block = Block.blocksList[mixPosition.getBlockID(worldObj)];
if (block instanceof BlockFluidMixture)
if (mixPosition.getBlockID(world()) != blockID())
{
ItemStack itemStack = entity.getEntityItem().copy();
Block block = Block.blocksList[mixPosition.getBlockID(worldObj)];
if (((BlockFluidMixture) block).mix(worldObj, mixPosition.intX(), mixPosition.intY(), mixPosition.intZ(), itemStack))
if (block instanceof BlockFluidMixture)
{
worldObj.notifyBlocksOfNeighborChange(mixPosition.intX(), mixPosition.intY(), mixPosition.intZ(), mixPosition.getBlockID(worldObj));
return true;
ItemStack itemStack = entity.getEntityItem().copy();
if (((BlockFluidMixture) block).mix(worldObj, mixPosition.intX(), mixPosition.intY(), mixPosition.intZ(), itemStack))
{
worldObj.notifyBlocksOfNeighborChange(mixPosition.intX(), mixPosition.intY(), mixPosition.intZ(), mixPosition.getBlockID(worldObj));
return true;
}
}
else if (block != null && (block.blockID == Block.waterStill.blockID || block.blockID == Block.waterMoving.blockID))
{
mixPosition.setBlock(worldObj, ResourceGenerator.getMixture(ResourceGenerator.getName(entity.getEntityItem())).blockID);
}
}
else if (block != null && (block.blockID == Block.waterStill.blockID || block.blockID == Block.waterMoving.blockID))
{
mixPosition.setBlock(worldObj, ResourceGenerator.getMixture(ResourceGenerator.getName(entity.getEntityItem())).blockID);
}
return false;

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