Skip to content

Commit

Permalink
Added mc_tweak clientEntityTargetingSelectAll
Browse files Browse the repository at this point in the history
resolved #56
  • Loading branch information
Fallen-Breath committed Mar 10, 2024
1 parent 6aee682 commit b105915
Show file tree
Hide file tree
Showing 13 changed files with 535 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/document-en_us.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,31 @@ Modify the maximum number of history messages stored in the chat hud
- Where's My Chat History (`wmch`)


### clientEntityTargetingSelectAll

Make the following client-side entity targeting stuffs being able to select all types of entities:

1. F3 + I entity data querying

2. Client-side command suggestion with target entity UUID

3. Mouse middle-click item picking. Supports picking items, xp orbs and falling blocks

Example use cases:

1. Get a /summon command for an item entity (F3 + I)

2. Enter /kill and tab-suggested a projectile entity (UUID suggestion)

3. Pick the item stack from the item entity to your inventory (pick entity)

Notes: In vanilla, client can only select collide-able and non-spectator entities

- Category: MC Tweaks
- Type: hotkey togglable boolean (Generic)
- Default value: *no hotkey*, `false`


### connectionSimulatedDelay

Client network delay simulator. Enabled when the value is greater than 0
Expand Down
25 changes: 25 additions & 0 deletions docs/document-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,31 @@ schematicBlockPlacement的严格模式
- Where's My Chat History (`wmch`)


### 客户端实体目标选择所有实体 (clientEntityTargetingSelectAll)

令下述客户端实体选择的功能可以选中所有类型的实体:

1. F3 + I 实体数据查询

2. 客户端指令补全中的实体UUID选项

3. 鼠标中键物品提取。支持提取物品实体、经验球实体和重力方块实体

用法举例:

1. 获取一个物品实体对应的/summon指令 (F3 + I)

2. 输入/kill然后tab补全面前的投掷物实体(UUID补全)

3. 把一个物品实体用鼠标中间拎进物品栏 (实体物品提取)

注:原版环境下,只能选中有碰撞箱且非旁观者的实体

- 分类: MC修改
- 类型: 带热键布尔值 (通用)
- 默认值: *无快捷键*, `false`


### 网络连接延迟模拟 (connectionSimulatedDelay)

客户端网络延迟模拟器,于给定值大于0时启用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ public class TweakerMoreConfigs
)
public static final TweakerMoreConfigInteger CHAT_MESSAGE_LIMIT = newConfigInteger("chatMessageLimit", 100, 100, 10000);

@Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigBooleanHotkeyed CLIENT_ENTITY_TARGETING_SUPPORT_ALL = newConfigBooleanHotkeyed("clientEntityTargetingSelectAll");

@Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigInteger CONNECTION_SIMULATED_DELAY = newConfigInteger("connectionSimulatedDelay", 0, 0, 15_000);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.impl.mc_tweaks.clientEntityTargetingSelectAll;

import net.minecraft.block.Block;
import net.minecraft.entity.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.jetbrains.annotations.Nullable;

