Skip to content

Commit d6f6a80

Browse files
Merge remote-tracking branch 'origin/1.19.4-forge' into 1.20.1-forge
2 parents 6e9ff6c + b2025c3 commit d6f6a80

10 files changed

Lines changed: 77 additions & 76 deletions

File tree

src/main/java/cam72cam/mod/ModCore.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import javax.annotation.Nullable;
6868
import java.io.File;
6969
import java.io.IOException;
70-
import java.util.function.Predicate;
7170
import java.util.stream.Collectors;
7271

7372
/** UMC Mod, do not touch... */
@@ -91,20 +90,20 @@ public static void register(Mod ctr) {
9190
}
9291

9392
/** Called during Mod Construction phase */
94-
public ModCore() {
93+
public ModCore(FMLJavaModLoadingContext context) {
9594
System.out.println("Welcome to UniversalModCore!");
9695
instance = this;
9796

9897
ModCore.register(new Internal());
9998
proxy.setup();
10099

101100

102-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::preInit);
103-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::init);
104-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::postInit);
105-
//FMLJavaModLoadingContext.get().getModEventBus().addListener(this::serverStarting);
106-
//FMLJavaModLoadingContext.get().getModEventBus().addListener(this::serverStarted);
107-
CommonEvents.Item.CREATIVE_TAB.register(FMLJavaModLoadingContext.get().getModEventBus());
101+
context.getModEventBus().addListener(this::preInit);
102+
context.getModEventBus().addListener(this::init);
103+
context.getModEventBus().addListener(this::postInit);
104+
//context.getModEventBus().addListener(this::serverStarting);
105+
//context.getModEventBus().addListener(this::serverStarted);
106+
CommonEvents.Item.CREATIVE_TAB.register(context.getModEventBus());
108107

109108
MinecraftForge.EVENT_BUS.register(this);
110109
}

src/main/java/cam72cam/mod/event/ClientEvents.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ public static void onRenderMouseover(RenderHighlightEvent.Block event) {
233233
// TODO 1.15+ do we need to set lightmap coords here?
234234
RENDER_MOUSEOVER.execute(x -> x.accept(event));
235235
RenderType.cutout().clearRenderState();
236-
RenderContext.resetState();
237236
}
238237

239238
@SubscribeEvent

src/main/java/cam72cam/mod/gui/screen/IScreen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
import cam72cam.mod.input.Keyboard;
55
import cam72cam.mod.render.opengl.RenderState;
66

