Multi material fix
This commit is contained in:
parent
d350425049
commit
a6acb67428
2 changed files with 20 additions and 14 deletions
|
@ -102,7 +102,9 @@ public class ModelsHelper {
|
||||||
private MultiPartBuilder() {}
|
private MultiPartBuilder() {}
|
||||||
|
|
||||||
public ModelPart part(ResourceLocation modelId) {
|
public ModelPart part(ResourceLocation modelId) {
|
||||||
return new ModelPart(modelId);
|
ModelPart part = new ModelPart(modelId);
|
||||||
|
modelParts.add(part);
|
||||||
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiPart build() {
|
public MultiPart build() {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.packs.resources.Resource;
|
import net.minecraft.server.packs.resources.Resource;
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.util.BlocksHelper;
|
import ru.bclib.util.BlocksHelper;
|
||||||
|
@ -62,14 +61,19 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
quadsUnbakedMap.put(dir, Lists.newArrayList());
|
quadsUnbakedMap.put(dir, Lists.newArrayList());
|
||||||
quadsBakedMap.put(dir, Lists.newArrayList());
|
quadsBakedMap.put(dir, Lists.newArrayList());
|
||||||
}
|
}
|
||||||
|
|
||||||
transforms = ItemTransforms.NO_TRANSFORMS;
|
transforms = ItemTransforms.NO_TRANSFORMS;
|
||||||
overrides = ItemOverrides.EMPTY;
|
overrides = ItemOverrides.EMPTY;
|
||||||
materials = new ArrayList<>(textureIDs.length + 1);
|
materials = new ArrayList<>(textureIDs.length);
|
||||||
sprites = new TextureAtlasSprite[textureIDs.length + 1];
|
sprites = new TextureAtlasSprite[textureIDs.length];
|
||||||
this.particleIndex = particleIndex;
|
this.particleIndex = particleIndex;
|
||||||
this.useCulling = useCulling;
|
this.useCulling = useCulling;
|
||||||
this.useShading = useShading;
|
this.useShading = useShading;
|
||||||
loadModel(location, textureIDs, offset);
|
loadModel(location, offset, (byte) (textureIDs.length - 1));
|
||||||
|
|
||||||
|
for (int i = 0; i < textureIDs.length; i++) {
|
||||||
|
materials.add(new Material(TextureAtlas.LOCATION_BLOCKS, textureIDs[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnbakedModel //
|
// UnbakedModel //
|
||||||
|
@ -163,7 +167,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs, Vector3f offset) {
|
private void loadModel(ResourceLocation location, Vector3f offset, byte maxIndex) {
|
||||||
Resource resource = getResource(location);
|
Resource resource = getResource(location);
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -176,8 +180,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
List<Integer> vertexIndex = new ArrayList<>(4);
|
List<Integer> vertexIndex = new ArrayList<>(4);
|
||||||
List<Integer> uvIndex = new ArrayList<>(4);
|
List<Integer> uvIndex = new ArrayList<>(4);
|
||||||
|
|
||||||
byte materialIndex = 0;
|
byte materialIndex = -1;
|
||||||
int vertCount = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStreamReader streamReader = new InputStreamReader(input);
|
InputStreamReader streamReader = new InputStreamReader(input);
|
||||||
|
@ -185,9 +188,11 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
String string;
|
String string;
|
||||||
|
|
||||||
while ((string = reader.readLine()) != null) {
|
while ((string = reader.readLine()) != null) {
|
||||||
if ((string.startsWith("usemtl") || string.startsWith("g")) && vertCount != vertecies.size()) {
|
if (string.startsWith("usemtl")) {
|
||||||
vertCount = vertecies.size();
|
|
||||||
materialIndex++;
|
materialIndex++;
|
||||||
|
if (materialIndex > maxIndex) {
|
||||||
|
materialIndex = maxIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (string.startsWith("vt")) {
|
else if (string.startsWith("vt")) {
|
||||||
String[] uv = string.split(" ");
|
String[] uv = string.split(" ");
|
||||||
|
@ -266,10 +271,9 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxID = textureIDs.length - 1;
|
if (materialIndex < 0) {
|
||||||
for (int i = 0; i <= materialIndex; i++) {
|
quadsUnbaked.forEach(quad -> quad.setSpriteIndex(0));
|
||||||
int index = Math.min(materialIndex, maxID);
|
quadsUnbakedMap.values().forEach(list -> list.forEach(quad -> quad.setSpriteIndex(0)));
|
||||||
materials.add(new Material(TextureAtlas.LOCATION_BLOCKS, textureIDs[index]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue