Fixed grinding wheel roatations
This commit is contained in:
parent
0fd99fa04e
commit
06a9c10788
11 changed files with 173 additions and 132 deletions
|
@ -19,7 +19,7 @@ public class BlockGenerator extends BlockRIRotatable
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
|
@ -33,6 +33,7 @@ public class BlockGenerator extends BlockRIRotatable
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,125 +11,132 @@ import universalelectricity.api.vector.Vector3;
|
|||
import calclavia.lib.prefab.tile.IRotatable;
|
||||
import calclavia.lib.prefab.tile.TileElectrical;
|
||||
|
||||
/** A kinetic energy to electrical energy converter.
|
||||
/**
|
||||
* A kinetic energy to electrical energy converter.
|
||||
*
|
||||
* @author Calclavia */
|
||||
* @author Calclavia
|
||||
*/
|
||||
public class TileGenerator extends TileElectrical implements IMechanical, IRotatable
|
||||
{
|
||||
/** Generator turns KE -> EE. Inverted one will turn EE -> KE. */
|
||||
public boolean isInversed = false;
|
||||
/** Generator turns KE -> EE. Inverted one will turn EE -> KE. */
|
||||
public boolean isInversed = false;
|
||||
|
||||
private float torqueRatio = 8000;
|
||||
private float torqueRatio = 8000;
|
||||
|
||||
public TileGenerator()
|
||||
{
|
||||
energy = new EnergyStorageHandler(10000);
|
||||
this.ioMap = 728;
|
||||
}
|
||||
public TileGenerator()
|
||||
{
|
||||
energy = new EnergyStorageHandler(10000);
|
||||
this.ioMap = 728;
|
||||
}
|
||||
|
||||
public float toggleRatio()
|
||||
{
|
||||
return torqueRatio = (torqueRatio + 1000) % energy.getMaxExtract();
|
||||
}
|
||||
public float toggleRatio()
|
||||
{
|
||||
return torqueRatio = (torqueRatio + 1000) % energy.getMaxExtract();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (this.isFunctioning())
|
||||
{
|
||||
if (!isInversed)
|
||||
{
|
||||
this.produce();
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 outputVector = new Vector3(this).modifyPositionFromSide(this.getDirection().getOpposite());
|
||||
TileEntity mechanical = outputVector.getTileEntity(worldObj);
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (this.isFunctioning())
|
||||
{
|
||||
if (!isInversed)
|
||||
{
|
||||
produce();
|
||||
}
|
||||
else
|
||||
{
|
||||
produceMechanical(new Vector3(this).modifyPositionFromSide(this.getDirection()));
|
||||
produceMechanical(new Vector3(this).modifyPositionFromSide(this.getDirection().getOpposite()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mechanical instanceof IMechanical)
|
||||
{
|
||||
long extract = energy.extractEnergy();
|
||||
public void produceMechanical(Vector3 outputVector)
|
||||
{
|
||||
TileEntity mechanical = outputVector.getTileEntity(worldObj);
|
||||
|
||||
if (extract > 0)
|
||||
{
|
||||
float angularVelocity = extract / torqueRatio;
|
||||
long torque = (long) (extract / angularVelocity);
|
||||
((IMechanical) mechanical).onReceiveEnergy(this.getDirection().getOpposite(), torque, angularVelocity, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mechanical instanceof IMechanical)
|
||||
{
|
||||
long extract = energy.extractEnergy();
|
||||
|
||||
if (extract > 0)
|
||||
{
|
||||
float angularVelocity = extract / torqueRatio;
|
||||
long torque = (long) (extract / angularVelocity);
|
||||
((IMechanical) mechanical).onReceiveEnergy(this.getDirection().getOpposite(), torque, angularVelocity, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getInputDirections()
|
||||
{
|
||||
return this.getOutputDirections();
|
||||
}
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getInputDirections()
|
||||
{
|
||||
return this.getOutputDirections();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getOutputDirections()
|
||||
{
|
||||
EnumSet<ForgeDirection> dirs = EnumSet.allOf(ForgeDirection.class);
|
||||
dirs.remove(this.getDirection());
|
||||
dirs.remove(this.getDirection().ordinal());
|
||||
return dirs;
|
||||
}
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getOutputDirections()
|
||||
{
|
||||
EnumSet<ForgeDirection> dirs = EnumSet.allOf(ForgeDirection.class);
|
||||
dirs.remove(this.getDirection());
|
||||
dirs.remove(this.getDirection().ordinal());
|
||||
return dirs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getDirection()
|
||||
{
|
||||
return ForgeDirection.getOrientation(this.getBlockMetadata());
|
||||
}
|
||||
@Override
|
||||
public ForgeDirection getDirection()
|
||||
{
|
||||
return ForgeDirection.getOrientation(this.getBlockMetadata());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(ForgeDirection dir)
|
||||
{
|
||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, dir.ordinal(), 3);
|
||||
@Override
|
||||
public void setDirection(ForgeDirection dir)
|
||||
{
|
||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, dir.ordinal(), 3);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFunctioning()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private boolean isFunctioning()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onReceiveEnergy(ForgeDirection from, long torque, float angularVelocity, boolean doReceive)
|
||||
{
|
||||
if (!this.isInversed)
|
||||
{
|
||||
return energy.receiveEnergy((long) (torque * angularVelocity), doReceive);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long onReceiveEnergy(ForgeDirection from, long torque, float angularVelocity, boolean doReceive)
|
||||
{
|
||||
if (!this.isInversed)
|
||||
{
|
||||
return energy.receiveEnergy((long) (torque * angularVelocity), doReceive);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
isInversed = nbt.getBoolean("isInversed");
|
||||
torqueRatio = nbt.getFloat("torqueRatio");
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
isInversed = nbt.getBoolean("isInversed");
|
||||
torqueRatio = nbt.getFloat("torqueRatio");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setBoolean("isInversed", isInversed);
|
||||
nbt.setFloat("torqueRatio", torqueRatio);
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setBoolean("isInversed", isInversed);
|
||||
nbt.setFloat("torqueRatio", torqueRatio);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
{
|
||||
@Override
|
||||
public void setClockwise(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package resonantinduction.mechanical.fluid.pipe;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -199,4 +200,18 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe,
|
|||
return FluidContainerRegistry.BUCKET_VOLUME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.save(nbt);
|
||||
nbt.setBoolean("isExtracting", isInsulated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.load(nbt);
|
||||
isExtracting= nbt.getBoolean("isExtracting");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +1,11 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.network.IMechanical;
|
||||
import resonantinduction.mechanical.network.IMechanicalConnector;
|
||||
import resonantinduction.mechanical.network.IMechanicalNetwork;
|
||||
import resonantinduction.mechanical.network.MechanicalNetwork;
|
||||
import resonantinduction.mechanical.network.PartMechanical;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Transformation;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.microblock.FaceMicroClass;
|
||||
import codechicken.multipart.JNormalOcclusion;
|
||||
import codechicken.multipart.TFacePart;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -43,16 +22,16 @@ public class PartGear extends PartMechanical
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
super.update();
|
||||
|
||||
if (!this.world().isRemote)
|
||||
{
|
||||
if (manualCrankTime > 0)
|
||||
{
|
||||
onReceiveEnergy(null, 20, 0.3f, true);
|
||||
onReceiveEnergy(null, 20, 0.2f, true);
|
||||
manualCrankTime--;
|
||||
}
|
||||
}
|
||||
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,5 +18,5 @@ public interface IMechanical extends IConnectable
|
|||
|
||||
public boolean isClockwise();
|
||||
|
||||
public void setRotation(boolean isClockwise);
|
||||
public void setClockwise(boolean isClockwise);
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
public void setClockwise(boolean isClockwise)
|
||||
{
|
||||
this.isClockwise = isClockwise;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class TileMechanical extends TileAdvanced implements IMechanicalConnector
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
public void setClockwise(boolean isClockwise)
|
||||
{
|
||||
this.isClockwise = isClockwise;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,17 @@ public class RenderGrinderWheel extends TileEntitySpecialRenderer
|
|||
TileGrinderWheel tile = (TileGrinderWheel) t;
|
||||
glPushMatrix();
|
||||
glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F);
|
||||
glScalef(0.5f, 0.5f, 0.515f);
|
||||
glRotatef((float) Math.toDegrees(tile.getNetwork().getRotation()), 0, 0, 1);
|
||||
glScalef(0.51f, 0.51f, 0.51f);
|
||||
|
||||
if (tile.getDirection().ordinal() < 2)
|
||||
glRotatef(90, 1, 0, 0);
|
||||
else if (tile.getDirection().ordinal() == 2 || tile.getDirection().ordinal() == 3)
|
||||
glRotatef(90, 0, 1, 0);
|
||||
else if (tile.getDirection().ordinal() == 4 || tile.getDirection().ordinal() == 5)
|
||||
glRotatef(180, 0, 1, 0);
|
||||
|
||||
glRotatef((float) Math.toDegrees(tile.getNetwork().getRotation()) * (tile.isClockwise() ? 1 : -1), 0, 0, 1);
|
||||
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
MODEL.renderAll();
|
||||
glPopMatrix();
|
||||
|
|
|
@ -2,9 +2,11 @@ package resonantinduction.mechanical.process;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import calclavia.lib.prefab.tile.IRotatable;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.api.recipe.MachineRecipes;
|
||||
import resonantinduction.api.recipe.MachineRecipes.RecipeType;
|
||||
import resonantinduction.api.recipe.RecipeUtils.ItemStackResource;
|
||||
|
@ -20,7 +22,7 @@ import cpw.mods.fml.relauncher.Side;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileGrinderWheel extends TileMechanical
|
||||
public class TileGrinderWheel extends TileMechanical implements IRotatable
|
||||
{
|
||||
public static final long POWER = 500000;
|
||||
public static final int DEFAULT_TIME = 20 * 20;
|
||||
|
@ -157,4 +159,32 @@ public class TileGrinderWheel extends TileMechanical
|
|||
|
||||
return clientTimer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClockwise()
|
||||
{
|
||||
if (worldObj != null)
|
||||
{
|
||||
return !(getBlockMetadata() % 2 == 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getDirection()
|
||||
{
|
||||
if (worldObj != null)
|
||||
{
|
||||
return ForgeDirection.getOrientation(getBlockMetadata());
|
||||
}
|
||||
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(ForgeDirection direction)
|
||||
{
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class TraitMechanical extends TileMultipart implements IMechanical
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
public void setClockwise(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class TraitMechanicalConnector extends TileMultipart implements IMechanic
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(boolean isClockwise)
|
||||
public void setClockwise(boolean isClockwise)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue