Split renderdata (generated data) from normal block data - to help

with custom block work
This commit is contained in:
Mike Primm 2011-08-29 14:21:39 -05:00
parent af1f47df23
commit 13bf8d7733
5 changed files with 51 additions and 28 deletions

View File

@ -31,11 +31,11 @@ public class HDBlockModels {
public static class HDScaledBlockModels {
private short[][][] modelvectors;
public final short[] getScaledModel(int blocktype, int blockdata) {
public final short[] getScaledModel(int blocktype, int blockdata, int blockrenderdata) {
if(modelvectors[blocktype] == null) {
return null;
}
return modelvectors[blocktype][blockdata];
return modelvectors[blocktype][(blockrenderdata>=0)?blockrenderdata:blockdata];
}
}

View File

@ -20,6 +20,10 @@ public interface HDPerspectiveState {
* Get current block data
*/
int getBlockData();
/**
* Get current block render data
*/
int getBlockRenderData();
/**
* Get direction of last block step
*/

View File

@ -95,6 +95,7 @@ public class IsoHDPerspective implements HDPerspective {
private class OurPerspectiveState implements HDPerspectiveState {
int blocktypeid = 0;
int blockdata = 0;
int blockrenderdata = -1;
int lastblocktypeid = 0;
Vector3D top, bottom;
int px, py;
@ -193,6 +194,10 @@ public class IsoHDPerspective implements HDPerspective {
* Get current block data
*/
public final int getBlockData() { return blockdata; }
/**
* Get current block render data
*/
public final int getBlockRenderData() { return blockrenderdata; }
/**
* Get direction of last block step
*/
@ -473,22 +478,23 @@ public class IsoHDPerspective implements HDPerspective {
skiptoair = false;
}
else if(nonairhit || (blocktypeid != 0)) {
blockdata = mapiter.getBlockData();
switch(blocktypeid) {
case FENCE_BLKTYPEID: /* Special case for fence - need to fake data so we can render properly */
blockdata = generateFenceBlockData(mapiter);
blockrenderdata = generateFenceBlockData(mapiter);
break;
case CHEST_BLKTYPEID: /* Special case for chest - need to fake data so we can render */
blockdata = generateChestBlockData(mapiter);
blockrenderdata = generateChestBlockData(mapiter);
break;
case REDSTONE_BLKTYPEID: /* Special case for redstone - fake data for wire pattern */
blockdata = generateRedstoneWireBlockData(mapiter);
blockrenderdata = generateRedstoneWireBlockData(mapiter);
break;
default:
blockdata = mapiter.getBlockData();
break;
blockrenderdata = -1;
break;
}
/* Look up to see if block is modelled */
short[] model = scalemodels.getScaledModel(blocktypeid, blockdata);
short[] model = scalemodels.getScaledModel(blocktypeid, blockdata, blockrenderdata);
if(model != null) {
return handleSubModel(model, shaderstate, shaderdone);
}

View File

@ -120,12 +120,15 @@ public class TexturePack {
private List<Integer> blockids;
private int databits;
private BlockTransparency bt;
private boolean userender;
private static HDTextureMap[] texmaps;
private static BlockTransparency transp[];
private static boolean userenderdata[];
private static void initializeTable() {
texmaps = new HDTextureMap[16*BLOCKTABLELEN];
transp = new BlockTransparency[BLOCKTABLELEN];
userenderdata = new boolean[BLOCKTABLELEN];
HDTextureMap blank = new HDTextureMap();
for(int i = 0; i < texmaps.length; i++)
texmaps[i] = blank;
@ -136,6 +139,7 @@ public class TexturePack {
private HDTextureMap() {
blockids = Collections.singletonList(Integer.valueOf(0));
databits = 0xFFFF;
userender = false;
faces = new int[] { BLOCKINDEX_BLANK, BLOCKINDEX_BLANK, BLOCKINDEX_BLANK, BLOCKINDEX_BLANK, BLOCKINDEX_BLANK, BLOCKINDEX_BLANK };
for(int i = 0; i < texmaps.length; i++) {
@ -143,11 +147,12 @@ public class TexturePack {
}
}
public HDTextureMap(List<Integer> blockids, int databits, int[] faces, BlockTransparency trans) {
public HDTextureMap(List<Integer> blockids, int databits, int[] faces, BlockTransparency trans, boolean userender) {
this.faces = faces;
this.blockids = blockids;
this.databits = databits;
this.bt = trans;
this.userender = userender;
}
public void addToTable() {
@ -159,11 +164,15 @@ public class TexturePack {
}
}
transp[blkid] = bt; /* Transparency is only blocktype based right now */
userenderdata[blkid] = userender; /* Ditto for using render data */
}
}
public static HDTextureMap getMap(int blkid, int blkdata) {
return texmaps[(blkid<<4) + blkdata];
public static HDTextureMap getMap(int blkid, int blkdata, int blkrenderdata) {
if(userenderdata[blkid])
return texmaps[(blkid<<4) + blkrenderdata];
else
return texmaps[(blkid<<4) + blkdata];
}
public static BlockTransparency getTransparency(int blkid) {
@ -704,6 +713,7 @@ public class TexturePack {
line = line.substring(6);
BlockTransparency trans = BlockTransparency.OPAQUE;
String[] args = line.split(",");
boolean userenderdata = false;
for(String a : args) {
String[] av = a.split("=");
if(av.length < 2) continue;
@ -759,12 +769,15 @@ public class TexturePack {
Log.severe("Texture mapping has invalid transparency setting - " + av[1] + " - line " + rdr.getLineNumber() + " of " + txtname);
}
}
else if(av[0].equals("userenderdata")) {
userenderdata = av[1].equals("true");
}
}
/* If no data bits, assume all */
if(databits < 0) databits = 0xFFFF;
/* If we have everything, build block */
if(blkids.size() > 0) {
HDTextureMap map = new HDTextureMap(blkids, databits, faces, trans);
HDTextureMap map = new HDTextureMap(blkids, databits, faces, trans, userenderdata);
map.addToTable();
cnt++;
}
@ -795,7 +808,7 @@ public class TexturePack {
*/
public final void readColor(final HDPerspectiveState ps, final MapIterator mapiter, final Color rslt, final int blkid, final int lastblocktype, final boolean biome_shaded) {
int blkdata = ps.getBlockData();
HDTextureMap map = HDTextureMap.getMap(blkid, blkdata);
HDTextureMap map = HDTextureMap.getMap(blkid, blkdata, ps.getBlockRenderData());
BlockStep laststep = ps.getLastBlockStep();
int textid = map.faces[laststep.ordinal()]; /* Get index of texture source */
if(textid < 0) {

View File

@ -280,35 +280,35 @@ block:id=52,allfaces=65,transparency=TRANSPARENT
# Wooden stairs
block:id=53,allsides=4,topbottom=4004,transparency=SEMITRANSPARENT
# Chest - single, facing west
block:id=54,data=0,topbottom=25,south=26,north=26,east=26,west=27
block:id=54,data=0,topbottom=25,south=26,north=26,east=26,west=27,userenderdata=true
# Chest - single, facing south
block:id=54,data=1,topbottom=25,south=27,north=26,east=26,west=26
block:id=54,data=1,topbottom=25,south=27,north=26,east=26,west=26,userenderdata=true
# Chest - single, facing east
block:id=54,data=2,topbottom=25,south=26,north=26,east=27,west=26
block:id=54,data=2,topbottom=25,south=26,north=26,east=27,west=26,userenderdata=true
# Chest - single, facing north
block:id=54,data=3,topbottom=25,south=26,north=27,east=26,west=26
block:id=54,data=3,topbottom=25,south=26,north=27,east=26,west=26,userenderdata=true
# Chest - left side of double, facing west
block:id=54,data=4,topbottom=25,south=26,north=26,east=58,west=41
block:id=54,data=4,topbottom=25,south=26,north=26,east=58,west=41,userenderdata=true
# Chest - left side of double, facing south
block:id=54,data=5,topbottom=25,south=41,north=58,east=26,west=26
block:id=54,data=5,topbottom=25,south=41,north=58,east=26,west=26,userenderdata=true
# Chest - left side of double, facing east
block:id=54,data=6,topbottom=25,south=26,north=26,east=41,west=58
block:id=54,data=6,topbottom=25,south=26,north=26,east=41,west=58,userenderdata=true
# Chest - left side of double, facing north
block:id=54,data=7,topbottom=25,south=58,north=41,east=26,west=26
block:id=54,data=7,topbottom=25,south=58,north=41,east=26,west=26,userenderdata=true
# Chest - right side of double, facing west
block:id=54,data=8,topbottom=25,south=26,north=26,east=57,west=42
block:id=54,data=8,topbottom=25,south=26,north=26,east=57,west=42,userenderdata=true
# Chest - right side of double, facing south
block:id=54,data=9,topbottom=25,south=42,north=57,east=26,west=26
block:id=54,data=9,topbottom=25,south=42,north=57,east=26,west=26,userenderdata=true
# Chest - right side of double, facing east
block:id=54,data=10,topbottom=25,south=26,north=26,east=42,west=57
block:id=54,data=10,topbottom=25,south=26,north=26,east=42,west=57,userenderdata=true
# Chest - right side of double, facing north
block:id=54,data=11,topbottom=25,south=57,north=42,east=26,west=26
block:id=54,data=11,topbottom=25,south=57,north=42,east=26,west=26,userenderdata=true
# Redstone wire (all but NS and EW)
block:id=55,data=0,data=3,data=4,data=5,data=6,data=7,data=8,data=9,data=10,allfaces=180,transparency=TRANSPARENT
block:id=55,data=0,data=3,data=4,data=5,data=6,data=7,data=8,data=9,data=10,allfaces=180,transparency=TRANSPARENT,userenderdata=true
# Redstone wire (EW)
block:id=55,data=2,allfaces=181,transparency=TRANSPARENT
block:id=55,data=2,allfaces=181,transparency=TRANSPARENT,userenderdata=true
# Redstone wire (NS)
block:id=55,data=1,allfaces=4181,transparency=TRANSPARENT
block:id=55,data=1,allfaces=4181,transparency=TRANSPARENT,userenderdata=true
# Diamond ore
block:id=56,allfaces=50
# Diamond block