Skip to content

Commit

Permalink
Fix config UI background, fix forced-synchronous rebuilds on chunk se…
Browse files Browse the repository at this point in the history
…ction borders
  • Loading branch information
FoundationGames committed Nov 26, 2023
1 parent 67a2aa6 commit 5c85fee
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ loader_version=0.14.22

fabric_version=0.89.3+1.20.2

mod_version = 0.9+1.20.2
mod_version = 0.9.1+1.20.2
maven_group = foundationgames
archives_base_name = enhancedblockentities

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ protected void init() {
public void renderBackgroundTexture(DrawContext context) {
}

@Override
public void renderInGameBackground(DrawContext context) {
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (this.client.world == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package foundationgames.enhancedblockentities.mixin;

import foundationgames.enhancedblockentities.util.WorldUtil;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.client.render.chunk.ChunkRendererRegionBuilder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.world.chunk.light.LightingProvider;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(WorldRenderer.class)
public class WorldRendererMixin {
private ChunkSectionPos enhanced_bes$updatingChunk = null;

@ModifyVariable(method = "updateChunks",
at = @At(value = "INVOKE_ASSIGN", shift = At.Shift.AFTER, target = "Lnet/minecraft/util/math/ChunkSectionPos;from(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/math/ChunkSectionPos;"),
index = 8)
private ChunkSectionPos enhanced_bes$cacheUpdatedChunkPos(ChunkSectionPos c) {
enhanced_bes$updatingChunk = c;
return c;
}

/* X------------------------updateChunks(Camera camera)-------------------------X
|---> HERE <--- |
| if (bl) { |
Expand All @@ -17,10 +37,14 @@ public class WorldRendererMixin {
X----------------------------[END: 5 LINES DOWN]-----------------------------X */
@ModifyVariable(method = "updateChunks", at = @At(value = "JUMP", shift = At.Shift.BEFORE, opcode = Opcodes.IFEQ, ordinal = 4), index = 9)
private boolean enhanced_bes$forceSynchronousChunkRebuild(boolean old) {
if (WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD) {
WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD = false;
if (enhanced_bes$updatingChunk != null && WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD.contains(enhanced_bes$updatingChunk)) {
WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD.remove(enhanced_bes$updatingChunk);

enhanced_bes$updatingChunk = null;
return true;
}

enhanced_bes$updatingChunk = null;
return old;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
import foundationgames.enhancedblockentities.EnhancedBlockEntities;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.world.World;

import java.util.HashSet;
import java.util.Set;

public enum WorldUtil {;
public static boolean FORCE_SYNCHRONOUS_CHUNK_REBUILD = false;
public static Set<ChunkSectionPos> FORCE_SYNCHRONOUS_CHUNK_REBUILD = new HashSet<>();

public static void rebuildChunkSynchronously(World world, BlockPos pos, boolean forceSync) {
var bState = world.getBlockState(pos);
try {
WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD = forceSync;
if (forceSync) {
WorldUtil.FORCE_SYNCHRONOUS_CHUNK_REBUILD.add(ChunkSectionPos.from(pos));
}
MinecraftClient.getInstance().worldRenderer.updateBlock(world, pos, bState, bState, 8);
} catch (NullPointerException ignored) {
EnhancedBlockEntities.LOG.warn("Error rebuilding chunk at block pos "+pos);
Expand Down

0 comments on commit 5c85fee

Please sign in to comment.