diff --git a/src/main/java/ru/bclib/client/models/OBJBlockModel.java b/src/main/java/ru/bclib/client/models/OBJBlockModel.java index f636ff65..ea090342 100644 --- a/src/main/java/ru/bclib/client/models/OBJBlockModel.java +++ b/src/main/java/ru/bclib/client/models/OBJBlockModel.java @@ -57,7 +57,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel { protected boolean useShading; protected byte particleIndex; - public OBJBlockModel(ResourceLocation location, boolean useCulling, boolean useShading, byte particleIndex, ResourceLocation... textureIDs) { + public OBJBlockModel(ResourceLocation location, Vector3f offset, boolean useCulling, boolean useShading, byte particleIndex, ResourceLocation... textureIDs) { for (Direction dir: BlocksHelper.DIRECTIONS) { quadsUnbakedMap.put(dir, Lists.newArrayList()); quadsBakedMap.put(dir, Lists.newArrayList()); @@ -69,7 +69,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel { this.particleIndex = particleIndex; this.useCulling = useCulling; this.useShading = useShading; - loadModel(location, textureIDs); + loadModel(location, textureIDs, offset); } // UnbakedModel // @@ -163,7 +163,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel { return resource; } - private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs) { + private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs, Vector3f offset) { Resource resource = getResource(location); if (resource == null) { return; @@ -227,9 +227,9 @@ public class OBJBlockModel implements UnbakedModel, BakedModel { for (int i = 0; i < 4; i++) { int index = vertexIndex.get(i) * 3; int quadIndex = i * 5; - quad.addData(quadIndex++, vertecies.get(index++)); // X - quad.addData(quadIndex++, vertecies.get(index++)); // Y - quad.addData(quadIndex++, vertecies.get(index)); // Z + quad.addData(quadIndex++, vertecies.get(index++) + offset.x()); // X + quad.addData(quadIndex++, vertecies.get(index++) + offset.y()); // Y + quad.addData(quadIndex++, vertecies.get(index) + offset.z()); // Z if (hasUV) { index = uvIndex.get(i) * 2; quad.addData(quadIndex++, uvs.get(index++) * 16F); // U diff --git a/src/main/java/ru/bclib/client/models/OBJModelBuilder.java b/src/main/java/ru/bclib/client/models/OBJModelBuilder.java index 99b7c8de..56dbcbd0 100644 --- a/src/main/java/ru/bclib/client/models/OBJModelBuilder.java +++ b/src/main/java/ru/bclib/client/models/OBJModelBuilder.java @@ -1,6 +1,7 @@ package ru.bclib.client.models; import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.resources.ResourceLocation; @@ -15,6 +16,7 @@ public class OBJModelBuilder { private ResourceLocation particles; private boolean useCulling; private boolean useShading; + private Vector3f offset; private OBJModelBuilder() {} @@ -24,6 +26,7 @@ public class OBJModelBuilder { */ public static OBJModelBuilder start(ResourceLocation modelLocation) { INSTANCE.modelLocation = modelLocation; + INSTANCE.offset.set(0, 0, 0); INSTANCE.useCulling = true; INSTANCE.useShading = true; INSTANCE.particles = null; @@ -76,6 +79,11 @@ public class OBJModelBuilder { return this; } + public OBJModelBuilder setOffset(float x, float y, float z) { + this.offset.set(x, y, z); + return this; + } + /** * Builds model from all required data. * @return {@link OBJBlockModel}. @@ -90,6 +98,6 @@ public class OBJModelBuilder { } } ResourceLocation[] sprites = textures.toArray(new ResourceLocation[textures.size()]); - return new OBJBlockModel(modelLocation, useCulling, useShading, particleIndex, sprites); + return new OBJBlockModel(modelLocation, offset, useCulling, useShading, particleIndex, sprites); } }