Added large gears
This commit is contained in:
parent
497d566bfa
commit
152051801a
11 changed files with 299 additions and 92 deletions
|
@ -62,12 +62,16 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
|||
if (tile instanceof IMechanical)
|
||||
{
|
||||
IMechanical mech = ((IMechanical) tile).getInstance(inputDir.getOpposite());
|
||||
long receive = energy.receiveEnergy((long) Math.abs(mech.getTorque() * mech.getAngularVelocity()), true);
|
||||
|
||||
if (receive > 0)
|
||||
if (mech != null)
|
||||
{
|
||||
mech.setTorque((long) (mech.getTorque() * 0.5));
|
||||
mech.setAngularVelocity(mech.getAngularVelocity() * 0.5f);
|
||||
long receive = energy.receiveEnergy((long) Math.abs(mech.getTorque() * mech.getAngularVelocity()), true);
|
||||
|
||||
if (receive > 0)
|
||||
{
|
||||
mech.setTorque((long) (mech.getTorque() * 0.5));
|
||||
mech.setAngularVelocity(mech.getAngularVelocity() * 0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +104,7 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
|||
setTorque = (long) Math.max(setTorque, currentTorque * (currentTorque / maxTorque));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float currentVelo = Math.abs(mech.getAngularVelocity());
|
||||
if (currentVelo != 0)
|
||||
setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (mech.getAngularVelocity() / currentVelo);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.multiblock.reference.IMultiBlockStructure;
|
||||
import calclavia.lib.multiblock.reference.MultiBlockHandler;
|
||||
|
||||
public class MultiPartMultiBlockHandler extends MultiBlockHandler<PartGear>
|
||||
{
|
||||
public MultiPartMultiBlockHandler(PartGear wrapper)
|
||||
{
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
public PartGear getWrapperAt(Vector3 position)
|
||||
{
|
||||
TileEntity tile = position.getTileEntity(self.getWorld());
|
||||
|
||||
if (tile instanceof TileMultipart)
|
||||
{
|
||||
TMultiPart part = ((TileMultipart) tile).partMap(getPlacementSide().ordinal());
|
||||
|
||||
if (part instanceof PartGear)
|
||||
{
|
||||
return (PartGear) part;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ForgeDirection getPlacementSide()
|
||||
{
|
||||
return self.placementSide;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,29 @@
|
|||
package resonantinduction.mechanical.gear;
|
||||
|
||||
import calclavia.lib.prefab.block.BlockAdvanced;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
|
||||
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.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import resonantinduction.mechanical.network.IMechanical;
|
||||
import resonantinduction.mechanical.network.IMechanicalNetwork;
|
||||
import resonantinduction.mechanical.network.PartMechanical;
|
||||
import calclavia.lib.multiblock.reference.IMultiBlockStructure;
|
||||
import calclavia.lib.multiblock.reference.MultiBlockHandler;
|
||||
import calclavia.lib.network.PacketHandler;
|
||||
import calclavia.lib.prefab.block.BlockAdvanced;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.vec.Rotation;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -19,7 +33,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class PartGear extends PartMechanical implements IMechanical
|
||||
public class PartGear extends PartMechanical implements IMechanical, IMultiBlockStructure<PartGear>
|
||||
{
|
||||
private int manualCrankTime = 0;
|
||||
|
||||
|
@ -38,7 +52,8 @@ public class PartGear extends PartMechanical implements IMechanical
|
|||
manualCrankTime--;
|
||||
}
|
||||
|
||||
angularVelocity *= 0.95f;
|
||||
if (getMultiBlock().isPrimary())
|
||||
angularVelocity *= 0.95f;
|
||||
}
|
||||
|
||||
super.update();
|
||||
|
@ -53,14 +68,17 @@ public class PartGear extends PartMechanical implements IMechanical
|
|||
{
|
||||
if (!world().isRemote)
|
||||
{
|
||||
angularVelocity = -angularVelocity;
|
||||
getMultiBlock().get().angularVelocity = -angularVelocity;
|
||||
player.addChatMessage("Flipped gear to rotate " + (angularVelocity > 0 ? "clockwise" : "anticlockwise") + ".");
|
||||
}
|
||||
}
|
||||
else if (ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
getMultiBlock().get().manualCrankTime = 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
this.manualCrankTime = 10;
|
||||
getMultiBlock().toggleConstruct();
|
||||
}
|
||||
|
||||
BlockAdvanced.damageWrench(player, player.getCurrentEquippedItem(), x(), y(), z());
|
||||
|
@ -70,6 +88,90 @@ public class PartGear extends PartMechanical implements IMechanical
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preRemove()
|
||||
{
|
||||
super.preRemove();
|
||||
getMultiBlock().deconstruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh should be called sparingly.
|
||||
*/
|
||||
public void refresh()
|
||||
{
|
||||
connections = new Object[6];
|
||||
|
||||
if (!getMultiBlock().isPrimary())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/** Look for gears that are back-to-back with this gear. Equate torque. */
|
||||
TileEntity tileBehind = new universalelectricity.api.vector.Vector3(tile()).translate(placementSide).getTileEntity(world());
|
||||
|
||||
if (tileBehind instanceof IMechanical)
|
||||
{
|
||||
IMechanical instance = (IMechanical) ((IMechanical) tileBehind).getInstance(placementSide.getOpposite());
|
||||
|
||||
if (instance != null && instance.canConnect(placementSide))
|
||||
{
|
||||
connections[placementSide.getOpposite().ordinal()] = instance;
|
||||
getNetwork().merge(instance.getNetwork());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!getMultiBlock().isConstructed())
|
||||
{
|
||||
/** Look for gears that are internal and adjacent to this gear. (The 4 sides) */
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
|
||||
IMechanical instance = ((IMechanical) tile()).getInstance(checkDir);
|
||||
|
||||
if (connections[checkDir.ordinal()] == null && checkDir != placementSide && checkDir != placementSide.getOpposite() && instance != null && instance.canConnect(checkDir.getOpposite()))
|
||||
{
|
||||
connections[checkDir.ordinal()] = instance;
|
||||
getNetwork().merge(instance.getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int displaceCheck = 1;
|
||||
|
||||
if (getMultiBlock().isPrimary() && getMultiBlock().isConstructed())
|
||||
{
|
||||
displaceCheck = 2;
|
||||
}
|
||||
|
||||
/** Look for gears outside this block space, the relative UP, DOWN, LEFT, RIGHT */
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(this.placementSide.ordinal(), i));
|
||||
TileEntity checkTile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir, displaceCheck).getTileEntity(world());
|
||||
|
||||
if (connections[checkDir.ordinal()] == null && checkTile instanceof IMechanical)
|
||||
{
|
||||
IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(placementSide);
|
||||
|
||||
if (instance != null && instance.canConnect(placementSide.getOpposite()))
|
||||
{
|
||||
connections[checkDir.ordinal()] = instance;
|
||||
getNetwork().merge(instance.getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getNetwork().reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
return getMultiBlock().get().connections;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getItem()
|
||||
{
|
||||
|
@ -91,4 +193,96 @@ public class PartGear extends PartMechanical implements IMechanical
|
|||
{
|
||||
return "resonant_induction_gear";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.load(nbt);
|
||||
|
||||
if (tile() != null)
|
||||
getMultiBlock().load(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.save(nbt);
|
||||
getMultiBlock().save(this, nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiblock
|
||||
*/
|
||||
private MultiPartMultiBlockHandler multiBlock;
|
||||
|
||||
@Override
|
||||
public universalelectricity.api.vector.Vector3[] getMultiBlockVectors()
|
||||
{
|
||||
Set<universalelectricity.api.vector.Vector3> vectors = new HashSet<universalelectricity.api.vector.Vector3>();
|
||||
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
vectors.add(new universalelectricity.api.vector.Vector3(x, 0, z));
|
||||
}
|
||||
}
|
||||
|
||||
return vectors.toArray(new universalelectricity.api.vector.Vector3[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return world();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultiBlockChanged()
|
||||
{
|
||||
if (!world().isRemote)
|
||||
{
|
||||
refresh();
|
||||
tile().notifyPartChange(this);
|
||||
sendDescUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiBlockHandler<PartGear> getMultiBlock()
|
||||
{
|
||||
if (multiBlock == null)
|
||||
multiBlock = new MultiPartMultiBlockHandler(this);
|
||||
|
||||
return multiBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public universalelectricity.api.vector.Vector3 getPosition()
|
||||
{
|
||||
return new universalelectricity.api.vector.Vector3(x(), y(), z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio(ForgeDirection dir)
|
||||
{
|
||||
if (dir == placementSide)
|
||||
{
|
||||
return super.getRatio(dir);
|
||||
}
|
||||
|
||||
return getMultiBlock().isConstructed() ? 1.5f : super.getRatio(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMechanical getInstance(ForgeDirection from)
|
||||
{
|
||||
if(!getMultiBlock().isPrimary() && from == placementSide)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getMultiBlock().get();
|
||||
}
|
||||
|
||||
}
|
|
@ -30,18 +30,26 @@ public class RenderGear
|
|||
|
||||
public void renderDynamic(PartGear part, double x, double y, double z, float frame)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
// Center the model first.
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||
GL11.glPushMatrix();
|
||||
if (part.getMultiBlock().isPrimary())
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
// Center the model first.
|
||||
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
||||
GL11.glPushMatrix();
|
||||
|
||||
RenderUtility.rotateFaceBlockToSide(part.placementSide);
|
||||
RenderUtility.rotateFaceBlockToSide(part.placementSide);
|
||||
|
||||
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
|
||||
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
|
||||
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
MODEL.renderAll();
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopMatrix();
|
||||
if (part.getMultiBlock().isConstructed())
|
||||
{
|
||||
GL11.glScalef(3, 1, 3);
|
||||
}
|
||||
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
MODEL.renderAll();
|
||||
GL11.glPopMatrix();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ public interface IMechanical extends IConnector<IMechanicalNetwork>
|
|||
|
||||
public void setTorque(long torque);
|
||||
|
||||
public float getRatio();
|
||||
public float getRatio(ForgeDirection dir);
|
||||
|
||||
public IMechanical getInstance(ForgeDirection dir);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
|
|||
|
||||
if (adjacentMech != null)
|
||||
{
|
||||
float ratio = adjacentMech.getRatio() / mechanical.getRatio();
|
||||
float ratio = adjacentMech.getRatio(dir) / mechanical.getRatio(dir.getOpposite());
|
||||
long torque = mechanical.getTorque();
|
||||
|
||||
if (Math.abs(torque - adjacentMech.getTorque() / ratio * ACCELERATION) < Math.abs(adjacentMech.getTorque() / ratio))
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import calclavia.lib.network.PacketHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -123,60 +124,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh should be called sparingly.
|
||||
*/
|
||||
public void refresh()
|
||||
{
|
||||
connections = new Object[6];
|
||||
|
||||
/** Look for gears that are back-to-back with this gear. Equate torque. */
|
||||
TileEntity tileBehind = new universalelectricity.api.vector.Vector3(tile()).translate(placementSide).getTileEntity(world());
|
||||
|
||||
if (tileBehind instanceof IMechanical)
|
||||
{
|
||||
IMechanical instance = (IMechanical) ((IMechanical) tileBehind).getInstance(placementSide.getOpposite());
|
||||
|
||||
if (instance != null && instance.canConnect(placementSide))
|
||||
{
|
||||
connections[placementSide.getOpposite().ordinal()] = instance;
|
||||
getNetwork().merge(instance.getNetwork());
|
||||
}
|
||||
|
||||
}
|
||||
/** Look for gears that are internal and adjacent to this gear. (The 4 sides) */
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection checkDir = ForgeDirection.getOrientation(i);
|
||||
IMechanical instance = (IMechanical) ((IMechanical) tile()).getInstance(checkDir);
|
||||
|
||||
if (connections[checkDir.ordinal()] == null && checkDir != placementSide && checkDir != placementSide.getOpposite() && instance != null && instance.canConnect(checkDir.getOpposite()))
|
||||
{
|
||||
connections[checkDir.ordinal()] = instance;
|
||||
getNetwork().merge(instance.getNetwork());
|
||||
}
|
||||
}
|
||||
|
||||
/** Look for gears outside this block space, the relative UP, DOWN, LEFT, RIGHT */
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ForgeDirection checkDir = ForgeDirection.getOrientation(Rotation.rotateSide(this.placementSide.ordinal(), i));
|
||||
TileEntity checkTile = new universalelectricity.api.vector.Vector3(tile()).translate(checkDir).getTileEntity(world());
|
||||
|
||||
if (connections[checkDir.ordinal()] == null && checkTile instanceof IMechanical)
|
||||
{
|
||||
IMechanical instance = (IMechanical) ((IMechanical) checkTile).getInstance(placementSide);
|
||||
|
||||
if (instance != null && instance.canConnect(placementSide.getOpposite()))
|
||||
{
|
||||
connections[checkDir.ordinal()] = instance;
|
||||
getNetwork().merge(instance.getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getNetwork().reconstruct();
|
||||
}
|
||||
protected abstract void refresh();
|
||||
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
|
@ -193,17 +141,24 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
/** Packet Code. */
|
||||
public void sendRotationPacket()
|
||||
{
|
||||
if (world() != null && !world().isRemote && tile() != null)
|
||||
if (world() != null && !world().isRemote)
|
||||
{
|
||||
tile().getWriteStream(this).writeByte(0).writeFloat(angularVelocity);
|
||||
sendDescUpdate();
|
||||
// TODO: Make packets more efficient.
|
||||
// getWriteStream().writeByte(1).writeFloat(angularVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
public void read(MCDataInput packet, int packetID)
|
||||
{
|
||||
if (packetID == 0)
|
||||
switch (packetID)
|
||||
{
|
||||
angularVelocity = packet.readFloat();
|
||||
case 0:
|
||||
readDesc(packet);
|
||||
break;
|
||||
case 1:
|
||||
angularVelocity = packet.readFloat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,19 +166,23 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
this.placementSide = ForgeDirection.getOrientation(packet.readByte());
|
||||
load(packet.readNBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(this.placementSide.ordinal());
|
||||
// packet.writeByte(0);
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
save(nbt);
|
||||
packet.writeNBTTagCompound(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(MCDataInput packet)
|
||||
{
|
||||
read(packet, packet.readUByte());
|
||||
super.read(packet);
|
||||
// read(packet, packet.readUByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -263,15 +222,15 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
super.load(nbt);
|
||||
this.placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
||||
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
|
||||
angularVelocity = nbt.getFloat("angularVelocity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
super.save(nbt);
|
||||
nbt.setByte("side", (byte) this.placementSide.ordinal());
|
||||
nbt.setByte("side", (byte) placementSide.ordinal());
|
||||
nbt.setFloat("angularVelocity", angularVelocity);
|
||||
}
|
||||
|
||||
protected abstract ItemStack getItem();
|
||||
|
@ -341,7 +300,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
|
|||
}
|
||||
|
||||
@Override
|
||||
public float getRatio()
|
||||
public float getRatio(ForgeDirection dir)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public abstract class TileMechanical extends TileAdvanced implements IMechanical
|
|||
}
|
||||
|
||||
@Override
|
||||
public float getRatio()
|
||||
public float getRatio(ForgeDirection dir)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,10 @@ public class TileMixer extends TileMechanical
|
|||
{
|
||||
super.updateEntity();
|
||||
|
||||
counter = Math.max(counter + torque, 0);
|
||||
|
||||
if (canWork())
|
||||
{
|
||||
counter = Math.max(counter + torque, 0);
|
||||
doWork();
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +155,8 @@ public class TileMixer extends TileMechanical
|
|||
{
|
||||
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "mixer", 0.5f, 1);
|
||||
}
|
||||
|
||||
counter-=requiredTorque;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 349 B After Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in a new issue