Add Nuker as well as Xray, Fullbright with support for Sodium+Iris

main
Charlotte Som 2022-03-04 17:51:31 +00:00
parent e174655189
commit cd2c208d3c
18 changed files with 431 additions and 10 deletions

View File

@ -56,8 +56,8 @@ dependencies {
runtimeOnly("org.anarres:jcpp:1.4.14")
modImplementation(files("vendor/mods/baritone-unoptimized-fabric-1.8.2.jar"))
modRuntimeOnly(files("vendor/mods/iris-mc1.18.1-1.2.0-pre.jar"))
modRuntimeOnly(files("vendor/mods/sodium-fabric-mc1.18.1-0.4.0-alpha6+build.14.jar"))
modImplementation(files("vendor/mods/iris-mc1.18.1-1.2.0-pre.jar"))
modImplementation(files("vendor/mods/sodium-fabric-mc1.18.1-0.4.0-alpha6+build.14.jar"))
modRuntimeOnly(files("vendor/mods/lazydfu-0.1.2.jar"))
}

View File

@ -0,0 +1,19 @@
package codes.som.hibiscus.mixins;
import codes.som.hibiscus.HibiscusMod;
import codes.som.hibiscus.events.WorldCullingEvent;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(RenderSectionManager.class)
public abstract class MixinRenderSectionManager {
@Redirect(method = "initSearch", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;chunkCullingEnabled:Z"))
public boolean cancelCulling(MinecraftClient client) {
var event = new WorldCullingEvent();
HibiscusMod.bus().fire(event);
return client.chunkCullingEnabled && !event.isCancelled();
}
}

View File

@ -1,9 +1,11 @@
package codes.som.hibiscus.mixins;
import codes.som.hibiscus.HibiscusMod;
import codes.som.hibiscus.events.*;
import codes.som.hibiscus.events.PostRenderEntitiesEvent;
import codes.som.hibiscus.events.PostRenderWorldEvent;
import codes.som.hibiscus.events.PreRenderEntitiesEvent;
import codes.som.hibiscus.events.PreRenderWorldEvent;
import codes.som.hibiscus.util.graphics.MinecraftRenderPipelineProgress;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.LightmapTextureManager;
@ -13,7 +15,6 @@ import net.minecraft.util.math.Matrix4f;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(WorldRenderer.class)
@ -28,12 +29,13 @@ public abstract class MixinWorldRenderer {
HibiscusMod.bus().fire(new PostRenderWorldEvent(tickDelta, camera, matrices));
}
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSpectator()Z"))
public boolean cancelCulling(ClientPlayerEntity instance) {
/* Obsoleted by Sodium-compatible MixinRenderSectionManager
@Redirect(method = "setupTerrain", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;chunkCullingEnabled:Z"))
public boolean cancelCulling(MinecraftClient client) {
var event = new WorldCullingEvent();
HibiscusMod.bus().fire(event);
return instance.isSpectator() || event.isCancelled();
}
return client.chunkCullingEnabled && !event.isCancelled();
} */
@Inject(method = "render", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", args = "ldc=entities"))
private void startRenderEntities(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {

View File

@ -0,0 +1,39 @@
package codes.som.hibiscus.mixins.xray;
import codes.som.hibiscus.subsystems.xray.XrayBlockView;
import codes.som.hibiscus.subsystems.xray.XraySystem;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
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.callback.CallbackInfoReturnable;
@Mixin(Block.class)
public abstract class MixinBlock {
private static boolean ignoreShouldDrawSide = false;
@Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true)
private static void onShouldRenderFace(BlockState state, BlockView world, BlockPos pos, Direction side, BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) {
if (ignoreShouldDrawSide)
return;
if (!XraySystem.shouldRenderXray())
return;
if (!XraySystem.isXrayBlock(state)) {
cir.setReturnValue(false);
return;
}
var xrayView = new XrayBlockView(world);
ignoreShouldDrawSide = true;
boolean xrayShouldDrawSide = Block.shouldDrawSide(state, xrayView, pos, side, blockPos);
ignoreShouldDrawSide = false;
cir.setReturnValue(xrayShouldDrawSide);
}
}

View File

@ -0,0 +1,43 @@
package codes.som.hibiscus.mixins.xray;
import codes.som.hibiscus.subsystems.xray.XrayBlockView;
import codes.som.hibiscus.subsystems.xray.XraySystem;
import me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
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.CallbackInfoReturnable;
@Mixin(BlockOcclusionCache.class)
public abstract class MixinBlockOcclusionCache {
@Shadow
public abstract boolean shouldDrawSide(BlockState selfState, BlockView view, BlockPos pos, Direction facing);
private boolean ignoreShouldDrawSide = false;
@Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true)
private void onShouldDrawSide(BlockState selfState, BlockView view, BlockPos pos, Direction facing, CallbackInfoReturnable<Boolean> cir) {
if (ignoreShouldDrawSide)
return;
if (!XraySystem.shouldRenderXray())
return;
if (!XraySystem.isXrayBlock(selfState)) {
cir.setReturnValue(false);
return;
}
var xrayView = new XrayBlockView(view);
ignoreShouldDrawSide = true;
boolean xrayShouldDrawSide = this.shouldDrawSide(selfState, xrayView, pos, facing);
ignoreShouldDrawSide = false;
cir.setReturnValue(xrayShouldDrawSide);
}
}

View File

@ -0,0 +1,20 @@
package codes.som.hibiscus.mixins.xray;
import codes.som.hibiscus.subsystems.xray.XraySystem;
import me.jellysquid.mods.sodium.client.render.chunk.tasks.ChunkRenderRebuildTask;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ChunkRenderRebuildTask.class)
public abstract class MixinChunkRenderRebuildTask {
@Redirect(method = "performBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getRenderType()Lnet/minecraft/block/BlockRenderType;"))
private BlockRenderType onGetRenderType(BlockState instance) {
if (!XraySystem.shouldRenderXray() || XraySystem.isXrayBlock(instance))
return instance.getRenderType();
return BlockRenderType.INVISIBLE;
}
}

View File

@ -0,0 +1,58 @@
package codes.som.hibiscus.mixins.xray;
import codes.som.hibiscus.subsystems.xray.XrayBlockRenderView;
import codes.som.hibiscus.subsystems.xray.XraySystem;
import me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;
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.CallbackInfoReturnable;
@Mixin(FluidRenderer.class)
public abstract class MixinFluidRenderer {
@Shadow
protected abstract boolean isFluidOccluded(BlockRenderView world, int x, int y, int z, Direction dir, Fluid fluid);
@Shadow
protected abstract boolean isSideExposed(BlockRenderView world, int x, int y, int z, Direction dir, float height);
private boolean ignoreFluidOccluded = false;
private boolean ignoreSideExposed = false;
@Inject(method = "isFluidOccluded", at = @At("HEAD"), cancellable = true)
private void onIsFluidOccluded(BlockRenderView world, int x, int y, int z, Direction dir, Fluid fluid, CallbackInfoReturnable<Boolean> cir) {
if (ignoreFluidOccluded)
return;
if (!XraySystem.shouldRenderXray())
return;
var xrayView = new XrayBlockRenderView(world);
ignoreFluidOccluded = true;
var xrayFluidOccluded = this.isFluidOccluded(xrayView, x, y, z, dir, fluid);
ignoreFluidOccluded = false;
cir.setReturnValue(xrayFluidOccluded);
}
@Inject(method = "isSideExposed", at = @At("HEAD"), cancellable = true)
private void onIsSideExposed(BlockRenderView world, int x, int y, int z, Direction dir, float height, CallbackInfoReturnable<Boolean> cir) {
if (ignoreSideExposed)
return;
if (!XraySystem.shouldRenderXray())
return;
var xrayView = new XrayBlockRenderView(world);
ignoreSideExposed = true;
var xraySideExposed = this.isSideExposed(xrayView, x, y, z, dir, height);
ignoreSideExposed = false;
cir.setReturnValue(xraySideExposed);
}
}

View File

@ -0,0 +1,31 @@
package codes.som.hibiscus.mixins.xray;
import codes.som.hibiscus.subsystems.fullbright.FullbrightSystem;
import codes.som.hibiscus.subsystems.xray.XraySystem;
import me.jellysquid.mods.sodium.client.model.light.data.LightDataAccess;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(LightDataAccess.class)
public abstract class MixinLightDataAccess {
@Redirect(method = "compute", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getAmbientOcclusionLightLevel(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;)F"))
private float getAOLevel(BlockState instance, BlockView blockView, BlockPos blockPos) {
if (XraySystem.shouldRenderXray() || FullbrightSystem.shouldRenderFullbright())
return 1f;
return instance.getAmbientOcclusionLightLevel(blockView, blockPos);
}
@Redirect(method = "compute", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;getLightmapCoordinates(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)I"))
private int getLMCoords(BlockRenderView world, BlockState state, BlockPos pos) {
if (XraySystem.shouldRenderXray() || FullbrightSystem.shouldRenderFullbright())
return 15728832;
return WorldRenderer.getLightmapCoordinates(world, state, pos);
}
}

View File

@ -66,6 +66,7 @@ object HibiscusMod : ModInitializer {
keybinds.register(GLFW_KEY_O, "nofall")
keybinds.register(GLFW_KEY_G, "speed")
keybinds.register(GLFW_KEY_B, "freecam")
keybinds.register(GLFW_KEY_X, "xray")
features.getFeature<AntiGhost>().enabled = true
features.getFeature<NoFallDamage>().enabled = true

View File

@ -9,7 +9,10 @@ import codes.som.hibiscus.features.movement.Speed
import codes.som.hibiscus.features.overlay.Overlay
import codes.som.hibiscus.features.player.NoFallDamage
import codes.som.hibiscus.features.player.NoSprintingPacket
import codes.som.hibiscus.features.player.Nuker
import codes.som.hibiscus.features.visual.Freecam
import codes.som.hibiscus.features.visual.Fullbright
import codes.som.hibiscus.features.visual.Xray
import codes.som.hibiscus.util.Resettable
fun allFeatureClasses(): Array<() -> Feature> = arrayOf(
@ -22,6 +25,9 @@ fun allFeatureClasses(): Array<() -> Feature> = arrayOf(
::AntiGhost,
::Freecam,
::NoSprintingPacket,
::Xray,
::Nuker,
::Fullbright,
)
class FeaturesRegistry : Resettable {

View File

@ -0,0 +1,63 @@
package codes.som.hibiscus.features.player
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.events.PlayerTickEvent
import codes.som.hibiscus.player
import codes.som.hibiscus.world
import net.minecraft.item.PickaxeItem
import net.minecraft.item.ShovelItem
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
import net.minecraft.util.math.Direction
class Nuker : Feature("Nuker", FeatureCategory.PLAYER) {
init {
on { _: PlayerTickEvent ->
val activeItem = player.mainHandStack
if (activeItem == null || (activeItem.item !is PickaxeItem && activeItem.item !is ShovelItem))
return@on
if (activeItem.damage > activeItem.maxDamage * 0.75)
return@on
for (x in -6..6) {
for (z in -6..6) {
for (y in 0..5) {
val pos = player.blockPos.add(x, y, z)
if (player.pos.squaredDistanceTo(
pos.x.toDouble() + 0.5,
pos.y.toDouble() + 0.5,
pos.z.toDouble() + 0.5
) > 36.0
) {
continue
}
val blockState = world.getBlockState(pos)
if (blockState.isAir)
continue
if (blockState.calcBlockBreakingDelta(player, world, pos) < 0.7) {
continue
}
player.networkHandler.sendPacket(
PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.START_DESTROY_BLOCK,
pos,
Direction.UP
)
)
player.networkHandler.sendPacket(
PlayerActionC2SPacket(
PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK,
pos,
Direction.UP
)
)
}
}
}
}
}
}

View File

@ -0,0 +1,15 @@
package codes.som.hibiscus.features.visual
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.mc
class Fullbright : Feature("Fullbright", FeatureCategory.VISUAL) {
override fun onEnable() {
mc.worldRenderer.reload()
}
override fun onDisable() {
mc.worldRenderer.reload()
}
}

View File

@ -0,0 +1,24 @@
package codes.som.hibiscus.features.visual
import codes.som.hibiscus.api.feature.Feature
import codes.som.hibiscus.api.feature.FeatureCategory
import codes.som.hibiscus.events.WorldCullingEvent
import codes.som.hibiscus.mc
class Xray : Feature("X-ray", FeatureCategory.VISUAL) {
init {
on { event: WorldCullingEvent -> event.cancel() }
}
override fun onEnable() {
mc.worldRenderer.reload()
}
override fun onDisable() {
mc.worldRenderer.reload()
}
override fun createFeatureCommand() = super.createFeatureCommand().apply {
alias("xray")
}
}

View File

@ -0,0 +1,16 @@
package codes.som.hibiscus.subsystems.fullbright
import codes.som.hibiscus.HibiscusMod
import codes.som.hibiscus.features.visual.Fullbright
object FullbrightSystem {
@JvmStatic
fun shouldRenderFullbright(): Boolean {
try {
return HibiscusMod.features.getFeature<Fullbright>().enabled
} catch (_: Exception) {
}
return false
}
}

View File

@ -0,0 +1,29 @@
package codes.som.hibiscus.subsystems.xray
import net.minecraft.block.BlockState
import net.minecraft.block.Blocks
import net.minecraft.util.math.BlockPos
import net.minecraft.world.BlockRenderView
import net.minecraft.world.BlockView
class XrayBlockView(private val delegate: BlockView) : BlockView by delegate {
override fun getBlockState(pos: BlockPos): BlockState {
val state = delegate.getBlockState(pos)
if (state.isAir || XraySystem.isXrayBlock(state)) {
return state
}
return Blocks.BIRCH_FENCE.defaultState
}
}
class XrayBlockRenderView(private val delegate: BlockRenderView) : BlockRenderView by delegate {
override fun getBlockState(pos: BlockPos): BlockState {
val state = delegate.getBlockState(pos)
if (state.isAir || XraySystem.isXrayBlock(state)) {
return state
}
return Blocks.BIRCH_FENCE.defaultState
}
}

View File

@ -0,0 +1,28 @@
package codes.som.hibiscus.subsystems.xray
import codes.som.hibiscus.HibiscusMod
import codes.som.hibiscus.features.visual.Xray
import net.minecraft.block.BlockState
import net.minecraft.block.FluidBlock
import net.minecraft.block.IceBlock
import net.minecraft.block.OreBlock
object XraySystem {
@JvmStatic
fun shouldRenderXray(): Boolean {
try {
return HibiscusMod.features.getFeature<Xray>().enabled
} catch (_: Exception) {
}
return false
}
@JvmStatic
fun isXrayBlock(blockState: BlockState): Boolean {
return when (blockState.block) {
is OreBlock, is FluidBlock, is IceBlock -> true
else -> false
}
}
}

View File

@ -2,3 +2,24 @@ accessWidener v1 named
accessible class net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractType
accessible class net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractTypeHandler
accessible class net/minecraft/client/render/RenderLayer$MultiPhaseParameters
accessible class net/minecraft/client/render/RenderPhase$Cull
accessible class net/minecraft/client/render/RenderPhase$DepthTest
accessible class net/minecraft/client/render/RenderPhase$Layering
accessible class net/minecraft/client/render/RenderPhase$Lightmap
accessible class net/minecraft/client/render/RenderPhase$LineWidth
accessible class net/minecraft/client/render/RenderPhase$OffsetTexturing
accessible class net/minecraft/client/render/RenderPhase$Overlay
accessible class net/minecraft/client/render/RenderPhase$Shader
accessible class net/minecraft/client/render/RenderPhase$Target
accessible class net/minecraft/client/render/RenderPhase$Texture
accessible class net/minecraft/client/render/RenderPhase$TextureBase
accessible class net/minecraft/client/render/RenderPhase$Textures
accessible class net/minecraft/client/render/RenderPhase$Texturing
accessible class net/minecraft/client/render/RenderPhase$Toggleable
accessible class net/minecraft/client/render/RenderPhase$Transparency
accessible class net/minecraft/client/render/RenderPhase$WriteMaskState
accessible field net/minecraft/client/render/RenderPhase SOLID_SHADER Lnet/minecraft/client/render/RenderPhase$Shader;
accessible method net/minecraft/client/render/RenderLayer of (Ljava/lang/String;Lnet/minecraft/client/render/VertexFormat;Lnet/minecraft/client/render/VertexFormat$DrawMode;IZZLnet/minecraft/client/render/RenderLayer$MultiPhaseParameters;)Lnet/minecraft/client/render/RenderLayer$MultiPhase;
accessible class net/minecraft/client/render/RenderLayer$MultiPhase

View File

@ -17,6 +17,12 @@
"MixinGameRenderer",
"MixinKeyboard",
"MixinMinecraftClient",
"MixinWorldRenderer"
"MixinRenderSectionManager",
"MixinWorldRenderer",
"xray.MixinBlock",
"xray.MixinBlockOcclusionCache",
"xray.MixinChunkRenderRebuildTask",
"xray.MixinFluidRenderer",
"xray.MixinLightDataAccess"
]
}