public class EntityItemPickHelper
{
@Nullable
public static ItemStack pickItem(Entity entity)
{
if (entity instanceof ItemEntity)
{
return ((ItemEntity)entity).getStack().copy();
}
else if (entity instanceof ExperienceOrbEntity)
{
return new ItemStack(Items.EXPERIENCE_BOTTLE);
}
else if (entity instanceof FallingBlockEntity)
{
Block block = ((FallingBlockEntity)entity).getBlockState().getBlock();
ItemStack itemStack = new ItemStack(block);
return itemStack.isEmpty() ? null : itemStack;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.impl.mc_tweaks.clientEntityTargetingSelectAll;

import net.minecraft.util.hit.EntityHitResult;
import org.jetbrains.annotations.Nullable;

public interface MinecraftClientWithExtendedTargetEntity
{
@Nullable
EntityHitResult getExtendedEntityHitResult$TKM();

void setExtendedEntityHitResult$TKM(@Nullable EntityHitResult entityHitResult);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.clientEntityTargetingSelectAll;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import me.fallenbreath.tweakermore.impl.mc_tweaks.clientEntityTargetingSelectAll.MinecraftClientWithExtendedTargetEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
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;

@Mixin(ClientCommandSource.class)
public abstract class ClientCommandSourceMixin
{
@Shadow @Final private MinecraftClient client;

@ModifyExpressionValue(
method = "getEntitySuggestions",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;"
)
)
private HitResult clientEntityTargetingSelectAll_hackUuidSuggestion(HitResult crosshairTarget)
{
if (TweakerMoreConfigs.CLIENT_ENTITY_TARGETING_SUPPORT_ALL.getBooleanValue())
{
EntityHitResult entityHitResult = ((MinecraftClientWithExtendedTargetEntity)this.client).getExtendedEntityHitResult$TKM();
if (entityHitResult != null)
{
crosshairTarget = entityHitResult;
}
}
return crosshairTarget;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.clientEntityTargetingSelectAll;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import me.fallenbreath.tweakermore.impl.mc_tweaks.clientEntityTargetingSelectAll.MinecraftClientWithExtendedTargetEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
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 java.util.function.Predicate;

@Mixin(GameRenderer.class)
public abstract class GameRendererMixin
{
@Shadow @Final private MinecraftClient client;

@WrapOperation(
method = "updateTargetedEntity",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/ProjectileUtil;rayTrace(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;D)Lnet/minecraft/util/hit/EntityHitResult;"
)
)
private @Nullable EntityHitResult clientEntityTargetingSelectAll_makeExtendedTarget(Entity entity, Vec3d vecStart, Vec3d vecEnd, Box box, Predicate<Entity> predicate, double reach, Operation<EntityHitResult> original)
{
MinecraftClientWithExtendedTargetEntity access = (MinecraftClientWithExtendedTargetEntity)this.client;
if (TweakerMoreConfigs.CLIENT_ENTITY_TARGETING_SUPPORT_ALL.getBooleanValue())
{
access.setExtendedEntityHitResult$TKM(original.call(entity, vecStart, vecEnd, box, (Predicate<Entity>)e -> true, reach));
}
else
{
access.setExtendedEntityHitResult$TKM(null);
}
return original.call(entity, vecStart, vecEnd, box, predicate, reach);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.clientEntityTargetingSelectAll;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import me.fallenbreath.tweakermore.impl.mc_tweaks.clientEntityTargetingSelectAll.MinecraftClientWithExtendedTargetEntity;
import net.minecraft.client.Keyboard;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
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;

@Mixin(Keyboard.class)
public abstract class KeyboardMixin
{
@Shadow @Final private MinecraftClient client;

@ModifyExpressionValue(
method = "copyLookAt",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;"
)
)
private HitResult clientEntityTargetingSelectAll_hackF3I(HitResult crosshairTarget)
{
if (TweakerMoreConfigs.CLIENT_ENTITY_TARGETING_SUPPORT_ALL.getBooleanValue())
{
EntityHitResult entityHitResult = ((MinecraftClientWithExtendedTargetEntity)this.client).getExtendedEntityHitResult$TKM();
if (entityHitResult != null)
{
crosshairTarget = entityHitResult;
}
}
return crosshairTarget;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.clientEntityTargetingSelectAll;

import me.fallenbreath.tweakermore.impl.mc_tweaks.clientEntityTargetingSelectAll.MinecraftClientWithExtendedTargetEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.EntityHitResult;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(MinecraftClient.class)
public abstract class MinecraftClient_extendedTargetMixin implements MinecraftClientWithExtendedTargetEntity
{
@Unique
private EntityHitResult extendedEntityHitResult = null;

@Nullable
@Override
public EntityHitResult getExtendedEntityHitResult$TKM()
{
return this.extendedEntityHitResult;
}

@Override
public void setExtendedEntityHitResult$TKM(@Nullable EntityHitResult entityHitResult)
{
this.extendedEntityHitResult = entityHitResult;
}
}
Loading

0 comments on commit b105915

Please sign in to comment.