Fix cake ; handle defaulted UV values the odd ways MC seems to

This commit is contained in:
Mike Primm 2022-01-30 12:34:26 -06:00
parent e284f9a3c4
commit 3823767c77
3 changed files with 34 additions and 25 deletions

View File

@ -333,16 +333,13 @@ public class PatchDefinition implements RenderPatch {
Vector3D upleft;
Vector3D upright;
// Default UV, if not defined
double[] patchuv;
double[] patchuv = null;
boolean flipU = false, flipV = false;
if (uv != null) { // MC V is top down, so flip
patchuv = new double[] { uv[0] / 16.0, 1 - uv[3] / 16.0, uv[2] / 16.0, 1 - uv[1] / 16.0 };
if (patchuv[0] > patchuv[2]) { flipU = true; double save = patchuv[0]; patchuv[0] = patchuv[2]; patchuv[2] = save; }
if (patchuv[1] > patchuv[3]) { flipV = true; double save = patchuv[1]; patchuv[1] = patchuv[3]; patchuv[3] = save; }
}
else {
patchuv = new double[] { 0, 0, 1, 1 };
}
switch (face) {
case BOTTOM:
case FACE_0:
@ -352,6 +349,9 @@ public class PatchDefinition implements RenderPatch {
lowright = new Vector3D(to[0] / 16.0, from[1] / 16.0, from[2] / 16.0);
upleft = new Vector3D(from[0] / 16.0, from[1] / 16.0, to[2] / 16.0);
upright = new Vector3D(to[0] / 16.0, from[1] / 16.0, to[2] / 16.0);
if (patchuv == null) {
patchuv = new double[] { from[0] / 16.0, from[2] / 16.0, to[0] / 16.0, to[2] / 16.0 };
}
break;
case TOP:
case FACE_1:
@ -361,6 +361,9 @@ public class PatchDefinition implements RenderPatch {
lowright = new Vector3D(to[0] / 16.0, to[1] / 16.0, to[2] / 16.0);
upleft = new Vector3D(from[0] / 16.0, to[1] / 16.0, from[2] / 16.0);
upright = new Vector3D(to[0] / 16.0, to[1] / 16.0, from[2] / 16.0);
if (patchuv == null) {
patchuv = new double[] { from[0] / 16.0, 1 - to[2] / 16.0, to[0] / 16.0, 1 - from[2] / 16.0 };
}
break;
case NORTH:
case FACE_2:
@ -370,6 +373,9 @@ public class PatchDefinition implements RenderPatch {
lowright = new Vector3D(from[0] / 16.0, from[1] / 16.0, from[2] / 16.0);
upleft = new Vector3D(to[0] / 16.0, to[1] / 16.0, from[2] / 16.0);
upright = new Vector3D(from[0] / 16.0, to[1] / 16.0, from[2] / 16.0);
if (patchuv == null) {
patchuv = new double[] { 1 - to[0] / 16.0, from[1] / 16.0, 1 - from[0] / 16.0, to[1] / 16.0 };
}
break;
case SOUTH:
case FACE_3:
@ -379,6 +385,9 @@ public class PatchDefinition implements RenderPatch {
lowright = new Vector3D(to[0] / 16.0, from[1] / 16.0,to[2] / 16.0);
upleft = new Vector3D(from[0] / 16.0, to[1] / 16.0, to[2] / 16.0);
upright = new Vector3D(to[0] / 16.0, to[1] / 16.0, to[2] / 16.0);
if (patchuv == null) {
patchuv = new double[] { from[0] / 16.0, from[1] / 16.0, to[0] / 16.0, to[1] / 16.0 };
}
break;
case WEST:
case FACE_4:
@ -388,6 +397,9 @@ public class PatchDefinition implements RenderPatch {
lowright = new Vector3D(from[0] / 16.0, from[1] / 16.0, to[2] / 16.0);
upleft = new Vector3D(from[0] / 16.0, to[1] / 16.0, from[2] / 16.0);
upright = new Vector3D(from[0] / 16.0, to[1] / 16.0, to[2] / 16.0);
if (patchuv == null) {
patchuv = new double[] { from[2] / 16.0, from[1] / 16.0, to[2] / 16.0, to[1] / 16.0 };
}
break;
case EAST:
case FACE_5:
@ -397,11 +409,19 @@ public class PatchDefinition implements RenderPatch {
lowright = new Vector3D(to[0] / 16.0, from[1] / 16.0, from[2] / 16.0);
upleft = new Vector3D(to[0] / 16.0, to[1] / 16.0, to[2] / 16.0);
upright = new Vector3D(to[0] / 16.0, to[1] / 16.0, from[2] / 16.0);
if (patchuv == null) {
patchuv = new double[] { 1 - to[2] / 16.0, from[1] / 16.0, 1 - from[2] / 16.0, to[1] / 16.0 };
}
break;
default:
Log.severe("Invalid side: " + face);
return;
}
}
// Clamp patchuv to avoid extending off of patch, while maintaining width and height of patch area
if (patchuv[0] < 0) { patchuv[2] -= patchuv[0]; patchuv[0] = 0.0; }
if (patchuv[1] < 0) { patchuv[3] -= patchuv[1]; patchuv[1] = 0.0; }
if (patchuv[2] > 1) { patchuv[0] -= (patchuv[2] - 1); patchuv[2] = 1; }
if (patchuv[3] > 1) { patchuv[1] -= (patchuv[3] - 1); patchuv[3] = 1; }
// If rotation, rotate face corners
if (rot == ModelBlockModel.SideRotation.DEG270) {
// 270 degrees CCW - origin is now upper left (V), V is now upper right (U+V-O), U is lower left (O)

View File

@ -902,25 +902,14 @@ layer:3,4
# Trap Chest - single or double
customblock:id=chest,id=trapped_chest,class=org.dynmap.hdmap.renderer.ChestStateRenderer,doublechest=true
# Cake Block
block:id=cake,scale=16
layer:0,1,2,3,4,5,6,7
----------------
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
-**************-
----------------
# Cake Block (cake_bottom, cake_top, cake_side, cake_inside)
modellist:id=cake,data=0,box=1/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/2
modellist:id=cake,data=1,box=3/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/3
modellist:id=cake,data=2,box=5/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/3
modellist:id=cake,data=3,box=7/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/3
modellist:id=cake,data=4,box=9/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/3
modellist:id=cake,data=5,box=11/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/3
modellist:id=cake,data=6,box=13/0/1:15/8/15:d/0:u/1:n/2:s/2:e/2:w/3
# Tripwire Hook
patch:id=HookBoxSide1,Ox=0.0,Oy=0.0,Oz=0.375,Ux=1.0,Uy=0.0,Uz=0.375,Vx=0.0,Vy=1.0,Vz=0.375,Umin=0.875,Umax=1.0,Vmin=0.0625,Vmax=0.5625,visibility=bottom
patch:id=HookBoxSide2,Ox=0.0,Oy=0.0,Oz=0.625,Ux=1.0,Uy=0.0,Uz=0.625,Vx=0.0,Vy=1.0,Vz=0.625,Umin=0.875,Umax=1.0,Vmin=0.0625,Vmax=0.5625,visibility=top

View File

@ -1034,7 +1034,7 @@ block:id=jack_o_lantern,data=2,face4=0:jack_o_lantern,face2=0:pumpkin_side,face3
# Jack-O-Lantern (east)
block:id=jack_o_lantern,data=3,face5=0:jack_o_lantern,face2=0:pumpkin_side,face3=0:pumpkin_side,face4=0:pumpkin_side,topbottom=6000:pumpkin_top,stdrot=true
# Cake Block
block:id=cake,allsides=0:cake_side,top=0:cake_top,bottom=0:cake_bottom,stdrot=true,transparency=TRANSPARENT
block:id=cake,patch0=0:cake_bottom,patch1=0:cake_top,patch2=0:cake_side,patch3=0:cake_inner,transparency=TRANSPARENT
# Repeater
block:id=repeater,data=*,patch0=0:smooth_stone,patch1=0:repeater,patch2=0:redstone_torch_off,patch3=0:redstone_torch,patch4=0:bedrock,patch5=0:repeater_on,transparency=TRANSPARENT
# Stained Glass (95)