forked from cev-api/Wurst7-CevAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobOwnersHack.java
More file actions
220 lines (192 loc) · 6.78 KB
/
Copy pathMobOwnersHack.java
File metadata and controls
220 lines (192 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Copyright (c) 2014-2026 Wurst-Imperium and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package net.wurstclient.hacks;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import java.awt.Color;
import java.util.UUID;
import net.minecraft.network.chat.Component;
import net.minecraft.client.gui.Font;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.animal.equine.AbstractHorse;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.RenderListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.CheckboxSetting;
import net.wurstclient.settings.ColorSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.OwnerResolver;
import net.wurstclient.util.EntityUtils;
import net.wurstclient.util.RenderUtils;
@SearchTags({"mob owners", "pet owners", "projectile owners"})
public final class MobOwnersHack extends Hack implements RenderListener
{
private final CheckboxSetting projectiles =
new CheckboxSetting("Projectiles", false);
private final ColorSetting color = new ColorSetting("Color",
"Color of projectile owner labels.", new Color(0x55FFFF));
private final SliderSetting labelScale =
new SliderSetting("Label scale", "Scale of the owner labels.", 1.0, 0.5,
2.0, 0.05, ValueDisplay.DECIMAL);
private final CheckboxSetting showUuidWhenUnknown = new CheckboxSetting(
"Show UUID when unknown",
"Shows the owner's shortened UUID when the player name is not known.",
true);
public MobOwnersHack()
{
super("MobOwners",
"Shows which player owns tamed mobs, horses, and optionally projectiles.",
false);
setCategory(Category.RENDER);
addSetting(projectiles);
addSetting(color);
addSetting(labelScale);
addSetting(showUuidWhenUnknown);
}
@Override
protected void onEnable()
{
EVENTS.add(RenderListener.class, this);
}
@Override
protected void onDisable()
{
EVENTS.remove(RenderListener.class, this);
}
public Component addOwnerInfo(Entity entity, Component original)
{
Component ownerNameTag = buildOwnerNameTag(entity, original);
return ownerNameTag == null ? original : ownerNameTag;
}
public boolean shouldForceMobNametag(Mob mob)
{
return buildOwnerNameTag(mob, null) != null;
}
private Component buildOwnerNameTag(Entity entity, Component original)
{
if(!isEnabled())
return null;
UUID owner = getOwnerUuid(entity);
if(owner == null)
return null;
String name = resolveOwnerName(owner);
if(name == null)
{
if(!showUuidWhenUnknown.isChecked())
return null;
String raw = owner.toString();
name = raw.substring(0, Math.min(8, raw.length()));
}
Component base = original == null ? entity.getName() : original;
return Component.literal(name + "'s ").append(base);
}
private UUID getOwnerUuid(Entity entity)
{
if(entity instanceof AbstractHorse horse)
return OwnerResolver.getOwnerUuid(horse, projectiles.isChecked());
return OwnerResolver.getOwnerUuid(entity, projectiles.isChecked());
}
private String resolveOwnerName(UUID owner)
{
String name = OwnerResolver.lookupPlayerName(owner);
return OwnerResolver.isResolvablePlayerName(name) ? name : null;
}
@Override
public void onRender(PoseStack matrixStack, float partialTicks)
{
if(MC.level == null || !projectiles.isChecked())
return;
int labelColor = color.getColorI();
float scale = (float)labelScale.getValue();
for(Entity entity : MC.level.entitiesForRendering())
{
if(!(entity instanceof Projectile projectile))
continue;
Entity owner = projectile.getOwner();
UUID ownerUuid = OwnerResolver.getOwnerUuid(projectile);
if(owner == MC.player || ownerUuid != null && MC.player != null
&& ownerUuid.equals(MC.player.getUUID()))
continue;
String label = getProjectileOwnerLabel(projectile, owner);
if(label == null)
continue;
AABB box = EntityUtils.getLerpedBox(entity, partialTicks);
Vec3 center = box.getCenter();
drawWorldLabel(matrixStack, label, center.x, box.maxY + 0.45,
center.z, labelColor, scale);
}
}
private String getProjectileOwnerLabel(Entity projectile, Entity owner)
{
UUID ownerUuid = OwnerResolver.getOwnerUuid(projectile);
if(ownerUuid != null)
{
String name = OwnerResolver.lookupPlayerName(ownerUuid);
if(OwnerResolver.isResolvablePlayerName(name))
return "Owner: " + name;
}
if(owner == null)
return showUuidWhenUnknown.isChecked() ? "Owner: Unknown" : null;
if(owner instanceof Player player)
return "Owner: " + player.getName().getString();
String name = owner.getName().getString();
if(name == null || name.isBlank())
name = owner.getType().toShortString();
return "Owner: " + name;
}
private void drawWorldLabel(PoseStack matrices, String text, double x,
double y, double z, int argb, float scale)
{
matrices.pushPose();
Vec3 cam = RenderUtils.getCameraPos();
Vec3 target = new Vec3(x, y, z);
Vec3 dir = target.subtract(cam);
double dist = dir.length();
double lx = x;
double ly = y;
double lz = z;
if(dist > 1.0)
{
double anchor = Math.min(dist, 12.0);
Vec3 anchored = cam.add(dir.scale(anchor / dist));
lx = anchored.x;
ly = anchored.y;
lz = anchored.z;
}
matrices.translate(lx - cam.x, ly - cam.y, lz - cam.z);
var camEntity = MC.getCameraEntity();
if(camEntity != null)
{
matrices.mulPose(Axis.YP.rotationDegrees(-camEntity.getYRot()));
matrices.mulPose(Axis.XP.rotationDegrees(camEntity.getXRot()));
}
matrices.mulPose(Axis.YP.rotationDegrees(180.0F));
float s = 0.025F * RenderUtils.getCappedWorldLabelScale(scale, dist);
matrices.scale(s, -s, s);
Font font = MC.font;
float w = font.width(text) / 2F;
int baseAlpha = (argb >>> 24) & 0xFF;
int bgAlpha =
(int)Math.round(MC.options.getBackgroundOpacity(0.25F) * baseAlpha);
int bg = bgAlpha << 24;
int strokeColor =
(Math.max(0, Math.min(255, baseAlpha)) << 24) | 0x000000;
var matrix = matrices.last().pose();
net.wurstclient.util.RenderUtils.drawOutlinedTextInBatch(font, text, -w,
0, argb, strokeColor, matrix, Font.DisplayMode.SEE_THROUGH, bg,
0xF000F0);
matrices.popPose();
}
}