Skip to content

Commit

Permalink
Finish hammer rendering and animation. Still needs texture
Browse files Browse the repository at this point in the history
  • Loading branch information
tterrag1098 committed Jan 5, 2015
1 parent 57ec67b commit 7241158
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 354 deletions.
22 changes: 9 additions & 13 deletions src/main/java/ExAstris/Block/BlockHammerAutomatic.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package ExAstris.Block;

import ExAstris.Block.TileEntity.TileEntityHammerAutomatic;
import ExAstris.Data.BlockData;
import ExAstris.Data.ModData;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import ExAstris.Block.TileEntity.TileEntityHammerAutomatic;
import ExAstris.Data.BlockData;
import ExAstris.Data.ModData;
import cpw.mods.fml.common.registry.GameRegistry;

public class BlockHammerAutomatic extends BlockContainer {

public BlockHammerAutomatic()
public static int renderId;

public BlockHammerAutomatic()
{
super(Material.iron);
setCreativeTab(ExAstris.ExAstris.ExAstrisTab);
setHardness(2.0f);

setBlockName(ModData.ID + "." + BlockData.HAMMER_AUTOMATIC_KEY);
setBlockTextureName(ModData.ID + ":HammerBase");
GameRegistry.registerTileEntity(TileEntityHammerAutomatic.class, ModData.ID + "." + BlockData.HAMMER_AUTOMATIC_KEY);
}

Expand All @@ -42,16 +44,10 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p
return true;
}

@Override
public String getUnlocalizedName()
{
return ModData.ID + "." + BlockData.HAMMER_AUTOMATIC_UNLOCALIZED_NAME;
}

@Override
public int getRenderType()
{
return -1;
return renderId;
}

@Override
Expand Down

This file was deleted.

118 changes: 118 additions & 0 deletions src/main/java/ExAstris/Block/Render/RenderBlockHammer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package ExAstris.Block.Render;

import org.lwjgl.opengl.GL11;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.model.obj.Face;
import net.minecraftforge.client.model.obj.GroupObject;
import net.minecraftforge.client.model.obj.TextureCoordinate;
import net.minecraftforge.client.model.obj.Vertex;
import net.minecraftforge.client.model.obj.WavefrontObject;
import ExAstris.Block.BlockHammerAutomatic;
import ExAstris.Data.ModData;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class RenderBlockHammer implements ISimpleBlockRenderingHandler, IItemRenderer
{
private static final WavefrontObject model_base = new WavefrontObject(new ResourceLocation(ModData.ID, "models/hammer_base.obj"));
private static final ResourceLocation texture_base = new ResourceLocation(ModData.ID, "textures/blocks/HammerBase.png");

public static final WavefrontObject model_arm = new WavefrontObject(new ResourceLocation(ModData.ID, "models/hammer_arm.obj"));
public static final ResourceLocation texture_arm= new ResourceLocation(ModData.ID, "textures/blocks/HammerArm.png");

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
return true;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
return helper == ItemRendererHelper.INVENTORY_BLOCK || helper == ItemRendererHelper.ENTITY_BOBBING || helper == ItemRendererHelper.ENTITY_ROTATION;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
switch(type)
{
case ENTITY:
break;
case EQUIPPED:
GL11.glRotatef(35, 0, 1, 0);
GL11.glRotatef(20, 0, 0, 1);
GL11.glScalef(0.65f, 0.65f, 0.65f);
GL11.glTranslatef(1.1f, -0.2f, 0.75f);
break;
case EQUIPPED_FIRST_PERSON:
GL11.glRotatef(20, 0, 0, 1);
GL11.glRotatef(30, 0, 1, 0);
GL11.glTranslatef(0.4f, -0.05f, -0.1f);
GL11.glScalef(0.5f, 0.5f, 0.5f);
break;
case FIRST_PERSON_MAP:
break;
case INVENTORY:
GL11.glTranslatef(0, -0.5f, 0);
}

Minecraft.getMinecraft().renderEngine.bindTexture(texture_base);
model_base.renderAll();
Minecraft.getMinecraft().renderEngine.bindTexture(texture_arm);
model_arm.renderAll();
}