7+
import javax.annotation.Nullable;
8+
79
public interface IScreen {
810
/** Called when screen is initially constructed */
911
void init(IScreenBuilder screen);
1012

1113
@Deprecated
1214
default void onEnterKey(IScreenBuilder builder) { }
13-
/** Called when any key is pressed outside textfield */
14-
default void onKeyType(IScreenBuilder builder, Keyboard.KeyCode keyCode){
15+
/**
16+
* Called when any key is pressed outside textfield
17+
* @param keyCode The typed key's code, or null if not recognizable
18+
* */
19+
default void onKeyType(IScreenBuilder builder, @Nullable Keyboard.KeyCode keyCode){
1520
if (keyCode == Keyboard.KeyCode.NUMPADENTER || keyCode == Keyboard.KeyCode.RETURN) {
1621
onEnterKey(builder);
1722
}

src/main/java/cam72cam/mod/input/Keyboard.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import net.minecraftforge.client.settings.KeyConflictContext;
1111
import org.lwjgl.glfw.GLFW;
1212

13+
import javax.annotation.Nullable;
14+
1315
public class Keyboard {
16+
private static final Int2ObjectArrayMap<KeyCode> keycodes = new Int2ObjectArrayMap<>();
17+
1418
public enum KeyCode {
1519
ESCAPE(GLFW.GLFW_KEY_ESCAPE),
1620
NUM1(GLFW.GLFW_KEY_1),
@@ -128,13 +132,11 @@ public enum KeyCode {
128132
keycodes.put(code, this);
129133
}
130134

131-
public static KeyCode of(int code) {
135+
public static @Nullable KeyCode of(int code) {
132136
return keycodes.get(code);
133137
}
134138
}
135139

136-
private static final Int2ObjectArrayMap<KeyCode> keycodes = new Int2ObjectArrayMap<>();
137-
138140
/** Registers a keybind */
139141
@OnlyIn(Dist.CLIENT)
140142
public static void registerKey(String name, KeyCode keyCode, String category, Runnable handler) {

src/main/java/cam72cam/mod/mixin/feat/global_renderer/MixinRenderGlobal.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ public void injectRenderGlobal(PoseStack stack, float partialTicks, long p_22842
2929
RenderState state = new RenderState(stack).translate(-pos.x, -pos.y, -pos.z);
3030
GlobalRender.renderGlobalFuncs(state.clone(), partialTicks);
3131
RenderType.cutoutMipped().clearRenderState();
32-
RenderContext.resetState();
3332
}
3433
}

src/main/java/cam72cam/mod/render/BlockRender.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ public void render(TileEntity te, float partialTicks, PoseStack var3, MultiBuffe
116116
model.renderCustom(new RenderState(var3).lightmap(j/240f, k/240f).stage(RenderContext.Stage.BLOCK), partialTicks);
117117

118118
RenderType.cutoutMipped().clearRenderState();
119-
RenderContext.resetState();
120119
}
121120

122121
@Override

src/main/java/cam72cam/mod/render/opengl/RenderContext.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.mojang.blaze3d.systems.RenderSystem;
1212
import com.mojang.blaze3d.vertex.VertexFormatElement;
1313
import net.minecraft.client.Minecraft;
14-
import net.minecraft.client.renderer.GameRenderer;
1514
import net.minecraft.client.renderer.ShaderInstance;
1615
import org.joml.Matrix4f;
1716
import org.lwjgl.opengl.GL11;
@@ -23,6 +22,9 @@
2322
import static cam72cam.mod.render.opengl.Texture.NO_TEXTURE;
2423

2524
public class RenderContext {
25+
//Lightmap UV coordinate for full bright
26+
public static final int FULL_BRIGHT = 240;
27+
2628
//Modified from rendertype_entity_cutout, fix model normal
2729
public static ShaderInstance UMC_CORE;
2830

@@ -37,29 +39,10 @@ private RenderContext() {
3739
}
3840

3941
public static With apply(RenderState state) {
40-
return apply(state, false);
41-
}
42-
43-
/**
44-
* Internal, use the method above
45-
* <p>
46-
* In some 1.19.4+ cases we can't use beacon shader but in other cases have to, so we added an alternative here
47-
* <p>
48-
* Assuming that only OBJ-related need beacon shader for now
49-
*/
50-
public static With apply(RenderState state, boolean useBeaconShader) {
5142
RenderContext.checkError();
5243
List<Runnable> restore = new ArrayList<>();
5344

54-
ShaderInstance shader;
55-
boolean vanillaEmissive = state.lightmap != null
56-
&& state.lightmap[0] == 1 && state.lightmap[1] == 1
57-
&& !ShaderHelper.isShaderPackEnabled();
58-
if (vanillaEmissive && useBeaconShader) {
59-
shader = GameRenderer.getRendertypeBeaconBeamShader();
60-
} else {
61-
shader = RenderSystem.getShader();
62-
}
45+
ShaderInstance shader = RenderSystem.getShader();
6346
if (state.model_view != null) {
6447
Matrix4f oldModelView = new Matrix4f(RenderSystem.getModelViewMatrix());
6548
restore.add(() -> RenderSystem.getModelViewMatrix().set(oldModelView));
@@ -95,8 +78,8 @@ public static With apply(RenderState state, boolean useBeaconShader) {
9578
restore.add(() -> RenderSystem.setShaderColor(oldColor[0], oldColor[1], oldColor[2], oldColor[3]));
9679
}
9780

98-
//TODO Without Iris there may be some kinds of light bug like 1.16 era...figure out why
99-
if (state.lightmap != null && !vanillaEmissive) {
81+
if (state.lightmap != null) {
82+
//Our custom shader will handle vanilla emissive stuff
10083
float oldX;
10184
float oldY;
10285
if (state.stage == Stage.ENTITY) {
@@ -241,8 +224,9 @@ private static void setupLightMap(ShaderInstance shader, float oldX, float oldY)
241224
if (element.getUsage() == VertexFormatElement.Usage.UV) {
242225
for (Map.Entry<String, VertexFormatElement> entry : shader.getVertexFormat().getElementMapping().entrySet()) {
243226
if (entry.getValue() == element && entry.getKey().equals("UV2")) {
244-
int x = (int) (oldX * 240);
245-
int y = (int) (oldY * 240);
227+
//240 means full bright
228+
int x = (int) (oldX * RenderContext.FULL_BRIGHT);
229+
int y = (int) (oldY * RenderContext.FULL_BRIGHT);
246230
GL32.glVertexAttribI2i(i, x, y);
247231
}
248232
}
@@ -294,9 +278,4 @@ public enum Stage {
294278

295279
NONE
296280
}
297-
298-
public static void resetState() {
299-
RenderSystem.defaultBlendFunc();
300-
RenderSystem.setShaderColor(1,1,1,1);
301-
}
302281
}

src/main/java/cam72cam/mod/render/opengl/VBO.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ protected Binding(RenderState state, boolean wait) {
210210
GL32.glVertexAttribPointer(i, 3, GL32.GL_FLOAT, false, stride, (long) vbInfo.vertexOffset * Float.BYTES);
211211
}
212212
case NORMAL -> {
213-
if (vbInfo.hasNormals) {
214-
GL32.glEnableVertexAttribArray(i);
215-
GL32.glVertexAttribPointer(i, 3, GL32.GL_FLOAT, true, stride, (long) vbInfo.normalOffset * Float.BYTES);
216-
}
213+
if (!vbInfo.hasNormals) continue;
214+
GL32.glEnableVertexAttribArray(i);
215+
GL32.glVertexAttribPointer(i, 3, GL32.GL_FLOAT, true, stride, (long) vbInfo.normalOffset * Float.BYTES);
217216
}
218217
case COLOR -> {
219218
GL32.glEnableVertexAttribArray(i);
@@ -222,21 +221,26 @@ protected Binding(RenderState state, boolean wait) {
222221
case UV -> {
223222
for (Map.Entry<String, VertexFormatElement> entry : shader.getVertexFormat().getElementMapping().entrySet()) {
224223
if (entry.getValue() == element) {
225-
if (entry.getKey().equals("UV0")) {
226-
GL32.glEnableVertexAttribArray(i);
227-
GL32.glVertexAttribPointer(i, 2, GL32.GL_FLOAT, false, stride, (long) vbInfo.textureOffset * Float.BYTES);
228-
} else if (entry.getKey().equals("UV1")) {
229-
GL32.glDisableVertexAttribArray(i);
230-
GL32.glVertexAttribI2i(i, 0, 10);
231-
} else if (entry.getKey().equals("UV2")) {
232-
GL32.glDisableVertexAttribArray(i);
233-
int x = 240;
234-
int y = 240;
235-
if (state.lightmap != null) {
236-
x = (int) (state.lightmap[0] * 240);
237-
y = (int) (state.lightmap[1] * 240);
224+
switch (entry.getKey()) {
225+
case "UV0" -> {
226+
GL32.glEnableVertexAttribArray(i);
227+
GL32.glVertexAttribPointer(i, 2, GL32.GL_FLOAT, false, stride, (long) vbInfo.textureOffset * Float.BYTES);
228+
}
229+
case "UV1" -> {
230+
GL32.glDisableVertexAttribArray(i);
231+
GL32.glVertexAttribI2i(i, 0, 10);
232+
}
233+
case "UV2" -> {
234+
GL32.glDisableVertexAttribArray(i);
235+
//240 means full bright
236+
int x = RenderContext.FULL_BRIGHT;
237+
int y = RenderContext.FULL_BRIGHT;
238+
if (state.lightmap != null) {
239+
x = (int) (state.lightmap[0] * RenderContext.FULL_BRIGHT);
240+
y = (int) (state.lightmap[1] * RenderContext.FULL_BRIGHT);
241+
}
242+
GL32.glVertexAttribI2i(i, x, y);
238243
}
239-
GL32.glVertexAttribI2i(i, x, y);
240244
}
241245
}
242246
}
@@ -245,7 +249,7 @@ protected Binding(RenderState state, boolean wait) {
245249
}
246250
RenderContext.checkError();
247251

248-
this.restore = RenderContext.apply(state, true).and(() -> {
252+
this.restore = RenderContext.apply(state).and(() -> {
249253
RenderContext.checkError();
250254
shader.getVertexFormat().clearBufferState();
251255

@@ -270,7 +274,7 @@ protected With push(Consumer<RenderState> mod) {
270274
}
271275
RenderState state = this.state.clone();
272276
mod.accept(state);
273-
return RenderContext.apply(state, true);
277+
return RenderContext.apply(state);
274278
}
275279

276280
/**

src/main/java/cam72cam/mod/world/WorldEntityTracker.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,19 @@ public void join(ModdedEntity entity) {
6161
}
6262

6363
public void leave(ModdedEntity entity) {
64-
BlockPos pos = entity.blockPosition();
65-
long sec = SectionPos.asLong(pos);
64+
long chunk = SectionPos.asLong(entity.blockPosition());
6665

6766
lock.writeLock().lock();
6867
try {
69-
if (!umcEntities.containsKey(sec)) {
68+
if (!umcEntities.containsKey(chunk)) {
7069
return;
7170
}
72-
Collection<ModdedEntity> moddedEntities = umcEntities.get(sec);
71+
Collection<ModdedEntity> moddedEntities = umcEntities.get(chunk);
7372
moddedEntities.remove(entity);
7473

7574
if (moddedEntities.isEmpty()) {
76-
umcEntities.remove(sec);
77-
scanningRange.removeKey(sec);
75+
umcEntities.remove(chunk);
76+
scanningRange.removeKey(chunk);
7877
}
7978
} finally {
8079
lock.writeLock().unlock();
@@ -84,6 +83,12 @@ public void leave(ModdedEntity entity) {
8483
public void move(ModdedEntity entity, long oldSection, long newSection) {
8584
lock.writeLock().lock();
8685
try {
86+
if (!umcEntities.containsKey(oldSection)) {
87+
//Newly added, no need to process here
88+
//Let join handle it
89+
return;
90+
}
91+
8792
// remove from old section
8893
Set<ModdedEntity> moddedEntities = umcEntities.get(oldSection);
8994
if (moddedEntities != null) {

src/main/resources/assets/minecraft/shaders/core/umc_core.vsh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@ out vec2 texCoord0;
2626
out vec4 normal;
2727

2828
void main() {
29-
gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0);
29+
vec4 viewPos = ModelViewMat * vec4(Position, 1.0);
30+
gl_Position = ProjMat * viewPos;
3031

3132
vec4 norm = ModelViewMat * vec4(Normal, 0.0);
32-
vertexDistance = length((ModelViewMat * vec4(Position, 1.0)).xyz);
33-
vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, norm.xyz, Color);
34-
lightMapColor = texelFetch(Sampler2, UV2 / 16, 0);
33+
vertexDistance = length(viewPos.xyz);
34+
35+
if (UV2.x == 240 && UV2.y == 240) {
36+
//Vanilla emissive
37+
//TODO can we optimize this by implementing new vertex format?
38+
vertexColor = Color;
39+
lightMapColor = texelFetch(Sampler2, ivec2(15, 15), 0);
40+
} else {
41+
vertexColor = minecraft_mix_light(Light0_Direction, Light1_Direction, norm.xyz, Color);
42+
lightMapColor = texelFetch(Sampler2, UV2 / 16, 0);
43+
}
44+
3545
overlayColor = texelFetch(Sampler1, UV1, 0);
3646
texCoord0 = UV0;
3747
normal = ProjMat * norm;

0 commit comments

Comments
 (0)