Skip to content

Commit b7c9372

Browse files
committed
Fixed Z-fighting issues.
1 parent 4b56e90 commit b7c9372

18 files changed

+1981
-277
lines changed

multipart/src/main/java/sunsetsatellite/catalyst/multipart/api/MultipartType.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ public class MultipartType {
1414
public final String model;
1515
public final String name;
1616
public final int thickness;
17+
public final int cubesPerSide;
1718

18-
public MultipartType(String name, String model, int thickness) {
19+
public MultipartType(String name, String model, int thickness, int cubesPerSide) {
1920
this.model = model;
2021
this.name = name;
2122
this.thickness = thickness;
23+
this.cubesPerSide = cubesPerSide;
2224
types.put(name, this);
2325
}
2426

25-
public static final MultipartType FOIL = new MultipartType("foil", "foil", 1);
26-
public static final MultipartType COVER = new MultipartType("cover", "cover", 2);
27-
public static final MultipartType PANEL = new MultipartType("panel", "panel", 4);
28-
public static final MultipartType SLAB = new MultipartType("slab", "slab", 8);
29-
public static final MultipartType ANTI_FOIL = new MultipartType("antifoil", "antifoil", 15);
30-
public static final MultipartType ANTI_COVER = new MultipartType("anticover", "anticover", 14);
31-
public static final MultipartType ANTI_PANEL = new MultipartType("antipanel", "antipanel", 12);
32-
public static final MultipartType HOLLOW_FOIL = new MultipartType("hollow_foil", "hollow_foil",1);
33-
public static final MultipartType HOLLOW_COVER = new MultipartType("hollow_cover", "hollow_cover",2);
34-
public static final MultipartType HOLLOW_PANEL = new MultipartType("hollow_panel", "hollow_panel",4);
35-
public static final MultipartType HOLLOW_SLAB = new MultipartType("hollow_slab", "hollow_slab",8);
36-
public static final MultipartType PILLAR = new MultipartType("pillar", "pillar",16);
27+
public static final MultipartType FOIL = new MultipartType("foil", "foil", 1, 1);
28+
public static final MultipartType COVER = new MultipartType("cover", "cover", 2, 1);
29+
public static final MultipartType PANEL = new MultipartType("panel", "panel", 4, 1);
30+
public static final MultipartType SLAB = new MultipartType("slab", "slab", 8, 1);
31+
/*public static final MultipartType ANTI_FOIL = new MultipartType("antifoil", "antifoil", 15, 1);
32+
public static final MultipartType ANTI_COVER = new MultipartType("anticover", "anticover", 14, 1);
33+
public static final MultipartType ANTI_PANEL = new MultipartType("antipanel", "antipanel", 12, 1);*/
34+
public static final MultipartType HOLLOW_FOIL = new MultipartType("hollow_foil", "hollow_foil",1, 4);
35+
public static final MultipartType HOLLOW_COVER = new MultipartType("hollow_cover", "hollow_cover",2, 4);
36+
public static final MultipartType HOLLOW_PANEL = new MultipartType("hollow_panel", "hollow_panel",4, 4);
37+
public static final MultipartType HOLLOW_SLAB = new MultipartType("hollow_slab", "hollow_slab",8, 4);
38+
//public static final MultipartType PILLAR = new MultipartType("pillar", "pillar",16, 1);
3739

3840
public static ModernBlockModel getOrCreateBlockModel(String modId, Multipart multipart) {
3941
NamespaceId namespaceId = new NamespaceId(modId, multipart.type.model+"_"+multipart.block.getKey().replace("tile","").replace(modId,"").replace(".","_").toLowerCase());

multipart/src/main/java/sunsetsatellite/catalyst/multipart/block/BlockMultipart.java

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public void getCollidingBoundingBoxes(World world, int x, int y, int z, AABB aab
8383
if (((ISupportsMultiparts) tile).getParts().values().stream().allMatch(Objects::isNull)) {
8484
super.getCollidingBoundingBoxes(world, x, y, z, aabb, aabbList);
8585
} else {
86-
8786
((ISupportsMultiparts) tile).getParts().forEach((dir,multipart)->{
8887
if(multipart == null) return;
8988
double d = Catalyst.map(multipart.type.thickness,1,16,0,1);

multipart/src/main/java/sunsetsatellite/catalyst/multipart/block/entity/TileEntityMultipart.java

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public TileEntityMultipart() {
1919

2020
}
2121

22+
@Override
23+
public void tick() {
24+
super.tick();
25+
worldObj.markBlockDirty(x,y,z);
26+
}
27+
2228
@Override
2329
public void writeToNBT(CompoundTag tag) {
2430
super.writeToNBT(tag);

multipart/src/main/java/sunsetsatellite/catalyst/multipart/block/model/BlockModelMultipart.java

+17-29
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sunsetsatellite.catalyst.CatalystMultipart;
1919
import sunsetsatellite.catalyst.multipart.api.ISupportsMultiparts;
2020
import sunsetsatellite.catalyst.multipart.api.MultipartType;
21+
import sunsetsatellite.catalyst.multipart.util.MultipartModelRenderer;
2122

2223
import java.util.ArrayList;
2324

@@ -35,7 +36,15 @@ public boolean render(Tessellator tessellator, int x, int y, int z) {
3536
InternalModel[] models = getModelsFromState(block, x, y, z, false);
3637
boolean didRender = false;
3738
for (InternalModel model : models) {
38-
didRender |= BlockModelRenderer.renderModelNormal(tessellator, model.model, block, x, y, z, model.rotationX, -model.rotationY);
39+
//X = 90 -> DOWN | Y NEG
40+
//X = -90 -> UP | Y POS
41+
//Y = 0 || 360 -> NORTH | Z NEG
42+
//Y = 90 -> EAST | X POS
43+
//Y = 180 -> SOUTH | Z POS
44+
//Y = 270 -> WEST | X NEG
45+
if(model instanceof MultipartInternalModel){
46+
didRender |= MultipartModelRenderer.renderModelNormal(tessellator, model.model, block, x, y, z, ((MultipartInternalModel) model).side, ((MultipartInternalModel) model).part);
47+
}
3948
}
4049
return didRender;
4150
}
@@ -58,34 +67,13 @@ public InternalModel[] getModelsFromState(Block block, int x, int y, int z, bool
5867
if(tile instanceof ISupportsMultiparts){
5968
((ISupportsMultiparts) tile).getParts().forEach((dir,multipart)->{
6069
if(multipart == null) return;
61-
//X = 90 -> DOWN
62-
//X = -90 -> UP
63-
//Y = 0 || 360 -> NORTH
64-
//Y = 90 -> EAST
65-
//Y = 180 -> SOUTH
66-
//Y = 270 -> WEST
67-
int rotX = 0;
68-
int rotY = 0;
69-
switch (dir) {
70-
case X_POS:
71-
rotY = 90;
72-
break;
73-
case X_NEG:
74-
rotY = 270;
75-
break;
76-
case Y_POS:
77-
rotX = -90;
78-
break;
79-
case Y_NEG:
80-
rotX = 90;
81-
break;
82-
case Z_POS:
83-
rotY = 180;
84-
break;
85-
case Z_NEG:
86-
break;
87-
}
88-
InternalModel internalModel = new InternalModel(MultipartType.getOrCreateBlockModel(CatalystMultipart.MOD_ID, multipart), rotX, rotY);
70+
//X = 90 -> DOWN | Y NEG
71+
//X = -90 -> UP | Y POS
72+
//Y = 0 || 360 -> NORTH | Z NEG
73+
//Y = 90 -> EAST | X POS
74+
//Y = 180 -> SOUTH | Z POS
75+
//Y = 270 -> WEST | X NEG
76+
MultipartInternalModel internalModel = new MultipartInternalModel(MultipartType.getOrCreateBlockModel(CatalystMultipart.MOD_ID, multipart), dir.getSide(), multipart);
8977
internalModel.model.refreshModel();
9078
models.add(internalModel);
9179
});

multipart/src/main/java/sunsetsatellite/catalyst/multipart/block/model/BlockModelMultipartItem.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,23 @@ public void renderBlockOnInventory(Tessellator tessellator, int metadata, float
155155
if (model.model.blockCubes != null){
156156
tessellator.startDrawingQuads();
157157
GL11.glColor4f(brightness, brightness, brightness, 1);
158-
for (BlockCube cube: model.model.blockCubes) {
159-
for (BlockFace face: cube.getFaces().values()) {
158+
BlockCube[] blockCubes = model.model.blockCubes;
159+
for (int i = 0; i < blockCubes.length; i++) {
160+
BlockCube cube = blockCubes[i];
161+
if(i < 2 * multipart.type.cubesPerSide || i >= (2 * multipart.type.cubesPerSide) + multipart.type.cubesPerSide) continue;
162+
for (BlockFace face : cube.getFaces().values()) {
160163
tessellator.setNormal(face.getSide().getOffsetX(), face.getSide().getOffsetY(), face.getSide().getOffsetZ());
161-
if (LightmapHelper.isLightmapEnabled() && lightmapCoordinate != null){
164+
if (LightmapHelper.isLightmapEnabled() && lightmapCoordinate != null) {
162165
tessellator.setLightmapCoord(lightmapCoordinate);
163166
}
164167
float r = 1;
165168
float g = 1;
166169
float b = 1;
167-
if (face.useTint()){
170+
if (face.useTint()) {
168171
int color = BlockColorDispatcher.getInstance().getDispatch(block).getFallbackColor(metadata);
169-
r = (float)(color >> 16 & 0xFF) / 255.0f;
170-
g = (float)(color >> 8 & 0xFF) / 255.0f;
171-
b = (float)(color & 0xFF) / 255.0f;
172+
r = (float) (color >> 16 & 0xFF) / 255.0f;
173+
g = (float) (color >> 8 & 0xFF) / 255.0f;
174+
b = (float) (color & 0xFF) / 255.0f;
172175
}
173176
BlockModelRenderer.renderModelFaceWithColor(tessellator, face, 0, 0, 0, r * brightness, g * brightness, b * brightness);
174177
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package sunsetsatellite.catalyst.multipart.block.model;
2+
3+
import net.minecraft.core.util.helper.Side;
4+
import org.useless.dragonfly.model.block.InternalModel;
5+
import org.useless.dragonfly.model.block.processed.ModernBlockModel;
6+
import sunsetsatellite.catalyst.multipart.api.Multipart;
7+
8+
public class MultipartInternalModel extends InternalModel {
9+
10+
public final Side side;
11+
public final Multipart part;
12+
13+
public MultipartInternalModel(ModernBlockModel model, Side side, Multipart part) {
14+
super(model, 0, 0);
15+
this.side = side;
16+
this.part = part;
17+
}
18+
}

multipart/src/main/java/sunsetsatellite/catalyst/multipart/mixin/BlockModelRendererMixin.java

-76
This file was deleted.

0 commit comments

Comments
 (0)