Started work on transformer
This commit is contained in:
parent
e464503fe1
commit
2c779cda17
2 changed files with 181 additions and 104 deletions
|
@ -6,12 +6,20 @@ import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import resonantinduction.ResonantInduction;
|
import resonantinduction.ResonantInduction;
|
||||||
import resonantinduction.multimeter.PartMultimeter.DetectMode;
|
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.MCDataInput;
|
||||||
import codechicken.lib.data.MCDataOutput;
|
import codechicken.lib.data.MCDataOutput;
|
||||||
import codechicken.lib.render.CCRenderState;
|
import codechicken.lib.render.CCRenderState;
|
||||||
|
@ -27,126 +35,195 @@ import codechicken.multipart.TFacePart;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
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];
|
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
oBoxes[0][0] = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1);
|
oBoxes[0][0] = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1);
|
||||||
oBoxes[0][1] = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D);
|
oBoxes[0][1] = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D);
|
||||||
for (int s = 1; s < 6; s++)
|
for (int s = 1; s < 6; s++)
|
||||||
{
|
{
|
||||||
Transformation t = Rotation.sideRotations[s].at(Vector3.center);
|
Transformation t = Rotation.sideRotations[s].at(Vector3.center);
|
||||||
oBoxes[s][0] = oBoxes[0][0].copy().apply(t);
|
oBoxes[s][0] = oBoxes[0][0].copy().apply(t);
|
||||||
oBoxes[s][1] = oBoxes[0][1].copy().apply(t);
|
oBoxes[s][1] = oBoxes[0][1].copy().apply(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** 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;
|
||||||
|
/** Amount to mulitply the step by (up x2. down /2) */
|
||||||
|
public int multiplier = 2;
|
||||||
|
|
||||||
public int side;
|
public void preparePlacement(int side, int itemDamage)
|
||||||
private boolean stepUp;
|
{
|
||||||
public int multiplier;
|
this.placementSide = (byte) (side ^ 1);
|
||||||
|
}
|
||||||
|
|
||||||
public void preparePlacement(int side, int itemDamage)
|
@Override
|
||||||
{
|
public void readDesc(MCDataInput packet)
|
||||||
this.side = (byte) (side ^ 1);
|
{
|
||||||
}
|
this.placementSide = packet.readByte();
|
||||||
|
this.face = packet.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readDesc(MCDataInput packet)
|
public void writeDesc(MCDataOutput packet)
|
||||||
{
|
{
|
||||||
this.side = packet.readByte();
|
packet.writeByte(this.placementSide);
|
||||||
}
|
packet.writeByte(this.face);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public boolean stepUp()
|
||||||
public void writeDesc(MCDataOutput packet)
|
{
|
||||||
{
|
return this.stepUp;
|
||||||
packet.writeByte(this.side);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean stepUp()
|
@Override
|
||||||
{
|
public int getSlotMask()
|
||||||
return this.stepUp;
|
{
|
||||||
}
|
return 1 << this.placementSide;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSlotMask()
|
public Cuboid6 getBounds()
|
||||||
{
|
{
|
||||||
return 1 << this.side;
|
return FaceMicroClass.aBounds()[0x10 | this.placementSide];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cuboid6 getBounds()
|
public int redstoneConductionMap()
|
||||||
{
|
{
|
||||||
return FaceMicroClass.aBounds()[0x10 | this.side];
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int redstoneConductionMap()
|
public boolean solid(int arg0)
|
||||||
{
|
{
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean solid(int arg0)
|
public Iterable<Cuboid6> getOcclusionBoxes()
|
||||||
{
|
{
|
||||||
return true;
|
return Arrays.asList(oBoxes[this.placementSide]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected ItemStack getItem()
|
||||||
public Iterable<Cuboid6> getOcclusionBoxes()
|
{
|
||||||
{
|
return new ItemStack(ResonantInduction.itemTransformer);
|
||||||
return Arrays.asList(oBoxes[this.side]);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected ItemStack getItem()
|
@Override
|
||||||
{
|
public Iterable<ItemStack> getDrops()
|
||||||
return new ItemStack(ResonantInduction.itemTransformer);
|
{
|
||||||
}
|
List<ItemStack> drops = new ArrayList<ItemStack>();
|
||||||
|
drops.add(getItem());
|
||||||
|
return drops;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<ItemStack> getDrops()
|
public ItemStack pickItem(MovingObjectPosition hit)
|
||||||
{
|
{
|
||||||
List<ItemStack> drops = new ArrayList<ItemStack>();
|
return getItem();
|
||||||
drops.add(getItem());
|
}
|
||||||
return drops;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack pickItem(MovingObjectPosition hit)
|
@SideOnly(Side.CLIENT)
|
||||||
{
|
public void renderDynamic(Vector3 pos, float frame, int pass)
|
||||||
return getItem();
|
{
|
||||||
}
|
if (pass == 0)
|
||||||
|
{
|
||||||
|
RenderTransformer.render(this, pos.x, pos.y, pos.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
public void load(NBTTagCompound nbt)
|
||||||
public void renderDynamic(Vector3 pos, float frame, int pass)
|
{
|
||||||
{
|
super.load(nbt);
|
||||||
if (pass == 0)
|
this.placementSide = nbt.getByte("side");
|
||||||
{
|
this.stepUp = nbt.getBoolean("stepUp");
|
||||||
RenderTransformer.render(this, pos.x, pos.y, pos.z);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(NBTTagCompound nbt)
|
public void save(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
super.load(nbt);
|
super.save(nbt);
|
||||||
this.side = nbt.getByte("side");
|
nbt.setByte("side", (byte) this.placementSide);
|
||||||
this.stepUp = nbt.getBoolean("stepUp");
|
nbt.setBoolean("stepUp", this.stepUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(NBTTagCompound nbt)
|
public String getType()
|
||||||
{
|
{
|
||||||
super.save(nbt);
|
return "resonant_induction_transformer";
|
||||||
nbt.setByte("side", (byte) this.side);
|
}
|
||||||
nbt.setBoolean("stepUp", this.stepUp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
protected ForgeDirection getFacing()
|
||||||
public String getType()
|
{
|
||||||
{
|
return ForgeDirection.NORTH;
|
||||||
return "resonant_induction_transformer";
|
}
|
||||||
}
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@ public class RenderTransformer
|
||||||
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
|
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
|
||||||
GL11.glScalef(1.0F, -1F, -1F);
|
GL11.glScalef(1.0F, -1F, -1F);
|
||||||
|
|
||||||
switch (part.side)
|
switch (part.placementSide)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
GL11.glRotatef(180, 0, 0, 1);
|
GL11.glRotatef(180, 0, 0, 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue