Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call recalcBlockCounts on the client #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import net.minecraft.client.Minecraft;
import net.minecraft.util.BitStorage;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunkSection;
import net.minecraft.world.level.chunk.Palette;
Expand Down Expand Up @@ -62,8 +64,8 @@ abstract class LevelChunkSectionMixin implements BlockCountingChunkSection {
private final IntList tickingBlocks = new IntList();

@Override
public final int moonrise$getSpecialCollidingBlocks() {
return this.specialCollidingBlocks;
public final boolean moonrise$maybeHasSpecialCollidingBlocks() {
return this.specialCollidingBlocks != 0;
}

@Override
Expand Down Expand Up @@ -184,7 +186,7 @@ public void recalcBlockCounts() {
}

/**
* @reason Call recalcBlockCounts on the client, as the client does not invoke it when deserializing chunk sections.
* @reason the client does not invoke recalcBlockCounts when deserializing chunk sections, but we need this info for collision optimizations
* @author Spottedleaf
*/
@Inject(
Expand All @@ -193,7 +195,13 @@ public void recalcBlockCounts() {
value = "RETURN"
)
)
private void callRecalcBlocksClient(final CallbackInfo ci) {
this.recalcBlockCounts();
private void checkForSpecialCollidingBlocksClient(final CallbackInfo ci) {
final ProfilerFiller profiler = Minecraft.getInstance().getProfiler();
profiler.push("checkForSpecialCollidingBlocksClient");
try {
this.specialCollidingBlocks = this.maybeHas(CollisionUtil::isSpecialCollidingBlock) ? 1 : 0;
} finally {
profiler.pop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public interface BlockCountingChunkSection {

public int moonrise$getSpecialCollidingBlocks();
public boolean moonrise$maybeHasSpecialCollidingBlocks();

public IntList moonrise$getTickingBlockList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ public static boolean getCollisionsForBlocksOrWorldBorder(final Level world, fin
continue;
}

final boolean hasSpecial = ((BlockCountingChunkSection)section).moonrise$getSpecialCollidingBlocks() != 0;
final boolean hasSpecial = ((BlockCountingChunkSection)section).moonrise$maybeHasSpecialCollidingBlocks();
final int sectionAdjust = !hasSpecial ? 1 : 0;

final PalettedContainer<BlockState> blocks = section.states;
Expand Down