Start of the new block renderer

This commit is contained in:
dmillerw 2014-04-11 19:27:38 -07:00
parent 1945458f97
commit 8267cb87ee
11 changed files with 306 additions and 57 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -8,39 +8,27 @@
*/
package buildcraft.builders;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockMultiTexture;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.tools.IToolWrench;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockArchitect extends BlockContainer {
IIcon blockTextureSides;
IIcon blockTextureFront;
IIcon blockTextureTopPos;
IIcon blockTextureTopNeg;
IIcon blockTextureTopArchitect;
public class BlockArchitect extends BlockMultiTexture {
public BlockArchitect() {
super(Material.iron);
setHardness(5F);
setCreativeTab(CreativeTabBuildCraft.TIER_3.get());
super(Material.iron, CreativeTabBuildCraft.TIER_3);
}
@Override
@ -105,42 +93,6 @@ public class BlockArchitect extends BlockContainer {
world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(),1);
}
@SuppressWarnings({ "all" })
@Override
public IIcon getIcon(IBlockAccess iblockaccess, int i, int j, int k, int l) {
int m = iblockaccess.getBlockMetadata(i, j, k);
if (l == 1)
return blockTextureTopArchitect;
return getIcon(l, m);
}
@Override
public IIcon getIcon(int i, int j) {
if (j == 0 && i == 3)
return blockTextureFront;
if (i == 1)
return blockTextureTopArchitect;
if (i == j)
return blockTextureFront;
return blockTextureSides;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister)
{
blockTextureSides = par1IconRegister.registerIcon("buildcraft:architect_sides");
blockTextureTopNeg = par1IconRegister.registerIcon("buildcraft:architect_top_neg");
blockTextureTopPos = par1IconRegister.registerIcon("buildcraft:architect_top_pos");
blockTextureTopArchitect = par1IconRegister.registerIcon("buildcraft:architect_top");
blockTextureFront = par1IconRegister.registerIcon("buildcraft:architect_front");
}
@Override
public boolean renderAsNormalBlock() {
return false;
@ -155,4 +107,16 @@ public class BlockArchitect extends BlockContainer {
public int getLightValue(IBlockAccess world, int x, int y, int z) {
return 1;
}
/* MULTI TEXTURE */
@Override
public String getIconPrefix() {
return "architect_";
}
@Override
public int getFrontSide(IBlockAccess world, int x, int y, int z) {
return world.getBlockMetadata(x, y, z);
}
}

View file

@ -9,11 +9,13 @@
package buildcraft.builders;
import buildcraft.builders.urbanism.RenderBoxProvider;
import buildcraft.core.render.RenderBlockMultiTexture;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
public class BuilderProxyClient extends BuilderProxy {
@Override
@Override
public void registerClientHook() {
}
@ -22,6 +24,8 @@ public class BuilderProxyClient extends BuilderProxy {
public void registerBlockRenderers() {
super.registerBlockRenderers();
RenderingRegistry.registerBlockHandler(new RenderBlockMultiTexture());
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderBoxProvider());
ClientRegistry.bindTileEntitySpecialRenderer(TileFiller.class, new RenderBuilder());
ClientRegistry.bindTileEntitySpecialRenderer(TileBuilder.class, new RenderBuilder());

View file

@ -0,0 +1,131 @@
package buildcraft.core;
import buildcraft.core.render.IconFlipped;
import buildcraft.core.render.RenderBlockMultiTexture;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.HashMap;
import java.util.Map;
/**
* This whole class may need tweaking
*
* @author dmillerw
*/
public abstract class BlockMultiTexture extends BlockBuildCraft {
private static Map<String, IIcon> iconMap = new HashMap<String, IIcon>();
public static int getUVTopForFront(int front) {
switch (front) {
case 2:
return 3;
case 3:
return 0;
case 4:
return 1;
case 5:
return 2;
default:
return 0;
}
}
public BlockMultiTexture(Material material, CreativeTabBuildCraft tab) {
super(material, tab);
}
public abstract int getFrontSide(IBlockAccess world, int x, int y, int z);
public abstract String getIconPrefix();
//TODO Remove once we get past 1.7.2! Bug #37106
public boolean shouldFlipU(IBlockAccess world, int x, int y, int z, int side) {
int front = getFrontSide(world, x, y, z);
return (front == 4 && side == 2) || (front == 5 && side == 5) || (front == 5 && side == 2) || (front == 2 && side == 5) || (front == 2 && side == 2) || (front == 3 && side == 5) || shouldFlipU(side, getFrontSide(world, x, y, z));
}
public boolean shouldFlipV(IBlockAccess world, int x, int y, int z, int side) {
return shouldFlipV(side, getFrontSide(world, x, y, z));
}
public boolean shouldFlipU(int side, int front) {
return front == 3;
}
public boolean shouldFlipV(int side, int front) {
return false;
}
public String getIconPostfix(IBlockAccess world, int x, int y, int z, int side) {
return getIconPostfix(side, getFrontSide(world, x, y, z));
}
public String getIconPostfix(int side, int front) {
ForgeDirection forge_side = ForgeDirection.getOrientation(side);
ForgeDirection forge_front = ForgeDirection.getOrientation(front);
ForgeDirection forge_back = forge_front.getOpposite();
ForgeDirection forge_left = forge_front.getRotation(ForgeDirection.UP).getOpposite();
ForgeDirection forge_right = forge_front.getRotation(ForgeDirection.UP);
// This would be a switch statement if it could be... :(
if (forge_side == forge_front) {
return "front";
} else if (forge_side == forge_left) {
return "leftSide";
} else if (forge_side == forge_right) {
return "rightSide";
} else if (forge_side == forge_back) {
return "back";
} else if (forge_side == ForgeDirection.UP) {
return "top";
} else if (forge_side == ForgeDirection.DOWN) {
return "bottom";
}
// If all else fails
return "front";
}
private String getIconName(int side) {
return getIconName(side, ForgeDirection.WEST.ordinal());
}
private String getIconName(int side, int front) {
return getIconPrefix() + getIconPostfix(side, front);
}
@Override
public int getRenderType() {
return RenderBlockMultiTexture.renderID;
}
@Override
public void registerBlockIcons(IIconRegister register) {
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
String name = getIconName(i);
iconMap.put(name, register.registerIcon("buildcraft:" + name));
}
}
@Override
public IIcon getIcon(int side, int meta) {
IconFlipped icon = new IconFlipped(iconMap.get(getIconName(side, ForgeDirection.SOUTH.ordinal())));
icon.flipU(shouldFlipU(side, ForgeDirection.SOUTH.ordinal()));
icon.flipV(shouldFlipV(side, ForgeDirection.SOUTH.ordinal()));
return icon;
}
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
IconFlipped icon = new IconFlipped(iconMap.get(getIconName(side, getFrontSide(world, x, y, z))));
icon.flipU(shouldFlipU(world, x, y, z, side));
icon.flipV(shouldFlipV(world, x, y, z, side));
return icon;
}
}

View file

@ -0,0 +1,75 @@
package buildcraft.core.render;
import net.minecraft.util.IIcon;
/**
* @author dmillerw
*/
public class IconFlipped implements IIcon {
private final IIcon icon;
private boolean flipU, flipV;
public IconFlipped(IIcon icon) {
this.icon = icon;
}
public IconFlipped flipU(boolean flip) {
this.flipU = flip;
return this;
}
public IconFlipped flipV(boolean flip) {
this.flipV = flip;
return this;
}
@Override
public int getIconWidth() {
return flipU ? -this.getIconWidth() : this.getIconWidth();
}
@Override
public int getIconHeight() {
return flipV ? -this.getIconHeight() : this.getIconHeight();
}
@Override
public float getMinU() {
return flipU ? this.icon.getMaxU() : this.icon.getMinU();
}
@Override
public float getMaxU() {
return flipU ? this.icon.getMinU() : this.icon.getMaxU();
}
@Override
public float getInterpolatedU(double value) {
float f = getMaxU() - getMinU();
return getMinU() + f * (((float) value / 16.0F));
}
@Override
public float getMinV() {
return flipV ? this.icon.getMaxV() : this.icon.getMinV();
}
@Override
public float getMaxV() {
return flipV ? this.icon.getMinV() : this.icon.getMaxV();
}
@Override
public float getInterpolatedV(double value) {
float f = getMaxV() - getMinV();
return getMinV() + f * (((float) value / 16.0F));
}
@Override
public String getIconName() {
return this.icon.getIconName();
}
}

View file

@ -0,0 +1,75 @@
package buildcraft.core.render;
import buildcraft.core.BlockMultiTexture;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
/**
* @author dmillerw
*/
public class RenderBlockMultiTexture implements ISimpleBlockRenderingHandler {
public static int renderID;
static {
renderID = RenderingRegistry.getNextAvailableRenderId();
}
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
renderer.uvRotateTop = BlockMultiTexture.getUVTopForFront(ForgeDirection.EAST.ordinal());
Tessellator tessellator = Tessellator.instance;
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1.0F, 0.0F);
renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(0, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(1, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(2, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1.0F);
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(3, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(4, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(5, metadata));
tessellator.draw();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
renderer.uvRotateTop = BlockMultiTexture.getUVTopForFront(((BlockMultiTexture) block).getFrontSide(world, x, y, z));
renderer.renderStandardBlock(block, x, y, z);
renderer.uvRotateTop = 0;
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return true;
}
@Override
public int getRenderId() {
return renderID;
}
}