mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-11 15:57:31 +00:00
Move over rendering stuff to ctmlib
This commit is contained in:
1 parent
ed5162104e
commit
fcec71a52d
38 files changed
+45
-1494
No files matched your search
@@ -5,7 +5,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
|
||||
/**
|
||||
* To be implemented on blocks that can be chiseled and need advanced metadata to variation mapping. Currently not very usable without internal classes.
|
||||
|
||||
@@ -17,8 +17,8 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.cricketcraft.chisel.api.ChiselAPIProps;
|
||||
import com.cricketcraft.chisel.api.FMPIMC;
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
|
||||
public interface IVariationInfo {
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.cricketcraft.chisel.api.carving;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
|
||||
public class VariationInfoBase implements IVariationInfo {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@API(apiVersion = ChiselAPIProps.VERSION, owner = "Chisel", provides = "ChiselAPI")
|
||||
@API(apiVersion = ChiselAPIProps.VERSION, owner = "chisel", provides = "ChiselAPI")
|
||||
package com.cricketcraft.chisel.api;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
@@ -1,291 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
import gnu.trove.map.TIntObjectMap;
|
||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.api.IFacade;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import static com.cricketcraft.chisel.api.rendering.Dir.*;
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* The CTM renderer will draw the block's FACE using by assembling 4 quadrants from the 5 available block
|
||||
* textures. The normal Texture.png is the blocks "unconnected" texture, and is used when CTM is disabled or the block
|
||||
* has nothing to connect to. This texture has all of the outside corner quadrants The texture-ctm.png contains the
|
||||
* rest of the quadrants.
|
||||
* <pre><blockquote>
|
||||
* ┌─────────────────┐ ┌────────────────────────────────┐
|
||||
* │ texture.png │ │ texture-ctm.png │
|
||||
* │ ╔══════╤══════╗ │ │ ──────┼────── ║ ─────┼───── ║ │
|
||||
* │ ║ │ ║ │ │ │ │ │║ │ ║ │
|
||||
* │ ║ 16 │ 17 ║ │ │ │ 0 │ 1 │║ 2 │ 3 ║ │
|
||||
* │ ╟──────┼──────╢ │ │ ┼──────┼──────┼╟──────┼──────╢ │
|
||||
* │ ║ │ ║ │ │ │ │ │║ │ ║ │
|
||||
* │ ║ 18 │ 19 ║ │ │ │ 4 │ 5 │║ 6 │ 7 ║ │
|
||||
* │ ╚══════╧══════╝ │ │ ──────┼────── ║ ─────┼───── ║ │
|
||||
* └─────────────────┘ │ ═══════╤═══════╝ ─────┼───── ╚ │
|
||||
* │ │ │ ││ │ │ │
|
||||
* │ │ 8 │ 9 ││ 10 │ 11 │ │
|
||||
* │ ┼──────┼──────┼┼──────┼──────┼ │
|
||||
* │ │ │ ││ │ │ │
|
||||
* │ │ 12 │ 13 ││ 14 │ 15 │ │
|
||||
* │ ═══════╧═══════╗ ─────┼───── ╔ │
|
||||
* └────────────────────────────────┘
|
||||
* </blockquote></pre>
|
||||
* combining { 18, 13, 9, 16 }, we can generate a texture connected to the right!
|
||||
* <pre><blockquote>
|
||||
* ╔══════╤═══════
|
||||
* ║ │ │
|
||||
* ║ 16 │ 9 │
|
||||
* ╟──────┼──────┼
|
||||
* ║ │ │
|
||||
* ║ 18 │ 13 │
|
||||
* ╚══════╧═══════
|
||||
* </blockquote></pre>
|
||||
*
|
||||
* combining { 18, 13, 11, 2 }, we can generate a texture, in the shape of an L (connected to the right, and up
|
||||
* <pre><blockquote>
|
||||
* ║ ─────┼───── ╚
|
||||
* ║ │ │
|
||||
* ║ 2 │ 11 │
|
||||
* ╟──────┼──────┼
|
||||
* ║ │ │
|
||||
* ║ 18 │ 13 │
|
||||
* ╚══════╧═══════
|
||||
* </blockquote></pre>
|
||||
*
|
||||
* HAVE FUN!
|
||||
* -CptRageToaster-
|
||||
*/
|
||||
// @formatter:on
|
||||
public class CTM {
|
||||
|
||||
/** Some hardcoded offset values for the different corner indeces */
|
||||
protected static int[] submapOffsets = { 4, 5, 1, 0 };
|
||||
protected static TIntObjectMap<Dir[]> submapMap = new TIntObjectHashMap<Dir[]>();
|
||||
protected static EnumMap<Dir, Boolean> connectionMap = Maps.newEnumMap(Dir.class);
|
||||
/** For use via the Chisel 2 config only, altering this could cause unintended behavior */
|
||||
public static boolean disableObscuredFaceCheckConfig = false;
|
||||
|
||||
public Boolean disableObscuredFaceCheck = null;
|
||||
|
||||
static {
|
||||
for (Dir dir : Dir.VALUES) {
|
||||
connectionMap.put(dir, false);
|
||||
}
|
||||
// Mapping the different corner indeces to their respective dirs
|
||||
submapMap.put(0, new Dir[] { BOTTOM, LEFT, BOTTOM_LEFT });
|
||||
submapMap.put(1, new Dir[] { BOTTOM, RIGHT, BOTTOM_RIGHT });
|
||||
submapMap.put(2, new Dir[] { TOP, RIGHT, TOP_RIGHT });
|
||||
submapMap.put(3, new Dir[] { TOP, LEFT, TOP_LEFT });
|
||||
}
|
||||
|
||||
protected CTM() {
|
||||
}
|
||||
|
||||
public static CTM getInstance() {
|
||||
return new CTM();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The indeces of the typical 4x4 submap to use for the given face at the given location.
|
||||
*
|
||||
* Indeces are in counter-clockwise order starting at bottom left.
|
||||
*/
|
||||
public int[] getSubmapIndices(IBlockAccess world, int x, int y, int z, int side) {
|
||||
int[] ret = new int[] { 18, 19, 17, 16 };
|
||||
|
||||
if (world == null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
buildConnectionMap(world, x, y, z, side, block, meta);
|
||||
|
||||
// Map connections to submap indeces
|
||||
for (int i = 0; i < 4; i++) {
|
||||
fillSubmaps(ret, i);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the connection map and stores it in this CTM instance. The {@link #connected(Dir)}, {@link #connectedAnd(Dir...)}, and {@link #connectedOr(Dir...)} methods can be used to access it.
|
||||
*/
|
||||
public void buildConnectionMap(IBlockAccess world, int x, int y, int z, int side, Block block, int meta) {
|
||||
for (Dir dir : Dir.VALUES) {
|
||||
connectionMap.put(dir, dir.isConnected(this, world, x, y, z, side, block, meta));
|
||||
}
|
||||
}
|
||||
|
||||
private void fillSubmaps(int[] ret, int idx) {
|
||||
Dir[] dirs = submapMap.get(idx);
|
||||
if (connectedOr(dirs[0], dirs[1])) {
|
||||
if (connectedAnd(dirs)) {
|
||||
// If all dirs are connected, we use the fully connected face,
|
||||
// the base offset value.
|
||||
ret[idx] = submapOffsets[idx];
|
||||
} else {
|
||||
// This is a bit magic-y, but basically the array is ordered so
|
||||
// the first dir requires an offset of 2, and the second dir
|
||||
// requires an offset of 8, plus the initial offset for the
|
||||
// corner.
|
||||
ret[idx] = submapOffsets[idx] + (connected(dirs[0]) ? 2 : 0) + (connected(dirs[1]) ? 8 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dir
|
||||
* The direction to check connection in.
|
||||
* @return True if the cached connectionMap holds a connection in this {@link Dir direction}.
|
||||
*/
|
||||
public boolean connected(Dir dir) {
|
||||
return connectionMap.get(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dirs
|
||||
* The directions to check connection in.
|
||||
* @return True if the cached connectionMap holds a connection in <i><b>all</b></i> the given {@link Dir directions}.
|
||||
*/
|
||||
public boolean connectedAnd(Dir... dirs) {
|
||||
for (Dir dir : dirs) {
|
||||
if (!connected(dir)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dirs
|
||||
* The directions to check connection in.
|
||||
* @return True if the cached connectionMap holds a connection in <i><b>one of</b></i> the given {@link Dir directions}.
|
||||
*/
|
||||
private boolean connectedOr(Dir... dirs) {
|
||||
for (Dir dir : dirs) {
|
||||
if (connected(dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple check for if the given block can connect to the given direction on the given side.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* The x coordinate of the block to check <i>against</i>. This is not the position of your block.
|
||||
* @param y
|
||||
* The y coordinate of the block to check <i>against</i>. This is not the position of your block.
|
||||
* @param z
|
||||
* The z coordinate of the block to check <i>against</i>. This is not the position of your block.
|
||||
* @param side
|
||||
* The side of the block to check for connection status. This is <i>not</i> the direction to check in.
|
||||
* @param block
|
||||
* The block to check against for connection.
|
||||
* @param meta
|
||||
* The metadata to check against for connection.
|
||||
* @return True if the given block can connect to the given location on the given side.
|
||||
*/
|
||||
public boolean isConnected(IBlockAccess world, int x, int y, int z, int side, Block block, int meta) {
|
||||
ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[side];
|
||||
return isConnected(world, x, y, z, dir, block, meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple check for if the given block can connect to the given direction on the given side.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* The x coordinate of the block to check <i>against</i>. This is not the position of your block.
|
||||
* @param y
|
||||
* The y coordinate of the block to check <i>against</i>. This is not the position of your block.
|
||||
* @param z
|
||||
* The z coordinate of the block to check <i>against</i>. This is not the position of your block.
|
||||
* @param dir
|
||||
* The {@link ForgeDirection side} of the block to check for connection status. This is <i>not</i> the direction to check in.
|
||||
* @param block
|
||||
* The block to check against for connection.
|
||||
* @param meta
|
||||
* The metadata to check against for connection.
|
||||
* @return True if the given block can connect to the given location on the given side.
|
||||
*/
|
||||
public boolean isConnected(IBlockAccess world, int x, int y, int z, ForgeDirection dir, Block block, int meta) {
|
||||
int x2 = x + dir.offsetX;
|
||||
int y2 = y + dir.offsetY;
|
||||
int z2 = z + dir.offsetZ;
|
||||
|
||||
boolean disableObscured = disableObscuredFaceCheck == null ? disableObscuredFaceCheckConfig : disableObscuredFaceCheck;
|
||||
|
||||
Block con = getBlockOrFacade(world, x, y, z, dir.ordinal());
|
||||
Block obscuring = disableObscured ? null : getBlockOrFacade(world, x2, y2, z2, dir.ordinal());
|
||||
|
||||
// no block or a bad API user
|
||||
if (con == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ret = con.equals(block) && getBlockOrFacadeMetadata(world, x, y, z, dir.ordinal()) == meta;
|
||||
|
||||
// no block obscuring this face
|
||||
if (obscuring == null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check that we aren't already connected outwards from this side
|
||||
ret &= !(obscuring.equals(block) && getBlockOrFacadeMetadata(world, x2, y2, z2, dir.ordinal()) == meta);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method to access metadata from both the world and {@link IFacade} blocks in the world.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param side
|
||||
* The side to check for. -1 for unknown.
|
||||
* @return The metadata at this position in the world, or inside an {@link IFacade} block.
|
||||
*/
|
||||
public int getBlockOrFacadeMetadata(IBlockAccess world, int x, int y, int z, int side) {
|
||||
Block blk = world.getBlock(x, y, z);
|
||||
if (blk instanceof IFacade) {
|
||||
return ((IFacade) blk).getFacadeMetadata(world, x, y, z, side);
|
||||
}
|
||||
return world.getBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method to access a block from both the world and {@link IFacade} blocks in the world.
|
||||
*
|
||||
* @param world
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param side
|
||||
* The side to check for. -1 for unknown.
|
||||
* @return The block at this position in the world, or inside an {@link IFacade} block.
|
||||
*/
|
||||
public Block getBlockOrFacade(IBlockAccess world, int x, int y, int z, int side) {
|
||||
Block blk = world.getBlock(x, y, z);
|
||||
if (blk instanceof IFacade) {
|
||||
blk = ((IFacade) blk).getFacade(world, x, y, z, side);
|
||||
}
|
||||
return blk;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
|
||||
public class ClientUtils {
|
||||
|
||||
public static int renderCTMId;
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import static net.minecraftforge.common.util.ForgeDirection.*;
|
||||
|
||||
/**
|
||||
* Think of this class as a "Two dimensional ForgeDirection, with diagonals".
|
||||
* <p>
|
||||
* It represents the eight different directions a face of a block can connect with CTM, and contains the logic for determining if a block is indeed connected in that direction.
|
||||
* <p>
|
||||
* Note that, for example, {@link #TOP_RIGHT} does not mean connected to the {@link #TOP} and {@link #RIGHT}, but connected in the diagonal direction represented by {@link #TOP_RIGHT}. This is used
|
||||
* for inner corner rendering.
|
||||
*/
|
||||
public enum Dir {
|
||||
// @formatter:off
|
||||
TOP(UP),
|
||||
TOP_RIGHT(UP, EAST),
|
||||
RIGHT(EAST),
|
||||
BOTTOM_RIGHT(DOWN, EAST),
|
||||
BOTTOM(DOWN),
|
||||
BOTTOM_LEFT(DOWN, WEST),
|
||||
LEFT(WEST),
|
||||
TOP_LEFT(UP, WEST);
|
||||
// @formatter:on
|
||||
|
||||
/**
|
||||
* All values of this enum, used to prevent unnecessary allocation via {@link #values()}.
|
||||
*/
|
||||
public static final Dir[] VALUES = values();
|
||||
private static final ForgeDirection NORMAL = SOUTH;
|
||||
|
||||
private ForgeDirection[] dirs;
|
||||
|
||||
private Dir(ForgeDirection... dirs) {
|
||||
this.dirs = dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds if this block is connected for the given side in this Dir.
|
||||
*
|
||||
* @param inst
|
||||
* The CTM instance to use for logic.
|
||||
* @param world
|
||||
* The world the block is in.
|
||||
* @param x
|
||||
* The x coordinate of your block.
|
||||
* @param y
|
||||
* The y coordinate of your block.
|
||||
* @param z
|
||||
* The z coordinate of your block.
|
||||
* @param sideIdx
|
||||
* The side index of the current face. This equivalent to {@link ForgeDirection#ordinal()}
|
||||
* @param block
|
||||
* The block being rendered.
|
||||
* @param meta
|
||||
* The metadata of the block.
|
||||
* @return True if the block is connected in the given Dir, false otherwise.
|
||||
*/
|
||||
public boolean isConnected(CTM inst, IBlockAccess world, int x, int y, int z, int sideIdx, Block block, int meta) {
|
||||
ForgeDirection side = getOrientation(sideIdx);
|
||||
ForgeDirection[] dirs = getNormalizedDirs(side);
|
||||
for (ForgeDirection dir : dirs) {
|
||||
x += dir.offsetX;
|
||||
y += dir.offsetY;
|
||||
z += dir.offsetZ;
|
||||
}
|
||||
return inst.isConnected(world, x, y, z, side, block, meta);
|
||||
}
|
||||
|
||||
private ForgeDirection[] getNormalizedDirs(ForgeDirection normal) {
|
||||
if (normal == NORMAL) {
|
||||
return dirs;
|
||||
} else if (normal == NORMAL.getOpposite()) {
|
||||
// If this is the opposite direction of the default normal, we
|
||||
// need to mirror the dirs
|
||||
// A mirror version does not affect y+ and y- so we ignore those
|
||||
ForgeDirection[] ret = new ForgeDirection[dirs.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = dirs[i].offsetY != 0 ? dirs[i] : dirs[i].getOpposite();
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
ForgeDirection axis = null;
|
||||
// Next, we need different a different rotation axis depending
|
||||
// on if this is up/down or not
|
||||
if (normal.offsetY == 0) {
|
||||
// If it is not up/down, pick either the left or right-hand
|
||||
// rotation
|
||||
axis = normal == NORMAL.getRotation(UP) ? UP : DOWN;
|
||||
} else {
|
||||
// If it is up/down, pick either the up or down rotation.
|
||||
axis = normal == UP ? NORMAL.getRotation(DOWN) : NORMAL.getRotation(UP);
|
||||
}
|
||||
ForgeDirection[] ret = new ForgeDirection[dirs.length];
|
||||
// Finally apply all the rotations
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = dirs[i].getRotation(axis);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface ISubmapManager {
|
||||
|
||||
/**
|
||||
* Gets the icon for item rendering, based on side and item metadata.
|
||||
*
|
||||
* @param side
|
||||
* Side of the ItemBlock.
|
||||
* @param meta
|
||||
* Metadata of the ItemBlock.
|
||||
* @return The IIcon for rendering.
|
||||
*/
|
||||
IIcon getIcon(int side, int meta);
|
||||
|
||||
/**
|
||||
* Gets the icon for world rendering, based on world position and side.
|
||||
*/
|
||||
IIcon getIcon(IBlockAccess world, int x, int y, int z, int side);
|
||||
|
||||
/**
|
||||
* Hook for registering any custom icons you might need in this class. Will be called during the normal block method.
|
||||
*
|
||||
* @param modName
|
||||
* The mod ID this submap was registered to.
|
||||
* @param block
|
||||
* The block being registered for.
|
||||
* @param register
|
||||
* The IIconRegister instance.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
void registerIcons(String modName, Block block, IIconRegister register);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
RenderBlocks createRenderContext(RenderBlocks rendererOld, Block block, IBlockAccess world);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void preRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void postRenderSide(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, ForgeDirection side);
|
||||
}
|
||||
@@ -1,533 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import static com.cricketcraft.chisel.api.rendering.RenderBlocksCTM.SubSide.*;
|
||||
import static com.cricketcraft.chisel.api.rendering.RenderBlocksCTM.Vert.*;
|
||||
|
||||
public class RenderBlocksCTM extends RenderBlocks {
|
||||
|
||||
/**
|
||||
* An enum for all possible 26 sub-side vertices.
|
||||
*
|
||||
* The naming scheme is as follows:
|
||||
*
|
||||
* ZERO is a special case, it is the absolute min point of the block. X, Y, Z, or any combination means that the axes listed in the name are at 1. X, Y, Z, or any combination followed by HALF
|
||||
* means that those axes are at 0.5. X, Y, Z, or any combination after a HALF means those axes are at 1.
|
||||
*/
|
||||
protected enum Vert {
|
||||
// @formatter:off
|
||||
ZERO(0, 0, 0),
|
||||
XYZ(1, 1, 1),
|
||||
X(1, 0, 0),
|
||||
Y(0, 1, 0),
|
||||
Z(0, 0, 1),
|
||||
XY(1, 1, 0),
|
||||
YZ(0, 1, 1),
|
||||
XZ(1, 0, 1),
|
||||
X_HALF(0.5, 0, 0),
|
||||
Y_HALF(0, 0.5, 0),
|
||||
Z_HALF(0, 0, 0.5),
|
||||
XY_HALF(0.5, 0.5, 0),
|
||||
YZ_HALF(0, 0.5, 0.5),
|
||||
XZ_HALF(0.5, 0, 0.5),
|
||||
X_HALF_Y(0.5, 1, 0),
|
||||
X_HALF_Z(0.5, 0, 1),
|
||||
Y_HALF_X(1, 0.5, 0),
|
||||
Y_HALF_Z(0, 0.5, 1),
|
||||
Z_HALF_X(1, 0, 0.5),
|
||||
Z_HALF_Y(0, 1, 0.5),
|
||||
X_HALF_YZ(0.5, 1, 1),
|
||||
Y_HALF_XZ(1, 0.5, 1),
|
||||
Z_HALF_XY(1, 1, 0.5),
|
||||
XY_HALF_Z(0.5, 0.5, 1),
|
||||
YZ_HALF_X(1, 0.5, 0.5),
|
||||
XZ_HALF_Y(0.5, 1, 0.5);
|
||||
// @formatter:on
|
||||
|
||||
private double x, y, z;
|
||||
|
||||
private Vert(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static double u, v, xDiff, yDiff, zDiff, uDiff, vDiff;
|
||||
|
||||
void render(RenderBlocksCTM inst, ForgeDirection normal, int cacheID) {
|
||||
if (inst.enableAO) {
|
||||
inst.tessellator.setColorOpaque_F(inst.redCache[cacheID], inst.grnCache[cacheID], inst.bluCache[cacheID]);
|
||||
inst.tessellator.setBrightness(inst.lightingCache[cacheID]);
|
||||
}
|
||||
u = cacheID == 1 || cacheID == 2 ? inst.maxU : inst.minU;
|
||||
v = cacheID < 2 ? inst.maxV : inst.minV;
|
||||
|
||||
uDiff = inst.maxU - inst.minU;
|
||||
vDiff = inst.maxV - inst.minV;
|
||||
|
||||
if (inst.renderMinX + inst.renderMinY + inst.renderMinZ != 0 || inst.renderMaxX + inst.renderMaxY + inst.renderMaxZ != 3) {
|
||||
boolean uMin = u == inst.minU;
|
||||
boolean vMin = v == inst.minV;
|
||||
|
||||
xDiff = inst.renderMaxX - inst.renderMinX;
|
||||
yDiff = inst.renderMaxY - inst.renderMinY;
|
||||
zDiff = inst.renderMaxZ - inst.renderMinZ;
|
||||
|
||||
if (normal.offsetY != 0) {
|
||||
uDiff *= uMin ? inst.renderMinX : 1 - inst.renderMaxX;
|
||||
vDiff *= vMin ? inst.renderMinZ : 1 - inst.renderMaxZ;
|
||||
} else if (normal.offsetX != 0) {
|
||||
uDiff *= uMin ? inst.renderMinZ : 1 - inst.renderMaxZ;
|
||||
vDiff *= vMin ? inst.renderMinY : 1 - inst.renderMaxY;
|
||||
} else if (normal.offsetZ != 0) {
|
||||
uDiff *= uMin ? inst.renderMinX : 1 - inst.renderMaxX;
|
||||
vDiff *= vMin ? inst.renderMinY : 1 - inst.renderMaxY;
|
||||
}
|
||||
u = u == inst.minU ? inst.minU + uDiff : inst.maxU - uDiff;
|
||||
|
||||
v = v == inst.minV ? inst.minV + vDiff : inst.maxV - vDiff;
|
||||
} else {
|
||||
xDiff = yDiff = zDiff = 1;
|
||||
}
|
||||
|
||||
inst.tessellator.addVertexWithUV(inst.renderMinX + (x * xDiff), inst.renderMinY + (y * yDiff), inst.renderMinZ + (z * zDiff), u, v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Each side is divided into 4 sub-sides. LB(left bottom), RB(right bottom), LT(right top), and RT(right top).
|
||||
*
|
||||
* Each sub-side contains 4 {@link Vert} objects representing its position on the block.
|
||||
*/
|
||||
protected enum SubSide {
|
||||
// @formatter:off
|
||||
XNEG_LB(ZERO, Z_HALF, YZ_HALF, Y_HALF), XNEG_RB(Z_HALF, Z, Y_HALF_Z, YZ_HALF), XNEG_RT(YZ_HALF, Y_HALF_Z, YZ, Z_HALF_Y), XNEG_LT(Y_HALF, YZ_HALF, Z_HALF_Y, Y),
|
||||
XPOS_LB(XZ, Z_HALF_X, YZ_HALF_X, Y_HALF_XZ), XPOS_RB(Z_HALF_X, X, Y_HALF_X, YZ_HALF_X), XPOS_RT(YZ_HALF_X, Y_HALF_X, XY, Z_HALF_XY), XPOS_LT(Y_HALF_XZ, YZ_HALF_X, Z_HALF_XY, XYZ),
|
||||
|
||||
ZNEG_LB(X, X_HALF, XY_HALF, Y_HALF_X), ZNEG_RB(X_HALF, ZERO, Y_HALF, XY_HALF), ZNEG_RT(XY_HALF, Y_HALF, Y, X_HALF_Y), ZNEG_LT(Y_HALF_X, XY_HALF, X_HALF_Y, XY),
|
||||
ZPOS_LB(Z, X_HALF_Z, XY_HALF_Z, Y_HALF_Z), ZPOS_RB(X_HALF_Z, XZ, Y_HALF_XZ, XY_HALF_Z), ZPOS_RT(XY_HALF_Z, Y_HALF_XZ, XYZ, X_HALF_YZ), ZPOS_LT(Y_HALF_Z, XY_HALF_Z, X_HALF_YZ, YZ),
|
||||
|
||||
YNEG_LB(ZERO, X_HALF, XZ_HALF, Z_HALF), YNEG_RB(X_HALF, X, Z_HALF_X, XZ_HALF), YNEG_RT(XZ_HALF, Z_HALF_X, XZ, X_HALF_Z), YNEG_LT(Z_HALF, XZ_HALF, X_HALF_Z, Z),
|
||||
YPOS_LB(YZ, X_HALF_YZ, XZ_HALF_Y, Z_HALF_Y), YPOS_RB(X_HALF_YZ, XYZ, Z_HALF_XY, XZ_HALF_Y), YPOS_RT(XZ_HALF_Y, Z_HALF_XY, XY, X_HALF_Y), YPOS_LT(Z_HALF_Y, XZ_HALF_Y, X_HALF_Y, Y);
|
||||
// @formatter:on
|
||||
private Vert xmin, xmax, ymin, ymax;
|
||||
private ForgeDirection normal;
|
||||
|
||||
SubSide(Vert xmin, Vert ymin, Vert ymax, Vert xmax) {
|
||||
this.xmin = xmin;
|
||||
this.ymin = ymin;
|
||||
this.ymax = ymax;
|
||||
this.xmax = xmax;
|
||||
this.normal = calcNormal();
|
||||
}
|
||||
|
||||
private ForgeDirection calcNormal() {
|
||||
double xTot = xmin.x + xmax.x + ymin.x + ymax.x;
|
||||
double yTot = xmin.y + xmax.y + ymin.y + ymax.y;
|
||||
double zTot = xmin.z + xmax.z + ymin.z + ymax.z;
|
||||
if (xTot % 4 == 0) {
|
||||
return xTot > 0 ? ForgeDirection.EAST : ForgeDirection.WEST;
|
||||
} else if (yTot % 4 == 0) {
|
||||
return yTot > 0 ? ForgeDirection.UP : ForgeDirection.DOWN;
|
||||
} else if (zTot % 4 == 0) {
|
||||
return zTot > 0 ? ForgeDirection.SOUTH : ForgeDirection.NORTH;
|
||||
}
|
||||
return ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
void render(RenderBlocksCTM inst) {
|
||||
xmin.render(inst, normal, 0);
|
||||
ymin.render(inst, normal, 1);
|
||||
ymax.render(inst, normal, 2);
|
||||
xmax.render(inst, normal, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public CTM ctm = CTM.getInstance();
|
||||
|
||||
// globals added to save the JVM some trouble. No need to constantly create
|
||||
// and destroy ints if we don't have to
|
||||
protected int blockLightBitChannel = 0;
|
||||
protected int redBitChannel = 0;
|
||||
protected int greenBitChannel = 0;
|
||||
protected int blueBitChannel = 0;
|
||||
protected int sunlightBitChannel = 0;
|
||||
|
||||
public RenderBlocksCTM() {
|
||||
super();
|
||||
renderMaxX = renderMaxY = renderMaxZ = 1;
|
||||
}
|
||||
|
||||
protected Tessellator tessellator = Tessellator.instance;
|
||||
protected double minU, maxU;
|
||||
protected double minV, maxV;
|
||||
protected int[] lightingCache = new int[4];
|
||||
protected float[] redCache = new float[4];
|
||||
protected float[] grnCache = new float[4];
|
||||
protected float[] bluCache = new float[4];
|
||||
public TextureSubmap submap;
|
||||
public TextureSubmap submapSmall;
|
||||
public RenderBlocks rendererOld;
|
||||
public ISubmapManager manager;
|
||||
|
||||
protected int[][] lightmap = new int[3][3];
|
||||
protected float[][] redmap = new float[3][3];
|
||||
protected float[][] grnmap = new float[3][3];
|
||||
protected float[][] blumap = new float[3][3];
|
||||
|
||||
protected int bx, by, bz;
|
||||
|
||||
private boolean inWorld = false;
|
||||
|
||||
@Override
|
||||
public boolean renderStandardBlock(Block block, int x, int y, int z) {
|
||||
bx = x;
|
||||
by = y;
|
||||
bz = z;
|
||||
|
||||
tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
|
||||
tessellator.addTranslation(x, y, z);
|
||||
inWorld = true;
|
||||
boolean res = super.renderStandardBlock(block, x, y, z);
|
||||
inWorld = false;
|
||||
tessellator.addTranslation(-x, -y, -z);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* @formatter:off
|
||||
* This method fills a 3x3 grid of light values based on the four corners, by averaging them together.
|
||||
*
|
||||
* 2 TL x TR
|
||||
*
|
||||
* 1 x x x
|
||||
*
|
||||
* 0 BL x BR
|
||||
* 0 1 2
|
||||
*
|
||||
* Note: Variable names mean nothing... don't touch
|
||||
*
|
||||
* ._.
|
||||
*
|
||||
* shakes fist in anger
|
||||
*/
|
||||
// @formatter:on
|
||||
protected void fillLightmap(int bottomLeft, int bottomRight, int topRight, int topLeft) {
|
||||
lightmap[0][0] = bottomLeft;
|
||||
lightmap[2][0] = bottomRight;
|
||||
lightmap[2][2] = topRight;
|
||||
lightmap[0][2] = topLeft;
|
||||
|
||||
lightmap[1][0] = avg(bottomLeft, bottomRight);
|
||||
lightmap[2][1] = avg(bottomRight, topRight);
|
||||
lightmap[1][2] = avg(topRight, topLeft);
|
||||
lightmap[0][1] = avg(topLeft, bottomLeft);
|
||||
|
||||
lightmap[1][1] = avg(bottomLeft, bottomRight, topRight, topLeft);
|
||||
}
|
||||
|
||||
protected void fillColormap(float bottomLeft, float bottomRight, float topRight, float topLeft, float[][] map) {
|
||||
map[0][0] = bottomLeft;
|
||||
map[2][0] = bottomRight;
|
||||
map[2][2] = topRight;
|
||||
map[0][2] = topLeft;
|
||||
|
||||
map[1][0] = (bottomLeft + bottomRight) / 2.0F;
|
||||
map[2][1] = (bottomRight + topRight) / 2.0F;
|
||||
map[1][2] = (topRight + topLeft) / 2.0F;
|
||||
map[0][1] = (topLeft + bottomLeft) / 2.0F;
|
||||
|
||||
map[1][1] = (bottomLeft + bottomRight + topRight + topLeft) / 4.0F;
|
||||
}
|
||||
|
||||
protected void getLight(int x, int y) {
|
||||
lightingCache[0] = lightmap[0 + x][0 + y];
|
||||
lightingCache[1] = lightmap[1 + x][0 + y];
|
||||
lightingCache[2] = lightmap[1 + x][1 + y];
|
||||
lightingCache[3] = lightmap[0 + x][1 + y];
|
||||
|
||||
redCache[0] = redmap[0 + x][0 + y];
|
||||
redCache[1] = redmap[1 + x][0 + y];
|
||||
redCache[2] = redmap[1 + x][1 + y];
|
||||
redCache[3] = redmap[0 + x][1 + y];
|
||||
|
||||
grnCache[0] = grnmap[0 + x][0 + y];
|
||||
grnCache[1] = grnmap[1 + x][0 + y];
|
||||
grnCache[2] = grnmap[1 + x][1 + y];
|
||||
grnCache[3] = grnmap[0 + x][1 + y];
|
||||
|
||||
bluCache[0] = blumap[0 + x][0 + y];
|
||||
bluCache[1] = blumap[1 + x][0 + y];
|
||||
bluCache[2] = blumap[1 + x][1 + y];
|
||||
bluCache[3] = blumap[0 + x][1 + y];
|
||||
}
|
||||
|
||||
/**
|
||||
* This works around a bug in CLC atm
|
||||
*/
|
||||
private int avg(int... lightVals) {
|
||||
blockLightBitChannel = 0;
|
||||
redBitChannel = 0;
|
||||
greenBitChannel = 0;
|
||||
blueBitChannel = 0;
|
||||
sunlightBitChannel = 0;
|
||||
|
||||
for (int light : lightVals) {
|
||||
blockLightBitChannel += (light & 0xFF);
|
||||
redBitChannel += (light & 0xF00);
|
||||
greenBitChannel += (light & 0xF000);
|
||||
blueBitChannel += (light & 0xF0000);
|
||||
sunlightBitChannel += (light & 0xF00000);
|
||||
}
|
||||
|
||||
return ((blockLightBitChannel / lightVals.length) & 0xFF) | ((redBitChannel / lightVals.length) & 0xF00) | ((greenBitChannel / lightVals.length) & 0xF000)
|
||||
| ((blueBitChannel / lightVals.length) & 0xF0000) | ((sunlightBitChannel / lightVals.length) & 0xF00000);
|
||||
}
|
||||
|
||||
protected void side(Block block, SubSide side, int iconIndex) {
|
||||
|
||||
IIcon icon;
|
||||
TextureSubmap map;
|
||||
if (iconIndex >= 16) {
|
||||
iconIndex -= 16;
|
||||
map = submapSmall;
|
||||
} else {
|
||||
map = submap;
|
||||
}
|
||||
|
||||
if (map == null) {
|
||||
icon = getBlockIconFromSide(block, side.normal.ordinal());
|
||||
} else {
|
||||
int x = iconIndex % map.getWidth();
|
||||
int y = iconIndex / map.getHeight();
|
||||
icon = map.getSubIcon(x, y);
|
||||
}
|
||||
|
||||
double umax = icon.getMaxU();
|
||||
double umin = icon.getMinU();
|
||||
double vmax = icon.getMaxV();
|
||||
double vmin = icon.getMinV();
|
||||
|
||||
minU = umin;
|
||||
maxU = umax;
|
||||
minV = vmin;
|
||||
maxV = vmax;
|
||||
|
||||
// uCache[0] = umin;
|
||||
// uCache[1] = umax;
|
||||
// uCache[2] = umax;
|
||||
// uCache[3] = umin;
|
||||
//
|
||||
// vCache[0] = vmax;
|
||||
// vCache[1] = vmax;
|
||||
// vCache[2] = vmin;
|
||||
// vCache[3] = vmin;
|
||||
|
||||
side.render(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceXNeg(Block block, double x, double y, double z, IIcon icon) {
|
||||
if (!inWorld || (rendererOld != null && rendererOld.hasOverrideBlockTexture())) {
|
||||
IIcon i = rendererOld.hasOverrideBlockTexture() ? rendererOld.overrideBlockTexture : icon;
|
||||
|
||||
tessellator.addVertexWithUV(renderMinX, renderMaxY, renderMinZ, i.getMinU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMinY, renderMinZ, i.getMinU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMinY, renderMaxZ, i.getMaxU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMaxY, renderMaxZ, i.getMaxU(), i.getMinV());
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 4);
|
||||
|
||||
pre(ForgeDirection.WEST);
|
||||
|
||||
fillLightmap(brightnessBottomRight, brightnessTopRight, brightnessTopLeft, brightnessBottomLeft);
|
||||
fillColormap(colorRedBottomRight, colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, redmap);
|
||||
fillColormap(colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, colorGreenBottomLeft, grnmap);
|
||||
fillColormap(colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, colorBlueBottomLeft, blumap);
|
||||
|
||||
getLight(0, 0);
|
||||
side(block, XNEG_LB, tex[0]);
|
||||
getLight(1, 0);
|
||||
side(block, XNEG_RB, tex[1]);
|
||||
getLight(1, 1);
|
||||
side(block, XNEG_RT, tex[2]);
|
||||
getLight(0, 1);
|
||||
side(block, XNEG_LT, tex[3]);
|
||||
|
||||
post(ForgeDirection.WEST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceXPos(Block block, double x, double y, double z, IIcon icon) {
|
||||
if (!inWorld || (rendererOld != null && rendererOld.hasOverrideBlockTexture())) {
|
||||
IIcon i = rendererOld.hasOverrideBlockTexture() ? rendererOld.overrideBlockTexture : icon;
|
||||
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMaxY, renderMaxZ, i.getMaxU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMinY, renderMaxZ, i.getMaxU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMinY, renderMinZ, i.getMinU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMaxY, renderMinZ, i.getMinU(), i.getMinV());
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 5);
|
||||
|
||||
pre(ForgeDirection.EAST);
|
||||
|
||||
fillLightmap(brightnessTopLeft, brightnessBottomLeft, brightnessBottomRight, brightnessTopRight);
|
||||
fillColormap(colorRedTopLeft, colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, redmap);
|
||||
fillColormap(colorGreenTopLeft, colorGreenBottomLeft, colorGreenBottomRight, colorGreenTopRight, grnmap);
|
||||
fillColormap(colorBlueTopLeft, colorBlueBottomLeft, colorBlueBottomRight, colorBlueTopRight, blumap);
|
||||
|
||||
getLight(0, 0);
|
||||
side(block, XPOS_LB, tex[0]);
|
||||
getLight(1, 0);
|
||||
side(block, XPOS_RB, tex[1]);
|
||||
getLight(1, 1);
|
||||
side(block, XPOS_RT, tex[2]);
|
||||
getLight(0, 1);
|
||||
side(block, XPOS_LT, tex[3]);
|
||||
|
||||
post(ForgeDirection.EAST);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceZNeg(Block block, double x, double y, double z, IIcon icon) {
|
||||
if (!inWorld || (rendererOld != null && rendererOld.hasOverrideBlockTexture())) {
|
||||
IIcon i = rendererOld.hasOverrideBlockTexture() ? rendererOld.overrideBlockTexture : icon;
|
||||
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMaxY, renderMinZ, i.getMaxU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMinY, renderMinZ, i.getMaxU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMinY, renderMinZ, i.getMinU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMaxY, renderMinZ, i.getMinU(), i.getMinV());
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 2);
|
||||
|
||||
pre(ForgeDirection.NORTH);
|
||||
|
||||
fillLightmap(brightnessBottomRight, brightnessTopRight, brightnessTopLeft, brightnessBottomLeft);
|
||||
fillColormap(colorRedBottomRight, colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, redmap);
|
||||
fillColormap(colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, colorGreenBottomLeft, grnmap);
|
||||
fillColormap(colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, colorBlueBottomLeft, blumap);
|
||||
|
||||
getLight(0, 0);
|
||||
side(block, ZNEG_LB, tex[0]);
|
||||
getLight(1, 0);
|
||||
side(block, ZNEG_RB, tex[1]);
|
||||
getLight(1, 1);
|
||||
side(block, ZNEG_RT, tex[2]);
|
||||
getLight(0, 1);
|
||||
side(block, ZNEG_LT, tex[3]);
|
||||
|
||||
post(ForgeDirection.NORTH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceZPos(Block block, double x, double y, double z, IIcon icon) {
|
||||
if (!inWorld || (rendererOld != null && rendererOld.hasOverrideBlockTexture())) {
|
||||
IIcon i = rendererOld.hasOverrideBlockTexture() ? rendererOld.overrideBlockTexture : icon;
|
||||
|
||||
tessellator.addVertexWithUV(renderMinX, renderMaxY, renderMaxZ, i.getMinU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMinY, renderMaxZ, i.getMinU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMinY, renderMaxZ, i.getMaxU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMaxY, renderMaxZ, i.getMaxU(), i.getMinV());
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 3);
|
||||
|
||||
pre(ForgeDirection.SOUTH);
|
||||
|
||||
fillLightmap(brightnessBottomLeft, brightnessBottomRight, brightnessTopRight, brightnessTopLeft);
|
||||
fillColormap(colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, colorRedTopLeft, redmap);
|
||||
fillColormap(colorGreenBottomLeft, colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, grnmap);
|
||||
fillColormap(colorBlueBottomLeft, colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, blumap);
|
||||
|
||||
getLight(0, 0);
|
||||
side(block, ZPOS_LB, tex[0]);
|
||||
getLight(1, 0);
|
||||
side(block, ZPOS_RB, tex[1]);
|
||||
getLight(1, 1);
|
||||
side(block, ZPOS_RT, tex[2]);
|
||||
getLight(0, 1);
|
||||
side(block, ZPOS_LT, tex[3]);
|
||||
|
||||
post(ForgeDirection.SOUTH);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceYNeg(Block block, double x, double y, double z, IIcon icon) {
|
||||
if (!inWorld || (rendererOld != null && rendererOld.hasOverrideBlockTexture())) {
|
||||
IIcon i = rendererOld.hasOverrideBlockTexture() ? rendererOld.overrideBlockTexture : icon;
|
||||
|
||||
tessellator.addVertexWithUV(renderMinX, renderMinY, renderMaxZ, i.getMinU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMinY, renderMinZ, i.getMinU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMinY, renderMinZ, i.getMaxU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMinY, renderMaxZ, i.getMaxU(), i.getMaxV());
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 0);
|
||||
|
||||
pre(ForgeDirection.DOWN);
|
||||
|
||||
fillLightmap(brightnessBottomLeft, brightnessBottomRight, brightnessTopRight, brightnessTopLeft);
|
||||
fillColormap(colorRedBottomLeft, colorRedBottomRight, colorRedTopRight, colorRedTopLeft, redmap);
|
||||
fillColormap(colorGreenBottomLeft, colorGreenBottomRight, colorGreenTopRight, colorGreenTopLeft, grnmap);
|
||||
fillColormap(colorBlueBottomLeft, colorBlueBottomRight, colorBlueTopRight, colorBlueTopLeft, blumap);
|
||||
|
||||
getLight(0, 0);
|
||||
side(block, YNEG_LB, tex[0]);
|
||||
getLight(1, 0);
|
||||
side(block, YNEG_RB, tex[1]);
|
||||
getLight(1, 1);
|
||||
side(block, YNEG_RT, tex[2]);
|
||||
getLight(0, 1);
|
||||
side(block, YNEG_LT, tex[3]);
|
||||
|
||||
post(ForgeDirection.DOWN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceYPos(Block block, double x, double y, double z, IIcon icon) {
|
||||
if (!inWorld || (rendererOld != null && rendererOld.hasOverrideBlockTexture())) {
|
||||
IIcon i = rendererOld.hasOverrideBlockTexture() ? rendererOld.overrideBlockTexture : icon;
|
||||
|
||||
tessellator.addVertexWithUV(renderMinX, renderMaxY, renderMinZ, i.getMinU(), i.getMinV());
|
||||
tessellator.addVertexWithUV(renderMinX, renderMaxY, renderMaxZ, i.getMinU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMaxY, renderMaxZ, i.getMaxU(), i.getMaxV());
|
||||
tessellator.addVertexWithUV(renderMaxX, renderMaxY, renderMinZ, i.getMaxU(), i.getMinV());
|
||||
} else {
|
||||
int tex[] = ctm.getSubmapIndices(blockAccess, bx, by, bz, 1);
|
||||
|
||||
pre(ForgeDirection.UP);
|
||||
|
||||
fillLightmap(brightnessTopRight, brightnessTopLeft, brightnessBottomLeft, brightnessBottomRight);
|
||||
fillColormap(colorRedTopRight, colorRedTopLeft, colorRedBottomLeft, colorRedBottomRight, redmap);
|
||||
fillColormap(colorGreenTopRight, colorGreenTopLeft, colorGreenBottomLeft, colorGreenBottomRight, grnmap);
|
||||
fillColormap(colorBlueTopRight, colorBlueTopLeft, colorBlueBottomLeft, colorBlueBottomRight, blumap);
|
||||
|
||||
getLight(0, 0);
|
||||
side(block, YPOS_LB, tex[0]);
|
||||
getLight(1, 0);
|
||||
side(block, YPOS_RB, tex[1]);
|
||||
getLight(1, 1);
|
||||
side(block, YPOS_RT, tex[2]);
|
||||
getLight(0, 1);
|
||||
side(block, YPOS_LT, tex[3]);
|
||||
|
||||
post(ForgeDirection.UP);
|
||||
}
|
||||
}
|
||||
|
||||
protected void pre(ForgeDirection face) {
|
||||
manager.preRenderSide(this, blockAccess, bx, by, bz, face);
|
||||
}
|
||||
|
||||
protected void post(ForgeDirection face) {
|
||||
manager.postRenderSide(this, blockAccess, bx, by, bz, face);
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
/**
|
||||
* Used by {@link TextureType#CTMV}, slated to be rewritten. Do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
public class RenderBlocksColumn extends RenderBlocks {
|
||||
|
||||
public TextureSubmap submap;
|
||||
public IIcon iconTop;
|
||||
|
||||
private IIcon sides[] = new IIcon[6];
|
||||
private CTM ctm = CTM.getInstance();
|
||||
|
||||
public RenderBlocksColumn() {
|
||||
super();
|
||||
}
|
||||
|
||||
boolean connected(IBlockAccess world, int x, int y, int z, Block block, int meta) {
|
||||
Block inWorld = ctm.getBlockOrFacade(world, x, y, z, -1);
|
||||
return inWorld != null && inWorld.equals(block) && ctm.getBlockOrFacadeMetadata(world, x, y, z, -1) == meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderStandardBlock(Block block, int x, int y, int z) {
|
||||
int metadata = blockAccess.getBlockMetadata(x, y, z);
|
||||
|
||||
boolean yp = connected(blockAccess, x, y + 1, z, block, metadata);
|
||||
boolean yn = connected(blockAccess, x, y - 1, z, block, metadata);
|
||||
|
||||
if (yp || yn) {
|
||||
sides[0] = iconTop;
|
||||
sides[1] = iconTop;
|
||||
|
||||
if (yp && yn)
|
||||
sides[2] = submap.getSubIcon(0, 1);
|
||||
else if (yp)
|
||||
sides[2] = submap.getSubIcon(1, 1);
|
||||
else
|
||||
sides[2] = submap.getSubIcon(1, 0);
|
||||
|
||||
sides[3] = sides[4] = sides[5] = sides[2];
|
||||
} else {
|
||||
boolean xp = connected(blockAccess, x + 1, y, z, block, metadata);
|
||||
boolean xn = connected(blockAccess, x - 1, y, z, block, metadata);
|
||||
|
||||
if (xp && (connected(blockAccess, x + 1, y + 1, z, block, metadata) || connected(blockAccess, x + 1, y - 1, z, block, metadata)))
|
||||
xp = false;
|
||||
if (xn && (connected(blockAccess, x - 1, y + 1, z, block, metadata) || connected(blockAccess, x - 1, y - 1, z, block, metadata)))
|
||||
xn = false;
|
||||
|
||||
if (xp || xn) {
|
||||
uvRotateEast = 2;
|
||||
uvRotateWest = 1;
|
||||
uvRotateTop = 1;
|
||||
uvRotateBottom = 1;
|
||||
|
||||
sides[4] = iconTop;
|
||||
sides[5] = iconTop;
|
||||
|
||||
// for some reason along the x axis the bottom texture on the ends is backwards. This flips it around.
|
||||
if (xp && xn) {
|
||||
sides[1] = submap.getSubIcon(0, 1);
|
||||
sides[0] = sides[1];
|
||||
} else if (xp) {
|
||||
sides[1] = submap.getSubIcon(1, 1);
|
||||
sides[0] = submap.getSubIcon(1, 0);
|
||||
} else {
|
||||
sides[1] = submap.getSubIcon(1, 0);
|
||||
sides[0] = submap.getSubIcon(1, 1);
|
||||
}
|
||||
sides[2] = sides[3] = sides[1];
|
||||
} else {
|
||||
boolean zp = connected(blockAccess, x, y, z + 1, block, metadata);
|
||||
boolean zn = connected(blockAccess, x, y, z - 1, block, metadata);
|
||||
|
||||
if (zp && (connected(blockAccess, x, y + 1, z + 1, block, metadata) || connected(blockAccess, x, y - 1, z + 1, block, metadata)))
|
||||
zp = false;
|
||||
if (zp && (connected(blockAccess, x + 1, y, z + 1, block, metadata) || connected(blockAccess, x - 1, y, z + 1, block, metadata)))
|
||||
zp = false;
|
||||
if (zn && (connected(blockAccess, x, y + 1, z - 1, block, metadata) || connected(blockAccess, x, y - 1, z - 1, block, metadata)))
|
||||
zn = false;
|
||||
if (zn && (connected(blockAccess, x + 1, y, z - 1, block, metadata) || connected(blockAccess, x - 1, y, z - 1, block, metadata)))
|
||||
zn = false;
|
||||
|
||||
if (zp || zn) {
|
||||
uvRotateSouth = 1;
|
||||
uvRotateNorth = 2;
|
||||
|
||||
sides[2] = iconTop;
|
||||
sides[3] = iconTop;
|
||||
|
||||
if (zp && zn)
|
||||
sides[0] = submap.getSubIcon(0, 1);
|
||||
else if (zp)
|
||||
sides[0] = submap.getSubIcon(1, 0);
|
||||
else
|
||||
sides[0] = submap.getSubIcon(1, 1);
|
||||
|
||||
sides[1] = sides[4] = sides[5] = sides[0];
|
||||
} else {
|
||||
sides[0] = sides[1] = iconTop;
|
||||
sides[2] = sides[3] = sides[4] = sides[5] = submap.getSubIcon(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean flag = super.renderStandardBlock(block, x, y, z);
|
||||
|
||||
uvRotateSouth = 0;
|
||||
uvRotateEast = 0;
|
||||
uvRotateWest = 0;
|
||||
uvRotateNorth = 0;
|
||||
uvRotateTop = 0;
|
||||
uvRotateBottom = 0;
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceXNeg(Block block, double x, double y, double z, IIcon icon) {
|
||||
super.renderFaceXNeg(block, x, y, z, getIcon(icon, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceXPos(Block block, double x, double y, double z, IIcon icon) {
|
||||
super.renderFaceXPos(block, x, y, z, getIcon(icon, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceZNeg(Block block, double x, double y, double z, IIcon icon) {
|
||||
super.renderFaceZNeg(block, x, y, z, getIcon(icon, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceZPos(Block block, double x, double y, double z, IIcon icon) {
|
||||
super.renderFaceZPos(block, x, y, z, getIcon(icon, 3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceYNeg(Block block, double x, double y, double z, IIcon icon) {
|
||||
super.renderFaceYNeg(block, x, y, z, getIcon(icon, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderFaceYPos(Block block, double x, double y, double z, IIcon icon) {
|
||||
super.renderFaceYPos(block, x, y, z, getIcon(icon, 1));
|
||||
}
|
||||
|
||||
private IIcon getIcon(IIcon defaultIcon, int side) {
|
||||
return sides[side] == null ? defaultIcon : sides[side];
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
package com.cricketcraft.chisel.api.rendering;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* This class is used to split up a large IIcon into smaller "submapped" icons used for CTM and other texture manipulation.
|
||||
*/
|
||||
public class TextureSubmap {
|
||||
|
||||
private static List<TextureSubmap> submaps = Lists.newArrayList();
|
||||
private static TextureSubmap dummy = new TextureSubmap(null, 0, 0);
|
||||
static {
|
||||
MinecraftForge.EVENT_BUS.register(dummy);
|
||||
}
|
||||
|
||||
private int width, height;
|
||||
private IIcon baseIcon;
|
||||
private IIcon[][] icons;
|
||||
|
||||
/**
|
||||
* Construct a new submap. A submap is not required to be square, but it is required to be rectangular.
|
||||
*
|
||||
* @param baseIcon
|
||||
* The IIcon to submap.
|
||||
* @param width
|
||||
* The width of the map, in icons.
|
||||
* @param height
|
||||
* The height of the map, in icons.
|
||||
*/
|
||||
public TextureSubmap(IIcon baseIcon, int width, int height) {
|
||||
this.baseIcon = baseIcon;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.icons = new IIcon[width][height];
|
||||
submaps.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The width, in icons, of the submap.
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* The height, in icons, of the submap.
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* The large "base" icon used for the submap.
|
||||
*/
|
||||
public IIcon getBaseIcon() {
|
||||
return baseIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns the sub-icon at the given coordinates. For example, if you have a 3 by 3 submap, calling {@code getSubIcon(1, 1)} will return the center subicon.
|
||||
*/
|
||||
public IIcon getSubIcon(int x, int y) {
|
||||
x = x % icons.length;
|
||||
return icons[x][y % icons[x].length];
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal use only, this is used to create the virtual "subicons" used in the map.
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public final void TexturesStitched(TextureStitchEvent.Post event) {
|
||||
for (TextureSubmap ts : submaps) {
|
||||
for (int x = 0; x < ts.width; x++) {
|
||||
for (int y = 0; y < ts.height; y++) {
|
||||
ts.icons[x][y] = new TextureVirtual(ts.getBaseIcon(), ts.width, ts.height, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TextureVirtual implements IIcon {
|
||||
|
||||
private int width, height;
|
||||
private float umin, umax, vmin, vmax;
|
||||
private String name;
|
||||
private IIcon parentIcon;
|
||||
|
||||
private TextureVirtual(IIcon parent, int w, int h, int x, int y) {
|
||||
parentIcon = parent;
|
||||
|
||||
umin = parentIcon.getInterpolatedU(16.0 * (x) / w);
|
||||
umax = parentIcon.getInterpolatedU(16.0 * (x + 1) / w);
|
||||
vmin = parentIcon.getInterpolatedV(16.0 * (y) / h);
|
||||
vmax = parentIcon.getInterpolatedV(16.0 * (y + 1) / h);
|
||||
|
||||
name = parentIcon.getIconName() + "|" + x + "." + y;
|
||||
|
||||
width = parentIcon.getIconWidth();
|
||||
height = parentIcon.getIconHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMinU() {
|
||||
return umin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMaxU() {
|
||||
return umax;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getInterpolatedU(double d0) {
|
||||
return (float) (umin + (umax - umin) * d0 / 16.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMinV() {
|
||||
return vmin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getMaxV() {
|
||||
return vmax;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getInterpolatedV(double d0) {
|
||||
return (float) (vmin + (vmax - vmin) * d0 / 16.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getIconName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getIconWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getIconHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ import org.apache.commons.lang3.tuple.Triple;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
import com.cricketcraft.ctmlib.CTM;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
import com.cricketcraft.ctmlib.RenderBlocksCTM;
|
||||
import com.cricketcraft.ctmlib.RenderBlocksColumn;
|
||||
import com.cricketcraft.ctmlib.TextureSubmap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -15,8 +15,8 @@ import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.chisel.init.ChiselTabs;
|
||||
import com.cricketcraft.ctmlib.ClientUtils;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.ctmlib.ClientUtils;
|
||||
|
||||
public class BlockCarvableCarpet extends BlockCarpet implements ICarvable {
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.world.IBlockAccess;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.chisel.init.ChiselTabs;
|
||||
import com.cricketcraft.ctmlib.ClientUtils;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.world.World;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.ctmlib.ClientUtils;
|
||||
|
||||
public class BlockCarvableIce extends BlockIce implements ICarvable {
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.world.World;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.ctmlib.ClientUtils;
|
||||
|
||||
public class BlockCarvablePackedIce extends Block implements ICarvable {
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.chisel.init.ChiselTabs;
|
||||
import com.cricketcraft.ctmlib.ClientUtils;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.cricketcraft.chisel.client.render;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.api.carving.IVariationInfo;
|
||||
import com.cricketcraft.chisel.api.rendering.ClientUtils;
|
||||
import com.cricketcraft.chisel.api.rendering.RenderBlocksCTM;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
public class RendererCTM implements ISimpleBlockRenderingHandler {
|
||||
|
||||
public RenderBlocksCTM rendererCTM = new RenderBlocksCTM();
|
||||
|
||||
public RendererCTM() {
|
||||
if (ClientUtils.renderCTMId == 0) {
|
||||
ClientUtils.renderCTMId = RenderingRegistry.getNextAvailableRenderId();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
|
||||
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||
IVariationInfo var = ((ICarvable) block).getVariation(new ItemStack(block, 1, metadata));
|
||||
Drawing.drawBlock(block, metadata, getContext(renderer, block, Minecraft.getMinecraft().theWorld, var, metadata));
|
||||
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 rendererOld) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
IVariationInfo var = ((ICarvable) block).getVariation(world, x, y, z, meta);
|
||||
return getContext(rendererOld, block, world, var, meta).renderStandardBlock(block, x, y, z);
|
||||
}
|
||||
|
||||
private RenderBlocks getContext(RenderBlocks rendererOld, Block block, IBlockAccess world, IVariationInfo var, int meta) {
|
||||
if (!rendererOld.hasOverrideBlockTexture() && var != null) {
|
||||
RenderBlocks rb = var.getSubmapManager().createRenderContext(rendererOld, block, world);
|
||||
if (rb != null && rb != rendererOld) {
|
||||
rb.blockAccess = world;
|
||||
if (rb instanceof RenderBlocksCTM) {
|
||||
RenderBlocksCTM rbctm = (RenderBlocksCTM) rb;
|
||||
rbctm.manager = rbctm.manager == null ? var.getSubmapManager() : rbctm.manager;
|
||||
rbctm.rendererOld = rbctm.rendererOld == null ? rendererOld : rbctm.rendererOld;
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
return rendererOld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender3DInInventory(int renderId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return ClientUtils.renderCTMId;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -10,8 +10,8 @@ import org.lwjgl.opengl.GL11;
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.block.BlockCarvableGlow;
|
||||
import com.cricketcraft.chisel.config.Configurations;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.chisel.utils.GeneralClient;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.cricketcraft.chisel.client.render;
|
||||
|
||||
import com.cricketcraft.chisel.block.BlockMultiLayerBase;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
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.init.Blocks;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class RendererMultiLayer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.block.BlockRoadLine;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.block.BlockCarvableLayered;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.block.BlockSnakestone;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.chisel.block.BlockCarvableStairs;
|
||||
import com.cricketcraft.chisel.utils.Drawing;
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
@@ -6,8 +6,8 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.RenderBlocksCTM;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureSubmap;
|
||||
import com.cricketcraft.ctmlib.RenderBlocksCTM;
|
||||
import com.cricketcraft.ctmlib.TextureSubmap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -6,8 +6,8 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.RenderBlocksCTM;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureSubmap;
|
||||
import com.cricketcraft.ctmlib.RenderBlocksCTM;
|
||||
import com.cricketcraft.ctmlib.TextureSubmap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
+4
-4
@@ -5,15 +5,15 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.CTM;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureSubmap;
|
||||
import com.cricketcraft.chisel.init.ChiselBlocks;
|
||||
import com.cricketcraft.ctmlib.CTM;
|
||||
import com.cricketcraft.ctmlib.TextureSubmap;
|
||||
|
||||
import static com.cricketcraft.ctmlib.Dir.*;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import static com.cricketcraft.chisel.api.rendering.Dir.*;
|
||||
|
||||
public class SubmapManagerFakeController extends SubmapManagerBase {
|
||||
|
||||
private TextureSubmap map;
|
||||
|
||||
@@ -7,9 +7,9 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.ISubmapManager;
|
||||
import com.cricketcraft.chisel.api.rendering.RenderBlocksCTM;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureSubmap;
|
||||
import com.cricketcraft.ctmlib.ISubmapManager;
|
||||
import com.cricketcraft.ctmlib.RenderBlocksCTM;
|
||||
import com.cricketcraft.ctmlib.TextureSubmap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.cricketcraft.chisel.client.render;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.cricketcraft.chisel.api.rendering.TextureSubmap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
@@ -10,6 +7,10 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.api.rendering.TextureType;
|
||||
import com.cricketcraft.ctmlib.TextureSubmap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.cricketcraft.chisel.config;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.Features;
|
||||
import com.cricketcraft.chisel.api.rendering.CTM;
|
||||
import com.cricketcraft.ctmlib.CTM;
|
||||
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
@@ -37,7 +37,6 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerBlockHandler(new RendererRoadLine());
|
||||
RenderingRegistry.registerBlockHandler(new RendererSnakeStone());
|
||||
RenderingRegistry.registerBlockHandler(new RendererEldritch());
|
||||
RenderingRegistry.registerBlockHandler(new RendererCTM());
|
||||
RenderingRegistry.registerBlockHandler(new RendererLayeredGlow());
|
||||
RenderingRegistry.registerBlockHandler(new RendererSimpleLayered());
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.cricketcraft.ctmlib.Drawing;
|
||||
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.cricketcraft.chisel.utils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class Drawing {
|
||||
|
||||
public static void drawBlock(Block block, IIcon icon, RenderBlocks renderer) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, -1.0F, 0.0F);
|
||||
renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, icon);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
||||
renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, icon);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 0.0F, -1.0F);
|
||||
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, icon);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 0.0F, 1.0F);
|
||||
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, icon);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
|
||||
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, icon);
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(1.0F, 0.0F, 0.0F);
|
||||
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, icon);
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void drawBlock(Block block, int meta, RenderBlocks renderer) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, -1.0F, 0.0F);
|
||||
renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(0, meta));
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
||||
renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(1, meta));
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 0.0F, -1.0F);
|
||||
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(2, meta));
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, 0.0F, 1.0F);
|
||||
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(3, meta));
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
|
||||
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(4, meta));
|
||||
tessellator.draw();
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(1.0F, 0.0F, 0.0F);
|
||||
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(5, meta));
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void renderAllFaces(RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon) {
|
||||
renderer.renderFaceYNeg(block, x, y, z, icon);
|
||||
renderer.renderFaceYPos(block, x, y, z, icon);
|
||||
renderer.renderFaceZNeg(block, x, y, z, icon);
|
||||
renderer.renderFaceZPos(block, x, y, z, icon);
|
||||
renderer.renderFaceXNeg(block, x, y, z, icon);
|
||||
renderer.renderFaceXPos(block, x, y, z, icon);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user