Skip to content

Commit 62c83b4

Browse files
committed
LightEngine impl for FakeLevel, fix porting (#95)
1 parent 2b3651b commit 62c83b4

File tree

7 files changed

+333
-20
lines changed

7 files changed

+333
-20
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.ldtteam.blockui.util.color;
2+
3+
import com.mojang.blaze3d.vertex.VertexConsumer;
4+
import com.mojang.blaze3d.vertex.VertexFormatElement;
5+
6+
/**
7+
* Wrapper for having default color for vertex consumer
8+
*/
9+
public class ColouredVertexConsumer implements VertexConsumer
10+
{
11+
protected final VertexConsumer parent;
12+
public IColour defaultColor = null;
13+
14+
public ColouredVertexConsumer(final VertexConsumer parent)
15+
{
16+
this.parent = parent;
17+
}
18+
19+
@Override
20+
public ColouredVertexConsumer addVertex(final float x, final float y, final float z)
21+
{
22+
parent.addVertex(x, y, z);
23+
return this;
24+
}
25+
26+
@Override
27+
public ColouredVertexConsumer setColor(final int r, final int g, final int b, final int a)
28+
{
29+
parent.setColor(r, g, b, a);
30+
return this;
31+
}
32+
33+
/**
34+
* Applies previously set defaultColor, will shamelessly NPE if you forgot to set it
35+
*/
36+
public ColouredVertexConsumer setDefaultColor()
37+
{
38+
defaultColor.writeIntoBuffer(this);
39+
return this;
40+
}
41+
42+
@Override
43+
public ColouredVertexConsumer setUv(final float u, final float v)
44+
{
45+
parent.setUv(u, v);
46+
return this;
47+
}
48+
49+
@Override
50+
public ColouredVertexConsumer setUv1(final int u, final int v)
51+
{
52+
parent.setUv1(u, v);
53+
return this;
54+
}
55+
56+
@Override
57+
public ColouredVertexConsumer setUv2(final int u, final int v)
58+
{
59+
parent.setUv2(u, v);
60+
return this;
61+
}
62+
63+
@Override
64+
public ColouredVertexConsumer setNormal(final float x, final float y, final float z)
65+
{
66+
parent.setNormal(x, y, z);
67+
return this;
68+
}
69+
70+
@Override
71+
public ColouredVertexConsumer misc(final VertexFormatElement element, final int... values)
72+
{
73+
parent.misc(element, values);
74+
return this;
75+
}
76+
}

src/main/java/com/ldtteam/blockui/util/color/IColour.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.ldtteam.blockui.util.color;
22

3-
import com.mojang.blaze3d.vertex.BufferBuilder;
3+
import com.mojang.blaze3d.vertex.VertexConsumer;
44

55
public interface IColour
66
{
@@ -67,9 +67,9 @@ default ColourARGB asARGB()
6767
}
6868

6969
/**
70-
* @see BufferBuilder#setColor(int, int, int, int)
70+
* @see VertexConsumer#setColor(int, int, int, int)
7171
*/
72-
default void writeIntoBuffer(final BufferBuilder buffer)
72+
default void writeIntoBuffer(final VertexConsumer buffer)
7373
{
7474
buffer.setColor(red(), green(), blue(), alpha());
7575
}

src/main/java/com/ldtteam/common/config/AbstractConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public abstract class AbstractConfiguration
2626
{
27-
public static final String DEFAULT_KEY_PREFIX = "structurize.config.default.";
27+
public static final String DEFAULT_KEY_PREFIX = "blockui.config.default.";
2828
public static final String COMMENT_SUFFIX = ".comment";
2929

3030
final List<ConfigWatcher<?>> watchers = new ArrayList<>();

src/main/java/com/ldtteam/common/config/Configurations.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.neoforged.fml.config.ModConfig.Type;
99
import net.neoforged.fml.event.config.ModConfigEvent;
1010
import net.neoforged.fml.loading.FMLEnvironment;
11+
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
12+
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
1113
import net.neoforged.neoforge.common.ModConfigSpec;
1214
import net.neoforged.neoforge.common.ModConfigSpec.Builder;
1315
import net.neoforged.neoforge.common.ModConfigSpec.ConfigValue;
@@ -75,6 +77,7 @@ public Configurations(final ModContainer modContainer,
7577
// register events for watchers
7678
modBus.addListener(ModConfigEvent.Loading.class, event -> onConfigLoad(event.getConfig()));
7779
modBus.addListener(ModConfigEvent.Reloading.class, event -> onConfigReload(event.getConfig()));
80+
modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
7881
}
7982

8083
private <T extends AbstractConfiguration> Pair<T, ModConfig> createConfig(final Function<Builder, T> factory,

src/main/java/com/ldtteam/common/fakelevel/FakeLevel.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class FakeLevel<SOURCE extends IFakeLevelBlockGetter> extends Level
9797
protected final boolean overrideBeLevel;
9898

9999
protected final FakeChunkSource chunkSource;
100+
protected final FakeLevelLightEngine lightEngine;
100101
protected final ModelDataManager modelDataManager;
101102
protected FakeLevelEntityGetterAdapter levelEntityGetter = FakeLevelEntityGetterAdapter.EMPTY;
102103
// TODO: this is currently manually filled by class user - ideally if not filled yet this should get constructed from levelSource
@@ -134,6 +135,7 @@ public FakeLevel(final SOURCE levelSource,
134135
this.overrideBeLevel = overrideBeLevel;
135136
this.chunkSource = new FakeChunkSource(this);
136137
this.modelDataManager = new ModelDataManager(this);
138+
this.lightEngine = new FakeLevelLightEngine(this);
137139

138140
setRealLevel(realLevel); // intentionally due to init
139141
}
@@ -426,6 +428,12 @@ public ModelDataManager getModelDataManager()
426428
return modelDataManager;
427429
}
428430

431+
@Override
432+
public LevelLightEngine getLightEngine()
433+
{
434+
return lightEngine;
435+
}
436+
429437
@Override
430438
public String gatherChunkSourceStats()
431439
{
@@ -502,14 +510,6 @@ public float getDayTimePerTick()
502510
// ======= NOOP UNSAFE NULL METHODS =======
503511
// ========================================
504512

505-
@Override
506-
public LevelLightEngine getLightEngine()
507-
{
508-
// TODO: noop
509-
throw new UnsupportedOperationException(
510-
"Structurize fake level - if you really need light engine please make issue on our GitHub");
511-
}
512-
513513
@Override
514514
public Explosion explode(@Nullable Entity p_311934_,
515515
@Nullable DamageSource p_312790_,

0 commit comments

Comments
 (0)