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;
import java.lang.reflect.Method;
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.ChatMessageComponent;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
@ -45,9 +48,9 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
}
}
/** Side of the block this is placed on */
public int placementSide;
public ForgeDirection placementSide;
/** Direction this block faces */
public int face = 0;
public byte face = 0;
/** Step the voltage up */
private boolean stepUp;
/** Amount to mulitply the step by (up x2. down /2) */
@ -55,20 +58,20 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
public void preparePlacement(int side, int itemDamage)
{
this.placementSide = (byte) (side ^ 1);
this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1));
}
@Override
public void readDesc(MCDataInput packet)
{
this.placementSide = packet.readByte();
this.placementSide = ForgeDirection.getOrientation(packet.readByte());
this.face = packet.readByte();
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte(this.placementSide);
packet.writeByte(this.placementSide.ordinal());
packet.writeByte(this.face);
}
@ -80,13 +83,13 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
@Override
public int getSlotMask()
{
return 1 << this.placementSide;
return 1 << this.placementSide.ordinal();
}
@Override
public Cuboid6 getBounds()
{
return FaceMicroClass.aBounds()[0x10 | this.placementSide];
return FaceMicroClass.aBounds()[0x10 | this.placementSide.ordinal()];
}
@Override
@ -104,7 +107,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
@Override
public Iterable<Cuboid6> getOcclusionBoxes()
{
return Arrays.asList(oBoxes[this.placementSide]);
return Arrays.asList(oBoxes[this.placementSide.ordinal()]);
}
protected ItemStack getItem()
@ -140,7 +143,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
public void load(NBTTagCompound nbt)
{
super.load(nbt);
this.placementSide = nbt.getByte("side");
this.placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
this.stepUp = nbt.getBoolean("stepUp");
}
@ -148,7 +151,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setByte("side", (byte) this.placementSide);
nbt.setByte("side", (byte) this.placementSide.ordinal());
nbt.setBoolean("stepUp", this.stepUp);
}
@ -160,6 +163,54 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
protected ForgeDirection getFacing()
{
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;
}
@ -200,6 +251,8 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
@Override
public long getVoltageOutput(ForgeDirection side)
{
if (side == this.getFacing())
{
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)
@ -218,6 +271,102 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF
{
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

@ -42,25 +42,113 @@ public class RenderTransformer
switch (part.placementSide)
{
case DOWN:
switch (part.face)
{
case 0:
GL11.glRotatef(90, 0, 1, 0);
break;
case 1:
GL11.glRotatef(180, 0, 0, 1);
GL11.glTranslatef(0, -2, 0);
GL11.glRotatef(180, 0, 1, 0);
break;
case 2:
GL11.glRotatef(90, 1, 0, 0);
GL11.glTranslatef(0, -1, -1);
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 4:
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 5:
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;
}