Further implement techne model rendering. Implement farm model.

This commit is contained in:
tterrag1098 committed 2015-03-16 23:46:51 -04:00
1 parent fbeb3822fd
commit fca2a2fbfc
25 files changed
+90 -98

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.
File renamed without changes.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

@@ -13,9 +13,17 @@ import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.obj.GroupObject;
import net.minecraftforge.client.model.techne.TechneModel;
import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
@@ -132,6 +140,7 @@ import crazypants.enderio.teleport.anchor.TileTravelAnchor;
import crazypants.enderio.teleport.anchor.TravelEntitySpecialRenderer;
import crazypants.enderio.teleport.telepad.TeleportEntityRenderHandler;
import crazypants.render.IconUtil;
import crazypants.render.TechneUtil;
@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy {
@@ -139,12 +148,7 @@ public class ClientProxy extends CommonProxy {
// @formatter:off
public static int[][] sideAndFacingToSpriteOffset = new int[][] {
{ 3, 2, 0, 0, 0, 0 },
{ 2, 3, 1, 1, 1, 1 },
{ 1, 1, 3, 2, 5, 4 },
{ 0, 0, 2, 3, 4, 5 },
{ 4, 5, 4, 5, 3, 2 },
{ 5, 4, 5, 4, 2, 3 } };
{ 3, 2, 0, 0, 0, 0 }, { 2, 3, 1, 1, 1, 1 }, { 1, 1, 3, 2, 5, 4 }, { 0, 0, 2, 3, 4, 5 }, { 4, 5, 4, 5, 3, 2 }, { 5, 4, 5, 4, 2, 3 } };
// @formatter:on
static {
@@ -258,7 +262,8 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileExperienceOblisk.class, eor);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockExperianceOblisk), eor);
ObeliskRenderer<TileWeatherObelisk> twr = new ObeliskRenderer<TileWeatherObelisk>(new ItemStack(EnderIO.itemMaterial, 1, Material.WEATHER_CRYSTAL.ordinal()));
ObeliskRenderer<TileWeatherObelisk> twr = new ObeliskRenderer<TileWeatherObelisk>(
new ItemStack(EnderIO.itemMaterial, 1, Material.WEATHER_CRYSTAL.ordinal()));
BlockWeatherObelisk.renderId = BlockAttractor.renderId;
ClientRegistry.bindTileEntitySpecialRenderer(TileWeatherObelisk.class, twr);
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockWeatherObelisk), twr);
@@ -15,7 +15,6 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
@@ -26,10 +25,8 @@ import crazypants.enderio.EnderIO;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.api.tool.ITool;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.tool.ToolUtil;
import crazypants.enderio.waila.IWailaInfoProvider;
public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> extends BlockEio implements IGuiHandler, IResourceTooltipProvider,
@@ -100,7 +97,7 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iIconRegister) {
iconBuffer = new IIcon[1][12];
iconBuffer = new IIcon[2][12];
String side = getSideIconKey(false);
// first the 6 sides in OFF state
iconBuffer[0][0] = iIconRegister.registerIcon(side);
@@ -117,6 +114,9 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
iconBuffer[0][9] = iIconRegister.registerIcon(getMachineFrontIconKey(true));
iconBuffer[0][10] = iIconRegister.registerIcon(side);
iconBuffer[0][11] = iIconRegister.registerIcon(side);
iconBuffer[1][0] = iIconRegister.registerIcon(getModelIconKey(false));
iconBuffer[1][1] = iIconRegister.registerIcon(getModelIconKey(false));
registerOverlayIcons(iIconRegister);
@@ -176,6 +176,18 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
return iconBuffer[0][blockSide];
}
public IIcon getModelIcon(IBlockAccess world, int x, int y, int z) {
return getModelIcon(((AbstractMachineEntity) world.getTileEntity(x, y, z)).isActive());
}
public IIcon getModelIcon() {
return getModelIcon(false);
}
private IIcon getModelIcon(boolean active) {
return active ? iconBuffer[1][1] : iconBuffer[1][0];
}
@Override
public boolean doNormalDrops(World world, int x, int y, int z) {
return false;
@@ -263,6 +275,10 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
return "enderio:machineTop";
}
protected String getModelIconKey(boolean active) {
return getSideIconKey(active);
}
protected boolean isActive(IBlockAccess blockAccess, int x, int y, int z) {
TileEntity te = blockAccess.getTileEntity(x, y, z);
if(te instanceof AbstractMachineEntity) {
@@ -30,7 +30,6 @@ public class BlockFarmStation extends AbstractMachineBlock<TileFarmStation> {
protected BlockFarmStation() {
super(ModObject.blockFarmStation, TileFarmStation.class);
setBlockBounds(0, 0, 0, 1, 0.85f, 1);
}
@Override
@@ -65,6 +64,11 @@ public class BlockFarmStation extends AbstractMachineBlock<TileFarmStation> {
protected String getSideIconKey(boolean active) {
return super.getBackIconKey(active);
}
@Override
protected String getModelIconKey(boolean active) {
return "enderio:farmModel";
}
@Override
public int getRenderType() {
@@ -1,5 +1,7 @@
package crazypants.enderio.machine.farm;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
@@ -7,74 +9,41 @@ import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
import net.minecraftforge.client.model.obj.GroupObject;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import crazypants.enderio.machine.generator.combustion.TranslatedCubeRenderer;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.VertexTransform;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
import crazypants.vecmath.Vertex;
import crazypants.render.TechneUtil;
public class FarmingStationRenderer implements ISimpleBlockRenderingHandler {
private VertXForm xform = new VertXForm();
private List<GroupObject> model = TechneUtil.getModel("models/farm");
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
GL11.glDisable(GL11.GL_LIGHTING);
Tessellator.instance.startDrawingQuads();
renderWorldBlock(null, 0, 0, 0, block, 0, renderer);
Tessellator.instance.draw();
GL11.glEnable(GL11.GL_LIGHTING);
TechneUtil.renderInventoryBlock(model, block, metadata);
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
IIcon override = renderer.overrideBlockTexture;
BoundingBox bb = BoundingBox.UNIT_CUBE;
TranslatedCubeRenderer.instance.renderBoundingBox(x, y, z, block, bb, xform, override, world != null);
float scale = 0.7f;
float width = 0.4f;
float trans = (1 - scale) / 2;
bb = BoundingBox.UNIT_CUBE.scale(1, scale, width);
bb = bb.translate(0, -trans, 0);
TranslatedCubeRenderer.instance.renderBoundingBox(x, y, z, block, bb, xform, override, world != null);
bb = BoundingBox.UNIT_CUBE.scale(width, scale, 1);
bb = bb.translate(0, -trans, 0);
TranslatedCubeRenderer.instance.renderBoundingBox(x, y, z, block, bb, xform, override, world != null);
float topWidth = 0.15f;
bb = BoundingBox.UNIT_CUBE.scale(1, topWidth, 1);
bb = bb.translate(0, 0.3f + topWidth / 2f, 0);
TranslatedCubeRenderer.instance.renderBoundingBox(x, y, z, block, bb, xform, override, world != null);
TranslatedCubeRenderer.instance.getRenderer().setOverrideTexture(null);
if(world != null) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileFarmStation && ((TileFarmStation) te).isActive()) {
bb = BoundingBox.UNIT_CUBE.scale(1, 0.08, .4);
bb = bb.translate(0, 0.1f, 0);
bb = bb.translate(x, y, z);
Tessellator.instance.setColorOpaque_F(1, 1, 1);
CubeRenderer.render(bb, override != null ? override : Blocks.portal.getBlockTextureFromSide(1));
bb = BoundingBox.UNIT_CUBE.scale(.4, 0.08, 1);
bb = bb.translate(0, 0.1f, 0);
BoundingBox bb = BoundingBox.UNIT_CUBE.scale(10D / 16D, 0.25, 10D / 16D);
bb = bb.scale(1.01, 1, 1.01);
bb = bb.translate(0, 5f / 16f, 0);
bb = bb.translate(x, y, z);
Tessellator.instance.setColorOpaque_F(1, 1, 1);
CubeRenderer.render(bb, override != null ? override : Blocks.portal.getBlockTextureFromSide(1));
}
}
return true;
if(override != null) {
return TechneUtil.renderWorldBlock(model, override, world, x, y, z, block);
}
return TechneUtil.renderWorldBlock(model, world, x, y, z, block);
}
@Override
@@ -86,39 +55,4 @@ public class FarmingStationRenderer implements ISimpleBlockRenderingHandler {
public int getRenderId() {
return BlockFarmStation.renderId;
}
private static class VertXForm implements VertexTransform {
public VertXForm() {
}
@Override
public void apply(Vertex vertex) {
apply(vertex.xyz);
}
@Override
public void apply(Vector3d vec) {
if(vec.y > 0.9) {
double pinch = 0.5;
vec.x -= 0.5;
vec.x *= pinch;
vec.x += 0.5;
vec.z -= 0.5;
vec.z *= pinch;
vec.z += 0.5;
}
double scale = 0.8;
vec.y -= 0.5;
vec.y *= scale;
vec.y += (0.5 * scale);
}
@Override
public void applyToNormal(Vector3f vec) {
}
}
}
@@ -46,7 +46,9 @@ import net.minecraft.client.model.TexturedQuad;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.obj.Face;
import net.minecraftforge.client.model.obj.GroupObject;
import net.minecraftforge.client.model.obj.TextureCoordinate;
@@ -61,6 +63,8 @@ import org.lwjgl.util.vector.Vector4f;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import crazypants.enderio.EnderIO;
import crazypants.enderio.machine.AbstractMachineBlock;
/**
* Slightly modified to fit the EnderIO source.
@@ -137,6 +141,7 @@ public class TechneUtil {
face.textureCoordinates[j] = new TextureCoordinate(pv.texturePositionX, pv.texturePositionY);
}
face.faceNormal = face.calculateFaceNormal();
obj.faces.add(face);
}
res.add(obj);
@@ -170,6 +175,11 @@ public class TechneUtil {
return res;
}
public static List<GroupObject> getModel(String modelPath) {
TechneModel tm = (TechneModel) AdvancedModelLoader.loadModel(new ResourceLocation(EnderIO.MODID.toLowerCase(), modelPath + ".tcn"));
return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1)));
}
public static void renderWithIcon(List<GroupObject> model, IIcon icon, Tessellator tes) {
for (GroupObject go : model) {
for (Face f : go.faces) {
@@ -178,27 +188,50 @@ public class TechneUtil {
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.addVertexWithUV(v.x, v.y, v.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 8));
}
}
}
}
public static void renderInventoryBlock(List<GroupObject> model, Block block, int metadata) {
RenderHelper.disableStandardItemLighting();
renderInventoryBlock(model, getIconFor(block, metadata), block, metadata);
}
public static void renderInventoryBlock(List<GroupObject> model, IIcon icon, Block block, int metadata) {
tes.startDrawingQuads();
tes.setColorOpaque_F(1, 1, 1);
renderWithIcon(model, block.getIcon(0, metadata), tes);
tes.addTranslation(0, -0.5f, 0);
renderWithIcon(model, icon, tes);
tes.addTranslation(0, 0.5f, 0);
tes.draw();
RenderHelper.enableStandardItemLighting();
}
public static boolean renderWorldBlock(List<GroupObject> model, IBlockAccess world, int x, int y, int z, Block block) {
IIcon icon = getIconFor(block, world, x, y, z);
return renderWorldBlock(model, icon, world, x, y, z, block);
}
public static boolean renderWorldBlock(List<GroupObject> model, IIcon icon, IBlockAccess world, int x, int y, int z, Block block) {
tes.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tes.setColorOpaque_F(1, 1, 1);
tes.addTranslation(x + .5F, y + .5F, z + .5F);
renderWithIcon(model, block.getIcon(0, world.getBlockMetadata(x, y, z)), tes);
tes.addTranslation(-x - .5F, -y - .5F, -z - .5F);
tes.addTranslation(x + .5F, y + 0.0375f, z + .5F);
renderWithIcon(model, icon, tes);
tes.addTranslation(-x - .5F, -y - 0.0375f, -z - .5F);
return true;
}
private static IIcon getIconFor(Block block, IBlockAccess world, int x, int y, int z) {
if(block instanceof AbstractMachineBlock<?>) {
return ((AbstractMachineBlock<?>) block).getModelIcon(world, x, y, z);
}
return getIconFor(block, world.getBlockMetadata(x, y, z));
}
private static IIcon getIconFor(Block block, int metadata) {
if(block instanceof AbstractMachineBlock<?>) {
return ((AbstractMachineBlock<?>) block).getModelIcon();
}
return block.getIcon(0, metadata);
}
}