Started work on transformer

This commit is contained in:
DarkGaurdsman 2013-12-28 23:36:57 -05:00
parent e464503fe1
commit 2c779cda17
2 changed files with 181 additions and 104 deletions

View file

@ -6,12 +6,20 @@ import java.util.List;
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 org.lwjgl.opengl.GL11;
import resonantinduction.ResonantInduction;
import resonantinduction.multimeter.PartMultimeter.DetectMode;
import universalelectricity.api.electricity.IElectricalNetwork;
import universalelectricity.api.electricity.IVoltageInput;
import universalelectricity.api.electricity.IVoltageOutput;
import universalelectricity.api.energy.IConductor;
import universalelectricity.api.energy.IEnergyInterface;
import universalelectricity.api.vector.VectorHelper;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.render.CCRenderState;
@ -27,7 +35,7 @@ import codechicken.multipart.TFacePart;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TFacePart
public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TFacePart, IVoltageOutput, IEnergyInterface
{
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
@ -42,26 +50,32 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
oBoxes[s][1] = oBoxes[0][1].copy().apply(t);
}
}
public int side;
/** Side of the block this is placed on */
public int placementSide;
/** Direction this block faces */
public int face = 0;
/** Step the voltage up */
private boolean stepUp;
public int multiplier;
/** Amount to mulitply the step by (up x2. down /2) */
public int multiplier = 2;
public void preparePlacement(int side, int itemDamage)
{
this.side = (byte) (side ^ 1);
this.placementSide = (byte) (side ^ 1);
}
@Override
public void readDesc(MCDataInput packet)
{
this.side = packet.readByte();
this.placementSide = packet.readByte();
this.face = packet.readByte();
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte(this.side);
packet.writeByte(this.placementSide);
packet.writeByte(this.face);
}
public boolean stepUp()
@ -72,13 +86,13 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
@Override
public int getSlotMask()
{
return 1 << this.side;
return 1 << this.placementSide;
}
@Override
public Cuboid6 getBounds()
{
return FaceMicroClass.aBounds()[0x10 | this.side];
return FaceMicroClass.aBounds()[0x10 | this.placementSide];
}
@Override
@ -96,7 +110,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
@Override
public Iterable<Cuboid6> getOcclusionBoxes()
{
return Arrays.asList(oBoxes[this.side]);
return Arrays.asList(oBoxes[this.placementSide]);
}
protected ItemStack getItem()
@ -132,7 +146,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
public void load(NBTTagCompound nbt)
{
super.load(nbt);
this.side = nbt.getByte("side");
this.placementSide = nbt.getByte("side");
this.stepUp = nbt.getBoolean("stepUp");
}
@ -140,7 +154,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setByte("side", (byte) this.side);
nbt.setByte("side", (byte) this.placementSide);
nbt.setBoolean("stepUp", this.stepUp);
}
@ -149,4 +163,67 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
{
return "resonant_induction_transformer";
}
protected ForgeDirection getFacing()
{
return ForgeDirection.NORTH;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return direction == getFacing() || direction == getFacing().getOpposite();
}
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
if (from == this.getFacing().getOpposite())
{
TileEntity entity = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(this.x(), this.y(), this.z()), this.getFacing());
if (entity instanceof IEnergyInterface)
{
if (entity instanceof IVoltageInput)
{
long voltage = this.getVoltageOutput(from.getOpposite());
if (voltage != ((IVoltageInput) entity).getVoltageInput(from))
{
((IVoltageInput) entity).onWrongVoltage(from, voltage);
}
}
return ((IEnergyInterface) entity).onReceiveEnergy(from, receive, doReceive);
}
}
return 0;
}
@Override
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
{
return 0;
}
@Override
public long getVoltageOutput(ForgeDirection side)
{
TileEntity entity = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(this.x(), this.y(), this.z()), this.getFacing().getOpposite());
if (entity instanceof IConductor && ((IConductor) entity).getNetwork() instanceof IElectricalNetwork)
{
long voltage = ((IElectricalNetwork) ((IConductor) entity).getNetwork()).getVoltage();
if (this.stepUp())
{
return voltage * this.multiplier;
}
else if (voltage > 0)
{
return voltage / this.multiplier;
}
}
else if (entity instanceof IVoltageOutput)
{
return ((IVoltageOutput) entity).getVoltageOutput(side);
}
return 0;
}
}

View file

@ -43,7 +43,7 @@ public class RenderTransformer
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
switch (part.side)
switch (part.placementSide)
{
case 1:
GL11.glRotatef(180, 0, 0, 1);