Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
new: Add Xray (#2186)
Browse files Browse the repository at this point in the history
Co-authored-by: lv <[email protected]>
  • Loading branch information
scorbett123 and 5HT2 authored Apr 19, 2021
1 parent 330e2eb commit da70eb4
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import org.kamiblue.client.module.modules.movement.Jesus;
import org.kamiblue.client.module.modules.render.Xray;
import org.spongepowered.asm.mixin.Final;
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

Expand All @@ -24,4 +28,11 @@ public class MixinStateImplementation {
public void addCollisionBoxToList(World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isActualState, CallbackInfo ci) {
Jesus.handleAddCollisionBoxToList(pos, block, entityIn, collidingBoxes);
}

@Inject(method = "shouldSideBeRendered", at = @At("HEAD"), cancellable = true)
public void shouldSideBeRendered(IBlockAccess blockAccess, BlockPos pos, EnumFacing facing, CallbackInfoReturnable<Boolean> ci) {
if (Xray.shouldReplace(blockAccess.getBlockState(pos.offset(facing)))) {
ci.setReturnValue(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import org.kamiblue.client.module.modules.movement.Velocity;
import org.kamiblue.client.module.modules.player.Freecam;
import org.kamiblue.client.module.modules.player.ViewLock;
import org.kamiblue.client.module.modules.render.Xray;
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = Entity.class, priority = Integer.MAX_VALUE)
public abstract class MixinEntity {
Expand Down Expand Up @@ -48,4 +50,11 @@ public void turn(float yaw, float pitch, CallbackInfo ci) {
if (Freecam.handleTurn(casted, yaw, pitch, ci)) return;
ViewLock.handleTurn(casted, yaw, pitch, ci);
}

@Inject(method = "getBrightnessForRender", at = @At("HEAD"), cancellable = true)
public void getBrightnessForRender(CallbackInfoReturnable<Integer> cir) {
if (Xray.INSTANCE.isEnabled()) {
cir.setReturnValue(15);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.kamiblue.client.mixin.client.render;

import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.tileentity.TileEntity;
import org.kamiblue.client.module.modules.render.Xray;
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.CallbackInfo;

@Mixin(TileEntityRendererDispatcher.class)
public class MixinTileRendererDispatcher {

@Inject(method = "render(Lnet/minecraft/tileentity/TileEntity;FI)V", at = @At("HEAD"), cancellable = true)
public void render(TileEntity tileEntityIn, float partialTicks, int destroyStage, CallbackInfo ci) {
if (Xray.shouldReplace(tileEntityIn.getBlockType().getDefaultState())) {
ci.cancel();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.kamiblue.client.module.modules.player.Freecam;
import org.kamiblue.client.module.modules.render.Xray;
import org.kamiblue.client.util.Wrapper;
import org.kamiblue.client.util.graphics.KamiTessellator;
import org.kamiblue.client.util.math.VectorUtils;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.EnumSet;
Expand All @@ -38,4 +40,11 @@ public void getVisibleFacings(CallbackInfoReturnable<Set<EnumFacing>> ci) {
}
}

@Inject(method = "setOpaqueCube", at = @At("HEAD"), cancellable = true)
public void setOpaqueCube(BlockPos pos, CallbackInfo ci) {
if (Xray.INSTANCE.isEnabled()) {
ci.cancel();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.kamiblue.client.mixin.client.world;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import org.kamiblue.client.module.modules.render.Xray;
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 class MixinBlock {
@Inject(method = "getLightValue(Lnet/minecraft/block/state/IBlockState;)I", at = @At("HEAD"), cancellable = true)
public void getLightValue(IBlockState state, CallbackInfoReturnable<Integer> cir) {
if (Xray.INSTANCE.isEnabled()) {
cir.setReturnValue(15);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.kamiblue.client.mixin.client.world;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BlockFluidRenderer;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import org.kamiblue.client.module.modules.render.Xray;
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(BlockFluidRenderer.class)
public class MixinBlockFluidRenderer {
@Inject(method = "renderFluid", at = @At("HEAD"), cancellable = true)
public void renderFluid(IBlockAccess blockAccess, IBlockState blockStateIn, BlockPos blockPosIn, BufferBuilder bufferBuilderIn, CallbackInfoReturnable<Boolean> ci) {
if (Xray.shouldReplace(blockStateIn)) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.kamiblue.client.mixin.client.world;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.BlockModelRenderer;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import org.kamiblue.client.module.modules.render.Xray;
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(BlockModelRenderer.class)
public class MixinBlockModelRenderer {
@Inject(method = "renderModel(Lnet/minecraft/world/IBlockAccess;Lnet/minecraft/client/renderer/block/model/IBakedModel;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/renderer/BufferBuilder;ZJ)Z", at = @At("HEAD"), cancellable = true)
public void renderModel(IBlockAccess worldIn, IBakedModel modelIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer, boolean checkSides, long rand, CallbackInfoReturnable<Boolean> ci) {
if (Xray.shouldReplace(stateIn)) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.kamiblue.client.command.commands

import org.kamiblue.client.command.ClientCommand
import org.kamiblue.client.module.modules.render.Xray
import org.kamiblue.client.util.text.MessageSendHelper
import org.kamiblue.client.util.text.formatValue

// TODO: Remove once GUI has List
object XrayCommand : ClientCommand(
name = "Xray",
description = "Manage visible xray blocks"
) {

init {
literal("add", "+") {
block("block") { blockArg ->
execute("Add a block to visible xray list") {
val blockName = blockArg.value.registryName.toString()

if (Xray.visibleList.contains(blockName)) {
MessageSendHelper.sendErrorMessage("${formatValue(blockName)} is already added to the visible block list")
} else {
Xray.visibleList.editValue { it.add(blockName) }
MessageSendHelper.sendChatMessage("${formatValue(blockName)} has been added to the visible block list")
}
}
}
}

literal("remove", "-") {
block("block") { blockArg ->
execute("Remove a block from visible xray list") {
val blockName = blockArg.value.registryName.toString()

if (!Xray.visibleList.contains(blockName)) {
MessageSendHelper.sendErrorMessage("You do not have ${formatValue(blockName)} added to xray visible block list")
} else {
Xray.visibleList.editValue { it.remove(blockName) }
MessageSendHelper.sendChatMessage("Removed ${formatValue(blockName)} from xray visible block list")
}
}
}
}

literal("set", "=") {
block("block") { blockArg ->
execute("Set the xray list to one block") {
val blockName = blockArg.value.registryName.toString()

Xray.visibleList.editValue {
it.clear()
it.add(blockName)
}
MessageSendHelper.sendChatMessage("Set the xray block list to ${formatValue(blockName)}")
}
}
}

literal("reset", "default") {
execute("Reset the visible block list to defaults") {
Xray.visibleList.editValue { it.resetValue() }
MessageSendHelper.sendChatMessage("Reset the visible block list to defaults")
}
}

literal("list") {
execute("Print visible list") {
MessageSendHelper.sendChatMessage(Xray.visibleList.joinToString())
}
}

literal("clear") {
execute("Set the visible list to nothing") {
Xray.visibleList.editValue { it.clear() }
MessageSendHelper.sendChatMessage("Cleared the visible block list")
}
}
}
}
31 changes: 31 additions & 0 deletions src/main/kotlin/org/kamiblue/client/module/modules/render/Xray.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.kamiblue.client.module.modules.render

import net.minecraft.block.state.IBlockState
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting

internal object Xray : Module(
name = "Xray",
description = "Lets you see through blocks",
category = Category.RENDER
) {
private val defaultVisibleList = linkedSetOf("minecraft:diamond_ore", "minecraft:iron_ore", "minecraft:gold_ore", "minecraft:portal", "minecraft:cobblestone")

val visibleList = setting(CollectionSetting("Visible List", defaultVisibleList, { false }))

@JvmStatic
fun shouldReplace(state: IBlockState): Boolean {
return isEnabled && !visibleList.contains(state.block.registryName.toString())
}

init {
onToggle {
mc.renderGlobal.loadRenderers()
}

visibleList.editListeners.add {
mc.renderGlobal.loadRenderers()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ open class MutableSetting<T : Any>(
}
field = new

valueListeners.forEach { it(prev, field) }
listeners.forEach { it() }
// TODO: CollectionSetting.editValue needs to somehow work here
valueListeners.forEach { it.invoke(prev, field) }
listeners.forEach { it.invoke() }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ class CollectionSetting<E : Any, T : MutableCollection<E>>(
override val defaultValue: T = valueClass.newInstance()
private val lockObject = Any()
private val type = TypeToken.getArray(value.first().javaClass).type
val editListeners = ArrayList<() -> Unit>()

init {
value.toCollection(defaultValue)
}

// Should be used instead of directly accessing value itself
// TODO: Hook into [MutableSetting] and allow this to work with `this.value.add(someVal)`
fun editValue(block: (value: CollectionSetting<E, T>) -> Unit) {
block.invoke(this)
editListeners.forEach { it.invoke() }
}

override fun resetValue() {
synchronized(lockObject) {
value.clear()
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/mixins.kami.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@
"render.MixinRenderPlayer",
"render.MixinTileEntityRendererDispatcher",
"render.MixinTileEntitySignRenderer",
"render.MixinTileRendererDispatcher",
"render.MixinViewFrustum",
"render.MixinVisGraph",
"world.MixinBlock",
"world.MixinBlockFluidRenderer",
"world.MixinBlockLiquid",
"world.MixinBlockModelRenderer",
"world.MixinBlockSoulSand",
"world.MixinBlockWeb",
"world.MixinWorld"
Expand Down

0 comments on commit da70eb4

Please sign in to comment.