fix InFaceUV errors

This commit is contained in:
Lukas 2020-12-08 15:57:58 +01:00
parent 76acaa5192
commit 8c47dedf3b
8 changed files with 63 additions and 38 deletions

View File

@ -59,10 +59,10 @@ public class ModIdentifier {
}
public boolean identifierEquals(ModIdentifier their) {
if (super.equals(their)) {
if (this == their) {
return true;
}
if (hashCode() != their.hashCode()) {
if (identifier.hashCode() != their.getIdentifier().hashCode()) {
return false;
}
return getIdentifier().equals(their.getIdentifier()) && getMod().equals(their.getMod());

View File

@ -34,7 +34,7 @@ public final class LegacyBlockTransform {
Block blockAbove = chunk.getBlock(block.getKey().getChunkLocation(section.getKey()).add(0, 1, 0));
Block newBlock = null;
if (block.getValue().equals(GRASS_BLOCK)) {
if (blockAbove == null || (!blockAbove.identifierEquals(SNOW_BLOCK) & !blockAbove.identifierEquals(SNOW_LAYER_BLOCK))) {
if (blockAbove == null || (!blockAbove.identifierEquals(SNOW_BLOCK) && !blockAbove.identifierEquals(SNOW_LAYER_BLOCK))) {
newBlock = GRASS_BLOCK_NOT_SNOWY;
} else {
newBlock = GRASS_BLOCK_SNOWY;

View File

@ -48,10 +48,13 @@ public class SubBlock {
JsonObject faces = json.getAsJsonObject("faces");
for (FaceOrientation orientation : FaceOrientation.values()) {
if (faces.has(orientation.name().toLowerCase())) {
putTexture(faces.getAsJsonObject(orientation.name().toLowerCase()), orientation, variables);
putTexture(faces.getAsJsonObject(orientation.name().toLowerCase()), orientation, variables, from, to);
}
}
full = createFull();
if (textures.containsValue("block/cake_side")) {
int unused = 0;
}
}
public SubBlock(SubBlock subBlock) {
@ -94,14 +97,14 @@ public class SubBlock {
uv.get(entry.getKey()).prepare(texture, loader);
}
// clean up
textures.clear();
// textures.clear();
}
private void putTexture(JsonObject faceJson, FaceOrientation orientation, HashMap<String, String> variables) {
private void putTexture(JsonObject faceJson, FaceOrientation orientation, HashMap<String, String> variables, SubBlockPosition from, SubBlockPosition to) {
if (faceJson.has("uv")) {
uv.put(orientation, new InFaceUV(faceJson.getAsJsonArray("uv")));
uv.put(orientation, new InFaceUV(faceJson.getAsJsonArray("uv"), from, to, orientation));
} else {
uv.put(orientation, new InFaceUV());
uv.put(orientation, new InFaceUV(from, to, orientation));
}
if (faceJson.has("rotation")) {
int rotation = (360 - faceJson.get("rotation").getAsInt()) / 90;

View File

@ -14,31 +14,52 @@
package de.bixilon.minosoft.render.texture;
import com.google.gson.JsonArray;
import de.bixilon.minosoft.render.blockModels.Face.FaceOrientation;
import de.bixilon.minosoft.render.blockModels.Face.RenderConstants;
import de.bixilon.minosoft.render.blockModels.subBlocks.SubBlockPosition;
import org.apache.commons.collections.primitives.ArrayFloatList;
public class InFaceUV {
public final int u1, v1, u2, v2;
private final int u1;
private final int v1;
private final int u2;
private final int v2;
public float realU1 = -1, realV1, realU2, realV2;
private float realU1 = -1, realV1, realU2, realV2;
public InFaceUV(JsonArray json) {
u1 = json.get(0).getAsInt();
v1 = json.get(1).getAsInt();
u2 = json.get(2).getAsInt();
v2 = json.get(3).getAsInt();
public InFaceUV(JsonArray json, SubBlockPosition from, SubBlockPosition to, FaceOrientation orientation) {
this(from, to, orientation);
}
public InFaceUV() {
u1 = v1 = 0;
u2 = v2 = 16;
public InFaceUV(SubBlockPosition from, SubBlockPosition to, FaceOrientation orientation) {
switch (orientation) {
case EAST, WEST -> {
u1 = (int) from.getVector().getZ();
v1 = (int) (RenderConstants.TEXTURE_PACK_RESOLUTION - from.getVector().getY());
u2 = (int) to.getVector().getZ();
v2 = (int) (RenderConstants.TEXTURE_PACK_RESOLUTION - to.getVector().getY());
}
case UP, DOWN -> {
u1 = (int) from.getVector().getX();
v1 = (int) (RenderConstants.TEXTURE_PACK_RESOLUTION - from.getVector().getZ());
u2 = (int) to.getVector().getX();
v2 = (int) (RenderConstants.TEXTURE_PACK_RESOLUTION - to.getVector().getZ());
}
case SOUTH, NORTH -> {
u1 = (int) from.getVector().getX();
v1 = (int) (RenderConstants.TEXTURE_PACK_RESOLUTION - from.getVector().getY());
u2 = (int) to.getVector().getX();
v2 = (int) (RenderConstants.TEXTURE_PACK_RESOLUTION - to.getVector().getY());
}
default -> throw new RuntimeException();
}
}
public void prepare(float texture, TextureLoader textureLoader) {
realU1 = texture + u1 * textureLoader.getStep() / RenderConstants.TEXTURE_PACK_RESOLUTION;
realU2 = texture + u2 * textureLoader.getStep() / RenderConstants.TEXTURE_PACK_RESOLUTION;
realV1 = (float) v1 / RenderConstants.TEXTURE_PACK_RESOLUTION;
realV2 = (float) v2 / RenderConstants.TEXTURE_PACK_RESOLUTION;
realU1 = texture + textureLoader.getStep() * u1 / RenderConstants.TEXTURE_PACK_RESOLUTION;
realU2 = texture + textureLoader.getStep() * u2 / RenderConstants.TEXTURE_PACK_RESOLUTION;
realV1 = (float) v2 / RenderConstants.TEXTURE_PACK_RESOLUTION;
realV2 = (float) v1 / RenderConstants.TEXTURE_PACK_RESOLUTION;
}
public ArrayFloatList getFloats(int i) {

View File

@ -108,4 +108,16 @@ public class Vec3 {
public void zero() {
x = y = z = 0f;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,17 +1,6 @@
{
"block/grass_block_top": [
0,
1,
0
],
"block/grass": [
0,
1,
0
],
"block/water_still": [
0,
0,
1
]
"block/grass_block_top": [0, 1, 0],
"blocks/grass_top": [0, 1, 0],
"block/grass": [0, 1, 0],
"block/water_still": [0, 0, 1]
}