More fixes and enhancements for modsupport API

This commit is contained in:
Mike Primm 2022-02-08 21:10:58 -06:00
parent a2f8f9defa
commit 611832fa22
5 changed files with 23 additions and 4 deletions

View File

@ -150,6 +150,8 @@ public abstract class BlockModelImpl implements BlockModel {
// If we have state data, favor this
if (this.blockstates != null) {
for (Map<String, String> rec : this.blockstates) {
// If no state, skip
if (rec.size() == 0) { continue; }
s += ",state=";
boolean first = true;
for (Entry<String, String> r : rec.entrySet()) {

View File

@ -533,6 +533,7 @@ public class BlockTextureRecordImpl implements BlockTextureRecord {
// If we have state data, favor this
if (this.blockstates != null) {
for (Map<String, String> rec : this.blockstates) {
if (rec.size() == 0) { continue; } // Skip if none
s += ",state=";
boolean first = true;
for (Entry<String, String> r : rec.entrySet()) {

View File

@ -191,6 +191,7 @@ public class CopyBlockTextureRecordImpl implements CopyBlockTextureRecord {
// If we have state data, favor this
if (this.blockstates != null) {
for (Map<String, String> rec : this.blockstates) {
if (rec.size() == 0) { continue; } // Skip if none
s += ",state=";
boolean first = true;
for (Entry<String, String> r : rec.entrySet()) {

View File

@ -22,6 +22,7 @@ public class ModelBlockModelImpl extends BlockModelImpl implements ModelBlockMod
private double[] to = { 16, 16, 16 };
private double xrot = 0, yrot = 0, zrot = 0;
private boolean shade;
private double[] rotorigin;
@Override
public void addBlockSide(BlockSide side, double[] uv, SideRotation rot, int textureid, int tintidx) {
ModelSide ms = new ModelSide();
@ -77,9 +78,10 @@ public class ModelBlockModelImpl extends BlockModelImpl implements ModelBlockMod
public String getLine() {
String ids = this.getIDsAndMeta();
if (ids == null) return null;
String line = String.format("patchblock:%s", ids);
String line;
// If rotating another model
if (rotsourceblockname != null) {
line = String.format("patchblock:%s", ids);
line += "\npatchrotate:id=" + rotsourceblockname;
if (rotsourcestatemap != null) {
line += ",state=";
@ -105,6 +107,7 @@ public class ModelBlockModelImpl extends BlockModelImpl implements ModelBlockMod
}
}
else {
line = String.format("modellist:%s", ids);
for (ModelBlockImpl mb: boxes) {
line += String.format(",box=%f/%f/%f", mb.from[0], mb.from[1], mb.from[2]);
if (!mb.shade) { // if shade=false
@ -113,6 +116,10 @@ public class ModelBlockModelImpl extends BlockModelImpl implements ModelBlockMod
line += String.format(":%f/%f/%f", mb.to[0], mb.to[1], mb.to[2]);
if ((mb.xrot != 0) || (mb.yrot != 0) || (mb.zrot != 0)) { // If needed, add rotation
line += String.format("/%f/%f/%f", mb.xrot, mb.yrot, mb.zrot);
// If origin also defined, add it
if (mb.rotorigin != null) {
line += String.format("/%f/%f/%f", mb.rotorigin[0], mb.rotorigin[1], mb.rotorigin[2]);
}
}
for (BlockSide bs : fromBlockSide.keySet()) {
String side = fromBlockSide.get(bs);
@ -160,16 +167,20 @@ public class ModelBlockModelImpl extends BlockModelImpl implements ModelBlockMod
* @param yrot - degrees of rotation of block around Y
* @param zrot - degrees of rotation of block around Z
* @param shade - shade setting for model
* @param rotorigin - rotation origin, if any (default [ 8, 8, 8 ](
* @return model block to add faces to
*/
@Override
public ModelBlock addModelBlock(double[] from, double[] to, double xrot, double yrot, double zrot,
boolean shade) {
boolean shade, double[] rotorigin) {
ModelBlockImpl mbi = new ModelBlockImpl();
if (from != null) { mbi.from[0] = from[0]; mbi.from[1] = from[1]; mbi.from[2] = from[2]; }
if (to != null) { mbi.to[0] = to[0]; mbi.to[1] = to[1]; mbi.to[2] = to[2]; }
mbi.xrot = xrot; mbi.yrot = yrot; mbi.zrot = zrot;
mbi.shade = shade;
if (rotorigin != null) {
mbi.rotorigin = Arrays.copyOf(rotorigin, 3);
}
boxes.add(mbi);
return mbi;
}

View File

@ -38,10 +38,14 @@ public interface ModelBlockModel extends BlockModel {
* @param yrot - degrees of rotation of block around Y
* @param zrot - degrees of rotation of block around Z
* @param shade - shade setting for model
* @param rotorigin = rotation origin [x, y, z] (if null, [ 8,8,8 ] is assumed
* @return model block to add faces to
*/
public ModelBlock addModelBlock(double[] from, double[] to, double xrot, double yrot, double zrot, boolean shade);
public ModelBlock addModelBlock(double[] from, double[] to, double xrot, double yrot, double zrot, boolean shade, double[] rotorigin);
default public ModelBlock addModelBlock(double[] from, double[] to, double xrot, double yrot, double zrot, boolean shade) {
return addModelBlock(from, to, xrot, yrot, zrot, shade, null);
}
default public ModelBlock addModelBlock(double[] from, double[] to, double xrot, double yrot, double zrot) {
return addModelBlock(from, to, xrot, yrot, zrot, true);
return addModelBlock(from, to, xrot, yrot, zrot, true, null);
}
}