Finished transformers complex multi side rotation

This commit is contained in:
DarkGuardsman 2014-01-06 23:33:57 -05:00
parent 2da3f0fdca
commit 4d4c437ac2
2 changed files with 447 additions and 210 deletions

View file

@ -1,12 +1,15 @@
package resonantinduction.transport.transformer; package resonantinduction.transport.transformer;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
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.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
@ -31,193 +34,339 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TFacePart, IVoltageOutput, IEnergyInterface 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 */ /** Side of the block this is placed on */
public int placementSide; public ForgeDirection placementSide;
/** Direction this block faces */ /** Direction this block faces */
public int face = 0; public byte face = 0;
/** Step the voltage up */ /** Step the voltage up */
private boolean stepUp; private boolean stepUp;
/** Amount to mulitply the step by (up x2. down /2) */ /** Amount to mulitply the step by (up x2. down /2) */
public int multiplier = 2; public int multiplier = 2;
public void preparePlacement(int side, int itemDamage) public void preparePlacement(int side, int itemDamage)
{ {
this.placementSide = (byte) (side ^ 1); this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1));
} }
@Override @Override
public void readDesc(MCDataInput packet) public void readDesc(MCDataInput packet)
{ {
this.placementSide = packet.readByte(); this.placementSide = ForgeDirection.getOrientation(packet.readByte());
this.face = packet.readByte(); this.face = packet.readByte();
} }
@Override @Override
public void writeDesc(MCDataOutput packet) public void writeDesc(MCDataOutput packet)
{ {
packet.writeByte(this.placementSide); packet.writeByte(this.placementSide.ordinal());
packet.writeByte(this.face); packet.writeByte(this.face);
} }
public boolean stepUp() public boolean stepUp()
{ {
return this.stepUp; return this.stepUp;
} }
@Override @Override
public int getSlotMask() public int getSlotMask()
{ {
return 1 << this.placementSide; return 1 << this.placementSide.ordinal();
} }
@Override @Override
public Cuboid6 getBounds() public Cuboid6 getBounds()
{ {
return FaceMicroClass.aBounds()[0x10 | this.placementSide]; return FaceMicroClass.aBounds()[0x10 | this.placementSide.ordinal()];
} }
@Override @Override
public int redstoneConductionMap() public int redstoneConductionMap()
{ {
return 0; return 0;
} }
@Override @Override
public boolean solid(int arg0) public boolean solid(int arg0)
{ {
return true; return true;
} }
@Override @Override
public Iterable<Cuboid6> getOcclusionBoxes() public Iterable<Cuboid6> getOcclusionBoxes()
{ {
return Arrays.asList(oBoxes[this.placementSide]); return Arrays.asList(oBoxes[this.placementSide.ordinal()]);
} }
protected ItemStack getItem() protected ItemStack getItem()
{ {
return new ItemStack(ResonantInduction.itemTransformer); return new ItemStack(ResonantInduction.itemTransformer);
} }
@Override @Override
public Iterable<ItemStack> getDrops() public Iterable<ItemStack> getDrops()
{ {
List<ItemStack> drops = new ArrayList<ItemStack>(); List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem()); drops.add(getItem());
return drops; return drops;
} }
@Override @Override
public ItemStack pickItem(MovingObjectPosition hit) public ItemStack pickItem(MovingObjectPosition hit)
{ {
return getItem(); return getItem();
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderDynamic(Vector3 pos, float frame, int pass) public void renderDynamic(Vector3 pos, float frame, int pass)
{ {
if (pass == 0) if (pass == 0)
{ {
RenderTransformer.render(this, pos.x, pos.y, pos.z); RenderTransformer.render(this, pos.x, pos.y, pos.z);
} }
} }
@Override @Override
public void load(NBTTagCompound nbt) public void load(NBTTagCompound nbt)
{ {
super.load(nbt); super.load(nbt);
this.placementSide = nbt.getByte("side"); this.placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
this.stepUp = nbt.getBoolean("stepUp"); this.stepUp = nbt.getBoolean("stepUp");
} }
@Override @Override
public void save(NBTTagCompound nbt) public void save(NBTTagCompound nbt)
{ {
super.save(nbt); super.save(nbt);
nbt.setByte("side", (byte) this.placementSide); nbt.setByte("side", (byte) this.placementSide.ordinal());
nbt.setBoolean("stepUp", this.stepUp); nbt.setBoolean("stepUp", this.stepUp);
} }
@Override @Override
public String getType() public String getType()
{ {
return "resonant_induction_transformer"; return "resonant_induction_transformer";
} }
protected ForgeDirection getFacing() protected ForgeDirection getFacing()
{ {
return ForgeDirection.NORTH; if (this.placementSide != ForgeDirection.UP && this.placementSide != ForgeDirection.DOWN)
} {
switch (this.face)
{
case 0:
return ForgeDirection.UP;
case 1:
switch (this.placementSide)
{
case NORTH:
return ForgeDirection.EAST;
case SOUTH:
return ForgeDirection.WEST;
case EAST:
return ForgeDirection.SOUTH;
case WEST:
return ForgeDirection.NORTH;
}
case 2:
return ForgeDirection.DOWN;
case 3:
switch (this.placementSide)
{
case NORTH:
return ForgeDirection.WEST;
case SOUTH:
return ForgeDirection.EAST;
case EAST:
return ForgeDirection.NORTH;
case WEST:
return ForgeDirection.SOUTH;
}
}
}
else
{
switch (this.face)
{
case 0:
return ForgeDirection.NORTH;
case 1:
return ForgeDirection.EAST;
case 2:
return ForgeDirection.SOUTH;
case 3:
return ForgeDirection.WEST;
}
}
return ForgeDirection.NORTH;
}
@Override @Override
public boolean canConnect(ForgeDirection direction) public boolean canConnect(ForgeDirection direction)
{ {
return direction == getFacing() || direction == getFacing().getOpposite(); return direction == getFacing() || direction == getFacing().getOpposite();
} }
@Override @Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{ {
if (from == this.getFacing().getOpposite()) if (from == this.getFacing().getOpposite())
{ {
TileEntity entity = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(this.x(), this.y(), this.z()), this.getFacing()); 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 IEnergyInterface)
{ {
if (entity instanceof IVoltageInput) if (entity instanceof IVoltageInput)
{ {
long voltage = this.getVoltageOutput(from.getOpposite()); long voltage = this.getVoltageOutput(from.getOpposite());
if (voltage != ((IVoltageInput) entity).getVoltageInput(from)) if (voltage != ((IVoltageInput) entity).getVoltageInput(from))
{ {
((IVoltageInput) entity).onWrongVoltage(from, voltage); ((IVoltageInput) entity).onWrongVoltage(from, voltage);
} }
} }
return ((IEnergyInterface) entity).onReceiveEnergy(from, receive, doReceive); return ((IEnergyInterface) entity).onReceiveEnergy(from, receive, doReceive);
} }
} }
return 0; return 0;
} }
@Override @Override
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract) public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
{ {
return 0; return 0;
} }
@Override @Override
public long getVoltageOutput(ForgeDirection side) 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 (side == this.getFacing())
if (entity instanceof IConductor && ((IConductor) entity).getNetwork() instanceof IElectricalNetwork) {
{ TileEntity entity = VectorHelper.getTileEntityFromSide(this.world(), new universalelectricity.api.vector.Vector3(this.x(), this.y(), this.z()), this.getFacing().getOpposite());
long voltage = ((IElectricalNetwork) ((IConductor) entity).getNetwork()).getVoltage(); if (entity instanceof IConductor && ((IConductor) entity).getNetwork() instanceof IElectricalNetwork)
if (this.stepUp()) {
{ long voltage = ((IElectricalNetwork) ((IConductor) entity).getNetwork()).getVoltage();
return voltage * this.multiplier; if (this.stepUp())
} {
else if (voltage > 0) return voltage * this.multiplier;
{ }
return voltage / this.multiplier; else if (voltage > 0)
} {
} return voltage / this.multiplier;
else if (entity instanceof IVoltageOutput) }
{ }
return ((IVoltageOutput) entity).getVoltageOutput(side); else if (entity instanceof IVoltageOutput)
} {
return 0; return ((IVoltageOutput) entity).getVoltageOutput(side);
} }
}
return 0;
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item)
{
if (this.isUsableWrench(player, player.inventory.getCurrentItem(), x(), y(), z()))
{
if (this.world().isRemote)
{
return true;
}
this.damageWrench(player, player.inventory.getCurrentItem(), x(), y(), z());
if (this.face < 3)
this.face++;
else
this.face = 0;
this.sendDescUpdate();
player.sendChatToPlayer(ChatMessageComponent.createFromText("Face:" + this.face));
return true;
}
return false;
}
public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
{
if (entityPlayer != null && itemStack != null)
{
Class wrenchClass = itemStack.getItem().getClass();
/** UE and Buildcraft */
try
{
Method methodCanWrench = wrenchClass.getMethod("canWrench", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
return (Boolean) methodCanWrench.invoke(itemStack.getItem(), entityPlayer, x, y, z);
}
catch (NoClassDefFoundError e)
{
}
catch (Exception e)
{
}
/** Industrialcraft */
try
{
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
{
return itemStack.getItemDamage() < itemStack.getMaxDamage();
}
}
catch (Exception e)
{
}
}
return false;
}
/** This function damages a wrench. Works with Buildcraft and Industrialcraft wrenches.
*
* @return True if damage was successfull. */
public boolean damageWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
{
if (this.isUsableWrench(entityPlayer, itemStack, x, y, z))
{
Class wrenchClass = itemStack.getItem().getClass();
/** UE and Buildcraft */
try
{
Method methodWrenchUsed = wrenchClass.getMethod("wrenchUsed", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
methodWrenchUsed.invoke(itemStack.getItem(), entityPlayer, x, y, z);
return true;
}
catch (Exception e)
{
}
/** Industrialcraft */
try
{
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
{
Method methodWrenchDamage = wrenchClass.getMethod("damage", ItemStack.class, Integer.TYPE, EntityPlayer.class);
methodWrenchDamage.invoke(itemStack.getItem(), itemStack, 1, entityPlayer);
return true;
}
}
catch (Exception e)
{
}
}
return false;
}
} }