@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer)
{
;
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
{
Tessellator tes = Tessellator.instance;
IIcon icon = block.getIcon(0, 0);
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tes.setColorOpaque_F(1, 1, 1);
tes.addTranslation(x + .5F, y, z + .5F);
for (GroupObject go : model_base.groupObjects)
{
for (Face f : go.faces)
{
Vertex n = f.faceNormal;
tes.setNormal(n.x, n.y, n.z);
for (int i = 0; i < f.vertices.length; i++)
{
Vertex v = f.vertices[i];
TextureCoordinate t = f.textureCoordinates[i];
tes.addVertexWithUV(v.x, v.y, v.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 16));
}
}
}
tes.addTranslation(-x - .5F, -y, -z - .5F);
return true;
}

@Override
public boolean shouldRender3DInInventory(int modelId)
{
return true;
}

@Override
public int getRenderId()
{
return BlockHammerAutomatic.renderId;
}

}
90 changes: 57 additions & 33 deletions src/main/java/ExAstris/Block/Render/RenderHammerAutomatic.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,67 @@
package ExAstris.Block.Render;

import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

import org.lwjgl.opengl.GL11;

import ExAstris.Block.TileEntity.TileEntityHammerAutomatic;
import ExAstris.Data.ModData;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;

public class RenderHammerAutomatic extends TileEntitySpecialRenderer {

private IModelCustom model;
private IModelCustom arm;

public RenderHammerAutomatic()
{
model = AdvancedModelLoader.loadModel(new ResourceLocation(ModData.TEXTURE_LOCATION, "models/hammer_base.obj"));
arm = AdvancedModelLoader.loadModel(new ResourceLocation(ModData.TEXTURE_LOCATION, "models/hammer_arm.obj"));
}

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
public class RenderHammerAutomatic extends TileEntitySpecialRenderer
{
private static EntityItem item;

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)
{
if (item == null)
{
item = new EntityItem(tileentity.getWorldObj());
}

float percMaxRaise = 0.95f;
float amntMaxRaise = 0.31f;
float percShowItem = 0.60f;

GL11.glPushMatrix();
GL11.glTranslated(x+0.5, y, z+0.5);
//Minecraft.getMinecraft().renderEngine.func_110577_a(casinoTexture);
model.renderAll();

TileEntityHammerAutomatic hammer = (TileEntityHammerAutomatic) tileentity;

GL11.glTranslated(x+0.5, y-0.5+hammer.getVolume(), z+0.5);
arm.renderAll();

GL11.glTranslated(x + 0.5, y, z + 0.5);

TileEntityHammerAutomatic tile = (TileEntityHammerAutomatic) tileentity;
float prog = 1 - tile.getVolume(); // volume counts down to 0, need to invert that

// show the item to be squashed
if (prog >= percShowItem)
{
GL11.glPushMatrix();
ItemStack stack = tile.getStackInSlot(0);
stack.stackSize = 1;
item.setEntityItemStack(stack);
GL11.glDepthMask(true);
item.hoverStart = 0.0F;
GL11.glTranslatef(0, 0.2f, 0);
GL11.glScalef(0.95f, 0.95f, 0.95f); // fits inside arm when squashed
RenderManager.instance.renderEntityWithPosYaw(item, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
GL11.glPopMatrix();
}

// on the way down
if (prog > percMaxRaise)
{
percMaxRaise = 1 - percMaxRaise;
prog = 1 - prog;
}

// cut off floating point errors to prevent "bounce" at the bottom
float translate = Math.max(0, amntMaxRaise * (prog / percMaxRaise));

GL11.glTranslatef(0, translate, 0);

bindTexture(RenderBlockHammer.texture_arm);
RenderBlockHammer.model_arm.renderAll();
GL11.glPopMatrix();


}
}

}
Loading

0 comments on commit 7241158

Please sign in to comment.