From 958cca31806fbf1afbc778b7155df5b7461c1cb8 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 21 Jan 2014 16:06:39 +0800 Subject: [PATCH] Added new transformer model --- .../core/render/RenderRIItem.java | 15 +- .../transformer/ItemTransformer.java | 6 +- .../transformer/ModelTransformer.java | 150 ---------------- .../transformer/PartTransformer.java | 20 +-- .../transformer/RenderTransformer.java | 160 +++--------------- .../mechanical/gear/RenderGear.java | 31 +--- .../process/RenderGrinderWheel.java | 8 +- 7 files changed, 49 insertions(+), 341 deletions(-) delete mode 100644 src/main/java/resonantinduction/electrical/transformer/ModelTransformer.java diff --git a/src/main/java/resonantinduction/core/render/RenderRIItem.java b/src/main/java/resonantinduction/core/render/RenderRIItem.java index f01855cd..3249dd45 100644 --- a/src/main/java/resonantinduction/core/render/RenderRIItem.java +++ b/src/main/java/resonantinduction/core/render/RenderRIItem.java @@ -39,29 +39,26 @@ public class RenderRIItem implements IItemRenderer @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + GL11.glPushMatrix(); + if (item.getItem() instanceof ItemGear) { RenderGear.INSTANCE.renderInventory(null, 0, 0, null); } else if (item.getItem() instanceof ItemMultimeter) { - GL11.glPushMatrix(); GL11.glRotatef(180, 0, 1, 0); GL11.glTranslated(0, -1, -0.7); FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderMultimeter.TEXTURE); RenderMultimeter.MODEL.render(0.0625f); - GL11.glPopMatrix(); } else if (item.getItem() instanceof ItemTransformer) { - GL11.glPushMatrix(); - GL11.glRotatef(180, 0, 0, 1); - GL11.glTranslated(0, -1, 0); - GL11.glScaled(0.9f, 0.9f, 0.9f); - FMLClientHandler.instance().getClient().renderEngine.bindTexture(RenderTransformer.TEXTURE); - RenderTransformer.MODEL.render(0.0625f); - GL11.glPopMatrix(); + GL11.glTranslated(0, -0.2f, 0); + RenderTransformer.INSTANCE.doRender(); } + + GL11.glPopMatrix(); } } diff --git a/src/main/java/resonantinduction/electrical/transformer/ItemTransformer.java b/src/main/java/resonantinduction/electrical/transformer/ItemTransformer.java index 85db2a20..15d0291a 100644 --- a/src/main/java/resonantinduction/electrical/transformer/ItemTransformer.java +++ b/src/main/java/resonantinduction/electrical/transformer/ItemTransformer.java @@ -3,6 +3,7 @@ package resonantinduction.electrical.transformer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import resonantinduction.core.Settings; import resonantinduction.core.prefab.part.ItemMultipartBase; @@ -28,7 +29,10 @@ public class ItemTransformer extends ItemMultipartBase if (part != null) { - part.preparePlacement(side, itemStack.getItemDamage()); + int l = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + int facing = l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0))); + + part.preparePlacement(facing, itemStack.getItemDamage()); } return part; diff --git a/src/main/java/resonantinduction/electrical/transformer/ModelTransformer.java b/src/main/java/resonantinduction/electrical/transformer/ModelTransformer.java deleted file mode 100644 index 4c227cfe..00000000 --- a/src/main/java/resonantinduction/electrical/transformer/ModelTransformer.java +++ /dev/null @@ -1,150 +0,0 @@ -package resonantinduction.electrical.transformer; - -import net.minecraft.client.model.ModelBase; -import net.minecraft.client.model.ModelRenderer; -import net.minecraft.entity.Entity; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class ModelTransformer extends ModelBase -{ - // fields - ModelRenderer a; - ModelRenderer b; - ModelRenderer c; - ModelRenderer d; - ModelRenderer out2; - ModelRenderer out1; - ModelRenderer out3; - ModelRenderer out4; - ModelRenderer i; - ModelRenderer j; - ModelRenderer in1; - ModelRenderer in2; - ModelRenderer in3; - ModelRenderer in4; - - public ModelTransformer() - { - textureWidth = 70; - textureHeight = 45; - - a = new ModelRenderer(this, 0, 0); - a.addBox(-8F, 0F, -8F, 16, 2, 16); - a.setRotationPoint(0F, 22F, 0F); - a.setTextureSize(70, 45); - a.mirror = true; - setRotation(a, 0F, 0F, 0F); - b = new ModelRenderer(this, 0, 19); - b.addBox(0F, 0F, -2F, 3, 11, 4); - b.setRotationPoint(5F, 11F, 0F); - b.setTextureSize(70, 45); - b.mirror = true; - setRotation(b, 0F, 0F, 0F); - c = new ModelRenderer(this, 0, 19); - c.addBox(0F, 0F, -2F, 3, 11, 4); - c.setRotationPoint(-8F, 11F, 0F); - c.setTextureSize(70, 45); - c.mirror = true; - setRotation(c, 0F, 0F, 0F); - d = new ModelRenderer(this, 15, 19); - d.addBox(0F, 0F, -2F, 16, 1, 4); - d.setRotationPoint(-8F, 10F, 0F); - d.setTextureSize(70, 45); - d.mirror = true; - setRotation(d, 0F, 0F, 0F); - out2 = new ModelRenderer(this, 0, 35); - out2.addBox(0F, 0F, -3F, 5, 0, 6); - out2.setRotationPoint(-9F, 16F, 0F); - out2.setTextureSize(70, 45); - out2.mirror = true; - setRotation(out2, 0F, 0F, 0F); - out1 = new ModelRenderer(this, 0, 35); - out1.addBox(0F, 0F, -3F, 5, 0, 6); - out1.setRotationPoint(-9F, 15F, 0F); - out1.setTextureSize(70, 45); - out1.mirror = true; - setRotation(out1, 0F, 0F, 0F); - out3 = new ModelRenderer(this, 0, 35); - out3.addBox(0F, 0F, -3F, 5, 0, 6); - out3.setRotationPoint(-9F, 17F, 0F); - out3.setTextureSize(70, 45); - out3.mirror = true; - setRotation(out3, 0F, 0F, 0F); - out4 = new ModelRenderer(this, 0, 35); - out4.addBox(0F, 0F, -3F, 5, 0, 6); - out4.setRotationPoint(-9F, 18F, 0F); - out4.setTextureSize(70, 45); - out4.mirror = true; - setRotation(out4, 0F, 0F, 0F); - i = new ModelRenderer(this, 34, 35); - i.addBox(0F, 0F, -1F, 2, 5, 2); - i.setRotationPoint(-10F, 14F, 0F); - i.setTextureSize(70, 45); - i.mirror = true; - setRotation(i, 0F, 0F, 0F); - j = new ModelRenderer(this, 24, 35); - j.addBox(0F, 0F, -1F, 2, 5, 2); - j.setRotationPoint(8F, 14F, 0F); - j.setTextureSize(70, 45); - j.mirror = true; - setRotation(j, 0F, 0F, 0F); - in1 = new ModelRenderer(this, 0, 35); - in1.addBox(0F, 0F, -3F, 5, 0, 6); - in1.setRotationPoint(4F, 15F, 0F); - in1.setTextureSize(70, 45); - in1.mirror = true; - setRotation(in1, 0F, 0F, 0F); - in2 = new ModelRenderer(this, 0, 35); - in2.addBox(0F, 0F, -3F, 5, 0, 6); - in2.setRotationPoint(4F, 16F, 0F); - in2.setTextureSize(70, 45); - in2.mirror = true; - setRotation(in2, 0F, 0F, 0F); - in3 = new ModelRenderer(this, 0, 35); - in3.addBox(0F, 0F, -3F, 5, 0, 6); - in3.setRotationPoint(4F, 17F, 0F); - in3.setTextureSize(70, 45); - in3.mirror = true; - setRotation(in3, 0F, 0F, 0F); - in4 = new ModelRenderer(this, 0, 35); - in4.addBox(0F, 0F, -3F, 5, 0, 6); - in4.setRotationPoint(4F, 18F, 0F); - in4.setTextureSize(70, 45); - in4.mirror = true; - setRotation(in4, 0F, 0F, 0F); - } - - public void render(float f5) - { - a.render(f5); - b.render(f5); - c.render(f5); - d.render(f5); - out2.render(f5); - out1.render(f5); - out3.render(f5); - out4.render(f5); - i.render(f5); - j.render(f5); - in1.render(f5); - in2.render(f5); - in3.render(f5); - in4.render(f5); - } - - private void setRotation(ModelRenderer model, float x, float y, float z) - { - model.rotateAngleX = x; - model.rotateAngleY = y; - model.rotateAngleZ = z; - } - - @Override - public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) - { - super.setRotationAngles(f, f1, f2, f3, f4, f5, entity); - } - -} \ No newline at end of file diff --git a/src/main/java/resonantinduction/electrical/transformer/PartTransformer.java b/src/main/java/resonantinduction/electrical/transformer/PartTransformer.java index b8107232..7c74e43a 100644 --- a/src/main/java/resonantinduction/electrical/transformer/PartTransformer.java +++ b/src/main/java/resonantinduction/electrical/transformer/PartTransformer.java @@ -12,6 +12,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; import net.minecraftforge.common.ForgeDirection; import resonantinduction.electrical.Electrical; +import resonantinduction.electrical.wire.framed.RenderFramedWire; import universalelectricity.api.electricity.IElectricalNetwork; import universalelectricity.api.electricity.IVoltageInput; import universalelectricity.api.electricity.IVoltageOutput; @@ -20,6 +21,7 @@ import universalelectricity.api.energy.IEnergyInterface; import universalelectricity.api.vector.VectorHelper; import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; +import codechicken.lib.lighting.LazyLightMatrix; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Rotation; import codechicken.lib.vec.Transformation; @@ -58,7 +60,8 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF public void preparePlacement(int side, int itemDamage) { - this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1)); + placementSide = ForgeDirection.getOrientation((byte) (side ^ 1)); + face = (byte) side; } @Override @@ -141,7 +144,7 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF { if (pass == 0) { - RenderTransformer.render(this, pos.x, pos.y, pos.z); + RenderTransformer.INSTANCE.render(this, pos.x, pos.y, pos.z); } } @@ -205,18 +208,9 @@ public class PartTransformer extends JCuboidPart implements JNormalOcclusion, TF } 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.getOrientation(this.face - 2); } + return ForgeDirection.NORTH; } diff --git a/src/main/java/resonantinduction/electrical/transformer/RenderTransformer.java b/src/main/java/resonantinduction/electrical/transformer/RenderTransformer.java index 89c98cb4..7152bb3c 100644 --- a/src/main/java/resonantinduction/electrical/transformer/RenderTransformer.java +++ b/src/main/java/resonantinduction/electrical/transformer/RenderTransformer.java @@ -1,6 +1,8 @@ package resonantinduction.electrical.transformer; +import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.ResourceLocation; @@ -20,145 +22,37 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderTransformer { - public static final ModelTransformer MODEL = new ModelTransformer(); - public static final WavefrontObject MODEL_OBJ = (WavefrontObject) AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "transformer.obj"); - public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "transformer.png"); + public static final RenderTransformer INSTANCE = new RenderTransformer(); - public static void render(PartTransformer part, double x, double y, double z) + public static final WavefrontObject MODEL = (WavefrontObject) AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "transformer.obj"); + public static final ResourceLocation TEXTURE_COIL = new ResourceLocation(Reference.DOMAIN, Reference.BLOCK_TEXTURE_DIRECTORY + "models/wire.png"); + public static final ResourceLocation TEXTURE_STONE = new ResourceLocation(Reference.BLOCK_TEXTURE_DIRECTORY + "stone.png"); + public static final ResourceLocation TEXTURE_IRON = new ResourceLocation(Reference.BLOCK_TEXTURE_DIRECTORY + "iron_block.png"); + + public void doRender() { - String status = LanguageUtility.getLocal((part.stepUp() ? "tooltip.transformer.stepUp" : "tooltip.transformer.stepDown")); + GL11.glScalef(0.5f, 0.5f, 0.5f); - EntityPlayer player = Minecraft.getMinecraft().thePlayer; - MovingObjectPosition movingPosition = player.rayTrace(5, 1f); + FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_COIL); + GL11.glColor4f(0.72f, .45f, 0.2f, 1); + MODEL.renderOnly("InsulatorLayerHigh", "InsulatorLayerMed", "InsulatorLayerLow"); + MODEL.renderOnly("OuterWindingConnector", "OuterWindingHigh", "OuterWindingMed", "OuterWindingLow"); + MODEL.renderOnly("InnerWindingConnector", "InnerWindingHigh", "InnerWindingMed", "InnerWindingLow"); - if (movingPosition != null) - { - if (new Vector3(part.x(), part.y(), part.z()).equals(new Vector3(movingPosition))) - { - RenderUtility.renderFloatingText(status, (float) (x + 0.5), (float) (y - 1), (float) (z + 0.5)); - } - } + GL11.glColor4f(1, 1, 1, 1); + FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_IRON); + MODEL.renderOnly("core"); + FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_STONE); + MODEL.renderOnly("base"); + } + public void render(PartTransformer part, double x, double y, double z) + { GL11.glPushMatrix(); - GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); - GL11.glScalef(1.0F, -1F, -1F); - - switch (part.placementSide) - { - case DOWN: - - 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 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); - //GL11.glScalef(0.5f, 0.5f, 0.5f); - //MODEL_OBJ.renderAll(); - MODEL.render(0.0625F); + GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F); + RenderUtility.rotateFaceBlockToSide(part.placementSide); + RenderUtility.rotateBlockBasedOnDirection(part.getFacing()); + doRender(); GL11.glPopMatrix(); } } \ No newline at end of file diff --git a/src/main/java/resonantinduction/mechanical/gear/RenderGear.java b/src/main/java/resonantinduction/mechanical/gear/RenderGear.java index 80a5aa7f..d31ff079 100644 --- a/src/main/java/resonantinduction/mechanical/gear/RenderGear.java +++ b/src/main/java/resonantinduction/mechanical/gear/RenderGear.java @@ -8,6 +8,7 @@ import net.minecraftforge.client.model.IModelCustom; import org.lwjgl.opengl.GL11; +import calclavia.lib.render.RenderUtility; import resonantinduction.core.Reference; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.relauncher.Side; @@ -22,11 +23,9 @@ public class RenderGear public void renderInventory(Block block, int metadata, int modelID, RenderBlocks renderer) { - GL11.glPushMatrix(); GL11.glRotatef(90, 1, 0, 0); FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE); MODEL.renderAll(); - GL11.glPopMatrix(); } public void renderDynamic(PartGear part, double x, double y, double z, float frame) @@ -34,40 +33,14 @@ public class RenderGear GL11.glPushMatrix(); // Center the model first. GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f); - GL11.glPushMatrix(); - switch (part.placementSide) - { - case DOWN: - GL11.glTranslatef(0, -0.45f, 0); - break; - case UP: - GL11.glTranslatef(0, 0.45f, 0); - break; - case NORTH: - GL11.glTranslatef(0, 0, -0.45f); - GL11.glRotatef(90, 1, 0, 0); - break; - case SOUTH: - GL11.glTranslatef(0, 0, 0.45f); - GL11.glRotatef(-90, 1, 0, 0); - break; - case WEST: - GL11.glTranslatef(-0.45f, 0, 0); - GL11.glRotatef(90, 0, 0, 1); - break; - case EAST: - GL11.glTranslatef(0.45f, 0, 0); - GL11.glRotatef(-90, 0, 0, 1); - break; - } + RenderUtility.rotateFaceBlockToSide(part.placementSide); GL11.glRotatef((float) Math.toDegrees(part.isClockwise() ? part.getNetwork().getRotation() : -part.getNetwork().getRotation()), 0, 1, 0); FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE); MODEL.renderAll(); - GL11.glPopMatrix(); GL11.glPopMatrix(); } diff --git a/src/main/java/resonantinduction/mechanical/process/RenderGrinderWheel.java b/src/main/java/resonantinduction/mechanical/process/RenderGrinderWheel.java index ddadbfe7..d0efe5d1 100644 --- a/src/main/java/resonantinduction/mechanical/process/RenderGrinderWheel.java +++ b/src/main/java/resonantinduction/mechanical/process/RenderGrinderWheel.java @@ -5,6 +5,7 @@ import static org.lwjgl.opengl.GL11.glPushMatrix; import static org.lwjgl.opengl.GL11.glRotatef; import static org.lwjgl.opengl.GL11.glScalef; import static org.lwjgl.opengl.GL11.glTranslatef; +import calclavia.lib.render.RenderUtility; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; @@ -35,12 +36,7 @@ public class RenderGrinderWheel extends TileEntitySpecialRenderer glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F); glScalef(0.51f, 0.51f, 0.51f); - if (tile.getDirection().ordinal() < 2) - glRotatef(90, 1, 0, 0); - else if (tile.getDirection().ordinal() == 2 || tile.getDirection().ordinal() == 3) - glRotatef(90, 0, 1, 0); - else if (tile.getDirection().ordinal() == 4 || tile.getDirection().ordinal() == 5) - glRotatef(180, 0, 1, 0); + RenderUtility.rotateBlockBasedOnDirection(tile.getDirection()); glRotatef((float) Math.toDegrees(tile.getNetwork().getRotation()) * (tile.isClockwise() ? 1 : -1), 0, 0, 1);