View file

@ -18,54 +18,142 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class RenderTransformer public class RenderTransformer
{ {
public static final ModelTransformer MODEL = new ModelTransformer(); public static final ModelTransformer MODEL = new ModelTransformer();
public static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "transformer.png"); public static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "transformer.png");
public static void render(PartTransformer part, double x, double y, double z) public static void render(PartTransformer part, double x, double y, double z)
{ {
String status = TranslationHelper.getLocal((part.stepUp() ? "tooltip.transformer.stepUp" : "tooltip.transformer.stepDown")); String status = TranslationHelper.getLocal((part.stepUp() ? "tooltip.transformer.stepUp" : "tooltip.transformer.stepDown"));
EntityPlayer player = Minecraft.getMinecraft().thePlayer; EntityPlayer player = Minecraft.getMinecraft().thePlayer;
MovingObjectPosition movingPosition = player.rayTrace(5, 1f); MovingObjectPosition movingPosition = player.rayTrace(5, 1f);
if (movingPosition != null) if (movingPosition != null)
{ {
if (new Vector3(part.x(), part.y(), part.z()).equals(new Vector3(movingPosition))) if (new Vector3(part.x(), part.y(), part.z()).equals(new Vector3(movingPosition)))
{ {
CalclaviaRenderHelper.renderFloatingText(status, (float) (x + 0.5), (float) (y - 1), (float) (z + 0.5)); CalclaviaRenderHelper.renderFloatingText(status, (float) (x + 0.5), (float) (y - 1), (float) (z + 0.5));
} }
} }
GL11.glPushMatrix(); GL11.glPushMatrix();
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.placementSide) switch (part.placementSide)
{ {
case 1: case DOWN:
GL11.glRotatef(180, 0, 0, 1);
GL11.glTranslatef(0, -2, 0);
break;
case 2:
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -1, -1);
break;
case 3:
GL11.glRotatef(-90, 1, 0, 0);
GL11.glTranslatef(0, -1, 1);
break;
case 4:
GL11.glRotatef(90, 0, 0, 1);
GL11.glTranslatef(1, -1, 0);
break;
case 5:
GL11.glRotatef(-90, 0, 0, 1);
GL11.glTranslatef(-1, -1, 0);
break;
}
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE); switch (part.face)
MODEL.render(0.0625F); {
GL11.glPopMatrix(); case 0:
} GL11.glRotatef(90, 0, 1, 0);
break;
case 1:
GL11.glRotatef(180, 0, 1, 0);
break;
case 2:
GL11.glRotatef(-90, 0, 1, 0);
break;
case 3:
break;
}
break;
case UP:
GL11.glRotatef(180, 0, 0, 1);
GL11.glTranslatef(0, -2, 0);
switch (part.face)
{
case 0:
GL11.glRotatef(90, 0, 1, 0);
break;
case 1:
GL11.glRotatef(180, 0, 1, 0);
break;
case 2:
GL11.glRotatef(-90, 0, 1, 0);
break;
case 3:
break;
}
break;
case NORTH:
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -1, -1);
switch (part.face)
{
case 0:
GL11.glRotatef(90, 0, 1, 0);
break;
case 1:
GL11.glRotatef(180, 0, 1, 0);
break;
case 2:
GL11.glRotatef(-90, 0, 1, 0);
break;
case 3:
break;
}
break;
case SOUTH:
GL11.glRotatef(-90, 1, 0, 0);
GL11.glTranslatef(0, -1, 1);
switch (part.face)
{
case 0:
GL11.glRotatef(-90, 0, 1, 0);
break;
case 1:
break;
case 2:
GL11.glRotatef(90, 0, 1, 0);
break;
case 3:
GL11.glRotatef(180, 0, 1, 0);
break;
}
break;
case WEST:
GL11.glRotatef(90, 0, 0, 1);
GL11.glTranslatef(1, -1, 0);
switch (part.face)
{
case 0:
break;
case 1:
GL11.glRotatef(90, 0, 1, 0);
break;
case 2:
GL11.glRotatef(180, 0, 1, 0);
break;
case 3:
GL11.glRotatef(-90, 0, 1, 0);
break;
}
break;
case EAST:
GL11.glRotatef(-90, 0, 0, 1);
GL11.glTranslatef(-1, -1, 0);
switch (part.face)
{
case 0:
GL11.glRotatef(180, 0, 1, 0);
break;
case 1:
GL11.glRotatef(-90, 0, 1, 0);
break;
case 2:
break;
case 3:
GL11.glRotatef(90, 0, 1, 0);
break;
}
break;
}
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
MODEL.render(0.0625F);
GL11.glPopMatrix();
}
} }