Skip to content

Commit

Permalink
Merge branch '1.20.4' into 1.20.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jun 18, 2024
2 parents 60bfd8f + 3289e7f commit aa33447
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package xaeroplus.event;

import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;

// fired right before block update is applied to mc.level
public record ChunkBlockUpdateEvent(ClientboundBlockUpdatePacket packet) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package xaeroplus.event;

import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;

// fired right before block updates are applied to mc.level
public record ChunkBlocksUpdateEvent(ClientboundSectionBlocksUpdatePacket packet) { }
5 changes: 0 additions & 5 deletions common/src/main/java/xaeroplus/event/PacketReceivedEvent.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xaeroplus.XaeroPlus;
import xaeroplus.event.ChunkBlockUpdateEvent;
import xaeroplus.event.ChunkBlocksUpdateEvent;
import xaeroplus.event.ChunkDataEvent;

@Mixin(ClientPacketListener.class)
Expand All @@ -19,4 +23,20 @@ public class MixinClientPlayNetworkHandler {
public void onChunkData(final ClientboundLevelChunkWithLightPacket packet, final CallbackInfo ci) {
XaeroPlus.EVENT_BUS.call(new ChunkDataEvent(level.getChunk(packet.getX(), packet.getZ())));
}

@Inject(method = "handleChunkBlocksUpdate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket;runUpdates(Ljava/util/function/BiConsumer;)V"
))
public void onChunkBlocksUpdate(final ClientboundSectionBlocksUpdatePacket packet, final CallbackInfo ci) {
XaeroPlus.EVENT_BUS.call(new ChunkBlocksUpdateEvent(packet));
}

@Inject(method = "handleBlockUpdate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/multiplayer/ClientLevel;setServerVerifiedBlockState(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)V"
))
public void onBlockUpdate(final ClientboundBlockUpdatePacket packet, final CallbackInfo ci) {
XaeroPlus.EVENT_BUS.call(new ChunkBlockUpdateEvent(packet));
}
}
19 changes: 2 additions & 17 deletions common/src/main/java/xaeroplus/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,9 @@

import xaeroplus.XaeroPlus;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public abstract class Module {

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ModuleInfo {
boolean enabled() default false;
}

private boolean enabled = getDeclaration().enabled();

private ModuleInfo getDeclaration() {
return getClass().getAnnotation(ModuleInfo.class);
}
private boolean enabled = false;

protected void onEnable() {

Expand Down Expand Up @@ -66,7 +51,7 @@ public void disable() {
public void toggle() {
if (isEnabled()) {
disable();
} else if (!isEnabled()) {
} else {
enable();
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/xaeroplus/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static void init() {
new Portals(),
new PortalSkipDetection(),
new WaystoneSync(),
new WorldTools())
.forEach(ModuleManager::addModule);
new WorldTools()
).forEach(ModuleManager::addModule);
}

private static void addModule(Module module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static net.minecraft.world.level.Level.NETHER;
import static net.minecraft.world.level.Level.OVERWORLD;

@Module.ModuleInfo()
public class BaritoneGoalSync extends Module {

@EventHandler
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/xaeroplus/module/impl/FpsLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.util.function.Supplier;

@Module.ModuleInfo()
public class FpsLimiter extends Module {
// todo: Buffer and mutate the rotation framebuffer separately to not cause visual
// impact while minimap north is not locked
Expand Down
89 changes: 40 additions & 49 deletions common/src/main/java/xaeroplus/module/impl/NewChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
import net.lenni0451.lambdaevents.EventHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.material.FluidState;
import xaeroplus.Globals;
import xaeroplus.XaeroPlus;
import xaeroplus.event.ClientTickEvent;
import xaeroplus.event.PacketReceivedEvent;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.event.*;
import xaeroplus.feature.render.ChunkHighlightProvider;
import xaeroplus.feature.render.ColorHelper;
import xaeroplus.feature.render.highlights.ChunkHighlightCache;
Expand All @@ -36,11 +29,10 @@
import static xaeroplus.feature.render.ColorHelper.getColor;
import static xaeroplus.util.ChunkUtils.getActualDimension;

@Module.ModuleInfo()
public class NewChunks extends Module {
// todo: add newchunk detection mode setting: fluid flows (current), timing, etc.

// chunks where liquid has not flowed from source blocks
private ChunkHighlightCache newChunksCache = new ChunkHighlightLocalCache();
// chunks where liquid sources have already flowed
private final Cache<Long, Byte> oldChunksCache = Caffeine.newBuilder()
.maximumSize(50)
.expireAfterWrite(10L, TimeUnit.SECONDS)
Expand Down Expand Up @@ -69,54 +61,53 @@ public void setNewChunksCache(boolean disk) {
}

@EventHandler
public void onPacketReceivedEvent(final PacketReceivedEvent event) {
public void onMultiBlockUpdate(final ChunkBlocksUpdateEvent event) {
if (mc.level == null || ((AccessorWorldRenderer) mc.levelRenderer).getChunks() == null) return;
// credits to BleachHack for this fluid flow based detection method
if (event.packet() instanceof ClientboundSectionBlocksUpdatePacket packet) {
packet.runUpdates((pos, state) -> {
if (!state.getFluidState().isEmpty() && !state.getFluidState().isSource()) {
ChunkPos chunkPos = new ChunkPos(pos);
for (Direction dir: searchDirs) {
if (mc.level.getBlockState(pos.relative(dir)).getFluidState().isSource()
&& oldChunksCache.getIfPresent(ChunkUtils.chunkPosToLong(chunkPos)) == null) {
newChunksCache.addHighlight(chunkPos.x, chunkPos.z);
return;
}
}
}
});
} else if (event.packet() instanceof ClientboundBlockUpdatePacket packet) {
if (!packet.getBlockState().getFluidState().isEmpty() && !packet.getBlockState().getFluidState().isSource()) {
ChunkPos chunkPos = new ChunkPos(packet.getPos());

event.packet().runUpdates((pos, state) -> {
if (!state.getFluidState().isEmpty() && !state.getFluidState().isSource()) {
ChunkPos chunkPos = new ChunkPos(pos);
for (Direction dir: searchDirs) {
if (mc.level.getBlockState(packet.getPos().relative(dir)).getFluidState().isSource()
&& oldChunksCache.getIfPresent(ChunkUtils.chunkPosToLong(chunkPos)) == null) {
if (mc.level.getBlockState(pos.relative(dir)).getFluidState().isSource()
&& oldChunksCache.getIfPresent(ChunkUtils.chunkPosToLong(chunkPos)) == null) {
newChunksCache.addHighlight(chunkPos.x, chunkPos.z);
return;
}
}
}
} else if (event.packet() instanceof ClientboundLevelChunkWithLightPacket packet) {
ChunkPos pos = new ChunkPos(packet.getX(), packet.getZ());
if (!newChunksCache.isHighlighted(pos.x, pos.z, getActualDimension()) && mc.level.getChunkSource().getChunkForLighting(packet.getX(), packet.getZ()) == null) {
LevelChunk chunk = new LevelChunk(mc.level, pos);
try {
chunk.replaceWithPacketData(packet.getChunkData().getReadBuffer(), new CompoundTag(), packet.getChunkData().getBlockEntitiesTagsConsumer(packet.getX(), packet.getZ()));
} catch (Throwable e) {
});
}

@EventHandler
public void onBlockUpdate(final ChunkBlockUpdateEvent event) {
if (mc.level == null || ((AccessorWorldRenderer) mc.levelRenderer).getChunks() == null) return;
var packet = event.packet();
if (!packet.getBlockState().getFluidState().isEmpty() && !packet.getBlockState().getFluidState().isSource()) {
final int chunkX = ChunkUtils.posToChunkPos(packet.getPos().getX());
final int chunkZ = ChunkUtils.posToChunkPos(packet.getPos().getZ());
final long chunkPosLong = ChunkUtils.chunkPosToLong(chunkX, chunkZ);
for (Direction dir: searchDirs) {
if (mc.level.getBlockState(packet.getPos().relative(dir)).getFluidState().isSource()
&& oldChunksCache.getIfPresent(chunkPosLong) == null) {
newChunksCache.addHighlight(chunkX, chunkZ);
return;
}
}
}
}

for (int x = 0; x < 16; x++) {
for (int y = mc.level.getMinBuildHeight(); y < mc.level.getMaxBuildHeight(); y++) {
for (int z = 0; z < 16; z++) {
FluidState fluid = chunk.getFluidState(x, y, z);

if (!fluid.isEmpty() && !fluid.isSource()) {
oldChunksCache.put(ChunkUtils.chunkPosToLong(pos), (byte) 0);
return;
}
}
@EventHandler
public void onChunkData(final ChunkDataEvent event) {
if (mc.level == null || ((AccessorWorldRenderer) mc.levelRenderer).getChunks() == null) return;
var chunk = event.chunk();
var chunkPos = chunk.getPos();
if (newChunksCache.isHighlighted(chunkPos.x, chunkPos.z, getActualDimension())) return;
for (int x = 0; x < 16; x++) {
for (int y = mc.level.getMinBuildHeight(); y < mc.level.getMaxBuildHeight(); y++) {
for (int z = 0; z < 16; z++) {
FluidState fluid = chunk.getFluidState(x, y, z);
if (!fluid.isEmpty() && !fluid.isSource()) {
oldChunksCache.put(ChunkUtils.chunkPosToLong(chunkPos), (byte) 0);
return;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/xaeroplus/module/impl/OldChunks.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static net.minecraft.world.level.Level.*;
import static xaeroplus.feature.render.ColorHelper.getColor;

@Module.ModuleInfo()
public class OldChunks extends Module {
private ChunkHighlightCache oldChunksCache = new ChunkHighlightLocalCache();
private ChunkHighlightCache modernChunksCache = new ChunkHighlightLocalCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static xaeroplus.util.ChunkUtils.*;
import static xaeroplus.util.GuiMapHelper.*;

@Module.ModuleInfo()
public class PortalSkipDetection extends Module {
private final ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
.setNameFormat("XaeroPlus-PortalSkipDetection-Search")
Expand Down
24 changes: 8 additions & 16 deletions common/src/main/java/xaeroplus/module/impl/Portals.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import net.lenni0451.lambdaevents.EventHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -21,10 +19,7 @@
import net.minecraft.world.level.chunk.LevelChunk;
import xaeroplus.Globals;
import xaeroplus.XaeroPlus;
import xaeroplus.event.ChunkDataEvent;
import xaeroplus.event.ClientTickEvent;
import xaeroplus.event.PacketReceivedEvent;
import xaeroplus.event.XaeroWorldChangeEvent;
import xaeroplus.event.*;
import xaeroplus.feature.render.ChunkHighlightProvider;
import xaeroplus.feature.render.ColorHelper;
import xaeroplus.feature.render.highlights.ChunkHighlightCache;
Expand All @@ -41,8 +36,6 @@
import static net.minecraft.world.level.Level.*;
import static xaeroplus.feature.render.ColorHelper.getColor;


@Module.ModuleInfo()
public class Portals extends Module {
private ChunkHighlightCache portalsCache = new ChunkHighlightLocalCache();
private final Minecraft mc = Minecraft.getInstance();
Expand Down Expand Up @@ -101,14 +94,13 @@ public void onChunkData(final ChunkDataEvent event) {
}

@EventHandler
public void onPacketReceived(final PacketReceivedEvent event) {
if (event.packet() instanceof ClientboundBlockUpdatePacket) {
final ClientboundBlockUpdatePacket packet = (ClientboundBlockUpdatePacket) event.packet();
handleBlockChange(packet.getPos(), packet.getBlockState());
} else if (event.packet() instanceof ClientboundSectionBlocksUpdatePacket) {
final ClientboundSectionBlocksUpdatePacket packet = (ClientboundSectionBlocksUpdatePacket) event.packet();
packet.runUpdates(this::handleBlockChange);
}
public void onMultiBlockUpdate(final ChunkBlocksUpdateEvent event) {
event.packet().runUpdates(this::handleBlockChange);
}

@EventHandler
public void onBlockUpdate(final ChunkBlockUpdateEvent event) {
handleBlockChange(event.packet().getPos(), event.packet().getBlockState());
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import static xaero.common.settings.ModSettings.COLORS;

@Module.ModuleInfo()
public class WaystoneSync extends Module {
private boolean subscribed = false;
private BlayWaystonesHelper blayWaystonesHelper = new BlayWaystonesHelper();
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/xaeroplus/module/impl/WorldTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static xaeroplus.feature.render.ColorHelper.getColor;

@Module.ModuleInfo()
public class WorldTools extends Module {

private int worldToolsColor = getColor(0, 255, 0, 100);
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/xaeroplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"MixinWorldMapOption",
"mc.AccessorGameOptions",
"mc.AccessorWorldRenderer",
"mc.MixinClientConnection",
"mc.MixinClientPlayNetworkHandler",
"mc.MixinGlStateManager",
"mc.MixinMinecraftClient",
Expand Down

0 comments on commit aa33447

Please sign in to comment.