forked from CCBlueX/LiquidBounce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Mob Owners and Ghost Hand (Closes CCBlueX#605)
- Loading branch information
1 parent
4f25029
commit 2d9230f
Showing
11 changed files
with
413 additions
and
57 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/main/java/net/ccbluex/liquidbounce/common/TweakedMethods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce) | ||
* | ||
* Copyright (c) 2016 - 2021 CCBlueX | ||
* | ||
* LiquidBounce is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiquidBounce is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.ccbluex.liquidbounce.common; | ||
|
||
import net.ccbluex.liquidbounce.features.module.modules.exploit.ModuleGhostHand; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.fluid.FluidState; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.RaycastContext; | ||
|
||
public class TweakedMethods { | ||
|
||
public static BlockHitResult tweakedRaycast(BlockView blockView, RaycastContext context) { | ||
if (ModuleGhostHand.INSTANCE.getEnabled()) { | ||
var returned = (BlockHitResult) BlockView.raycast(context.getStart(), context.getEnd(), context, (contextx, pos) -> { | ||
BlockState blockState = blockView.getBlockState(pos); | ||
|
||
if (!ModuleGhostHand.INSTANCE.getTargetedBlocks().contains(blockState.getBlock())) | ||
return null; | ||
|
||
VoxelShape voxelShape = contextx.getBlockShape(blockState, blockView, pos); | ||
|
||
return blockView.raycastBlock(contextx.getStart(), contextx.getEnd(), pos, voxelShape, blockState); | ||
}, (contextx) -> null); | ||
|
||
if (returned != null) | ||
return returned; | ||
} | ||
|
||
return BlockView.raycast(context.getStart(), context.getEnd(), context, (contextx, pos) -> { | ||
BlockState blockState = blockView.getBlockState(pos); | ||
FluidState fluidState = blockView.getFluidState(pos); | ||
Vec3d vec3d = contextx.getStart(); | ||
Vec3d vec3d2 = contextx.getEnd(); | ||
VoxelShape voxelShape = contextx.getBlockShape(blockState, blockView, pos); | ||
BlockHitResult blockHitResult = blockView.raycastBlock(vec3d, vec3d2, pos, voxelShape, blockState); | ||
VoxelShape voxelShape2 = contextx.getFluidShape(fluidState, blockView, pos); | ||
BlockHitResult blockHitResult2 = voxelShape2.raycast(vec3d, vec3d2, pos); | ||
double d = blockHitResult == null ? Double.MAX_VALUE : contextx.getStart().squaredDistanceTo(blockHitResult.getPos()); | ||
double e = blockHitResult2 == null ? Double.MAX_VALUE : contextx.getStart().squaredDistanceTo(blockHitResult2.getPos()); | ||
return d <= e ? blockHitResult : blockHitResult2; | ||
}, contextx -> { | ||
Vec3d vec3d = contextx.getStart().subtract(contextx.getEnd()); | ||
return BlockHitResult.createMissed(contextx.getEnd(), Direction.getFacing(vec3d.x, vec3d.y, vec3d.z), new BlockPos(contextx.getEnd())); | ||
}); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/block/MixinBlockView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce) | ||
* | ||
* Copyright (c) 2016 - 2021 CCBlueX | ||
* | ||
* LiquidBounce is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiquidBounce is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.ccbluex.liquidbounce.injection.mixins.minecraft.block; | ||
|
||
import net.ccbluex.liquidbounce.common.TweakedMethods; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.fluid.FluidState; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.RaycastContext; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
@Mixin(BlockView.class) | ||
public interface MixinBlockView { | ||
|
||
@Shadow | ||
static <T, C> T raycast(Vec3d start, Vec3d end, C context, BiFunction<C, BlockPos, T> blockHitFactory, Function<C, T> missFactory) { | ||
return null; | ||
} | ||
|
||
@Shadow | ||
BlockState getBlockState(BlockPos pos); | ||
|
||
@Shadow @Nullable BlockHitResult raycastBlock(Vec3d start, Vec3d end, BlockPos pos, VoxelShape shape, BlockState state); | ||
|
||
@Shadow FluidState getFluidState(BlockPos pos); | ||
|
||
/** | ||
* @author superblaubeere27 | ||
*/ | ||
@Overwrite | ||
default BlockHitResult raycast(RaycastContext context) { | ||
return TweakedMethods.tweakedRaycast((BlockView) this, context); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleGhostHand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce) | ||
* | ||
* Copyright (c) 2016 - 2021 CCBlueX | ||
* | ||
* LiquidBounce is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiquidBounce is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.ccbluex.liquidbounce.features.module.modules.exploit | ||
|
||
import net.ccbluex.liquidbounce.features.module.Category | ||
import net.ccbluex.liquidbounce.features.module.Module | ||
import net.minecraft.block.Blocks | ||
|
||
object ModuleGhostHand : Module("GhostHand", Category.EXPLOIT) { | ||
|
||
val targetedBlocks by blocks("TargetedBlocks", hashSetOf(Blocks.CHEST, Blocks.ENDER_CHEST, Blocks.TRAPPED_CHEST)) | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleMobOwners.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce) | ||
* | ||
* Copyright (c) 2016 - 2021 CCBlueX | ||
* | ||
* LiquidBounce is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiquidBounce is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.ccbluex.liquidbounce.features.module.modules.render | ||
|
||
import net.ccbluex.liquidbounce.config.util.decode | ||
import net.ccbluex.liquidbounce.features.module.Category | ||
import net.ccbluex.liquidbounce.features.module.Module | ||
import net.ccbluex.liquidbounce.utils.io.HttpClient | ||
import net.minecraft.entity.Entity | ||
import net.minecraft.entity.passive.HorseBaseEntity | ||
import net.minecraft.entity.passive.TameableEntity | ||
import net.minecraft.entity.projectile.ProjectileEntity | ||
import net.minecraft.text.OrderedText | ||
import net.minecraft.text.Style | ||
import net.minecraft.util.Formatting | ||
import java.util.* | ||
import java.util.concurrent.ConcurrentHashMap | ||
import java.util.concurrent.Executors | ||
|
||
object ModuleMobOwners : Module("MobOwners", Category.RENDER) { | ||
|
||
val projectiles by boolean("Projectiles", false) | ||
|
||
val uuidNameCache = ConcurrentHashMap<UUID, OrderedText>() | ||
|
||
var asyncRequestExecutor = Executors.newSingleThreadExecutor() | ||
|
||
fun getOwnerInfoText(entity: Entity): OrderedText? { | ||
if (!this.enabled) | ||
return null | ||
|
||
val ownerId = when { | ||
entity is TameableEntity -> entity.ownerUuid | ||
entity is HorseBaseEntity -> entity.ownerUuid | ||
entity is ProjectileEntity && projectiles -> entity.ownerUuid | ||
else -> null | ||
} ?: return null | ||
|
||
return world.getPlayerByUuid(ownerId) | ||
?.let { OrderedText.styledForwardsVisitedString(it.entityName, Style.EMPTY) } | ||
?: getFromMojangApi(ownerId) | ||
} | ||
|
||
private fun getFromMojangApi(ownerId: UUID): OrderedText { | ||
return uuidNameCache.computeIfAbsent(ownerId) { | ||
this.asyncRequestExecutor.submit { | ||
try { | ||
class UsernameRecord(var name: String, var changedToAt: Int?) | ||
|
||
val response = decode<Array<UsernameRecord>>(HttpClient.get("https://api.mojang.com/user/profiles/${it.toString().replace("-", "")}/names")) | ||
|
||
val entityName = response.first { it.changedToAt == null }.name | ||
|
||
uuidNameCache[it] = OrderedText.styledForwardsVisitedString(entityName, Style.EMPTY) | ||
} catch (e: InterruptedException) { | ||
|
||
} catch (e: Exception) { | ||
uuidNameCache[it] = OrderedText.styledForwardsVisitedString("Failed to query Mojang API", Style.EMPTY.withItalic(true).withColor(Formatting.RED)) | ||
} | ||
} | ||
|
||
OrderedText.styledForwardsVisitedString("Loading", Style.EMPTY.withItalic(true)) | ||
} | ||
} | ||
|
||
override fun disable() { | ||
this.asyncRequestExecutor.shutdownNow() | ||
|
||
this.asyncRequestExecutor = Executors.newSingleThreadExecutor() | ||
} | ||
|
||
} |
Oops, something went wrong.