/
NewChunksHack.java
261 lines (218 loc) · 7.81 KB
/
NewChunksHack.java
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
* Copyright (c) 2014-2024 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 java.awt.Color;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.dimension.DimensionType;
import net.wurstclient.Category;
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.hacks.newchunks.NewChunksChunkRenderer;
import net.wurstclient.hacks.newchunks.NewChunksReasonsRenderer;
import net.wurstclient.hacks.newchunks.NewChunksRenderer;
import net.wurstclient.hacks.newchunks.NewChunksShowSetting;
import net.wurstclient.hacks.newchunks.NewChunksShowSetting.Show;
import net.wurstclient.hacks.newchunks.NewChunksStyleSetting;
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.BlockUtils;
import net.wurstclient.util.ChunkUtils;
import net.wurstclient.util.RegionPos;
import net.wurstclient.util.RenderUtils;
public final class NewChunksHack extends Hack
implements UpdateListener, RenderListener
{
private final NewChunksStyleSetting style = new NewChunksStyleSetting();
private final NewChunksShowSetting show = new NewChunksShowSetting();
private final CheckboxSetting showReasons = new CheckboxSetting(
"Show reasons",
"Highlights the block that caused each chunk to be marked as new/old.",
false);
private final CheckboxSetting showCounter =
new CheckboxSetting("Show counter",
"Shows the number of new/old chunks found so far.", false);
private final SliderSetting altitude =
new SliderSetting("Altitude", 0, -64, 320, 1, ValueDisplay.INTEGER);
private final SliderSetting drawDistance =
new SliderSetting("Draw distance", 32, 8, 64, 1, ValueDisplay.INTEGER);
private final SliderSetting opacity = new SliderSetting("Opacity", 0.75,
0.1, 1, 0.01, ValueDisplay.PERCENTAGE);
private final ColorSetting newChunksColor =
new ColorSetting("New chunks color", Color.RED);
private final ColorSetting oldChunksColor =
new ColorSetting("Old chunks color", Color.BLUE);
private final CheckboxSetting logChunks = new CheckboxSetting("Log chunks",
"Writes to the log file when a new/old chunk is found.", false);
private final Set<ChunkPos> newChunks =
Collections.synchronizedSet(new HashSet<>());
private final Set<ChunkPos> oldChunks =
Collections.synchronizedSet(new HashSet<>());
private final Set<ChunkPos> dontCheckAgain =
Collections.synchronizedSet(new HashSet<>());
private final Set<BlockPos> newChunkReasons =
Collections.synchronizedSet(new HashSet<>());
private final Set<BlockPos> oldChunkReasons =
Collections.synchronizedSet(new HashSet<>());
private final NewChunksRenderer renderer = new NewChunksRenderer(altitude,
opacity, newChunksColor, oldChunksColor);
private final NewChunksReasonsRenderer reasonsRenderer =
new NewChunksReasonsRenderer(drawDistance);
private RegionPos lastRegion;
private DimensionType lastDimension;
public NewChunksHack()
{
super("NewChunks");
setCategory(Category.RENDER);
addSetting(style);
addSetting(show);
addSetting(showReasons);
addSetting(showCounter);
addSetting(altitude);
addSetting(drawDistance);
addSetting(opacity);
addSetting(newChunksColor);
addSetting(oldChunksColor);
addSetting(logChunks);
}
@Override
protected void onEnable()
{
EVENTS.add(UpdateListener.class, this);
EVENTS.add(RenderListener.class, this);
reset();
}
private void reset()
{
oldChunks.clear();
newChunks.clear();
dontCheckAgain.clear();
oldChunkReasons.clear();
newChunkReasons.clear();
lastRegion = null;
lastDimension = MC.world.getDimension();
}
@Override
protected void onDisable()
{
EVENTS.remove(UpdateListener.class, this);
EVENTS.remove(RenderListener.class, this);
renderer.closeBuffers();
}
@Override
public String getRenderName()
{
if(!showCounter.isChecked())
return getName();
return String.format("%s [%d/%d]", getName(), newChunks.size(),
oldChunks.size());
}
@Override
public void onUpdate()
{
renderer.closeBuffers();
Show showSetting = show.getSelected();
int dd = drawDistance.getValueI();
NewChunksChunkRenderer chunkRenderer =
style.getSelected().getChunkRenderer();
if(showSetting.includesNew())
{
renderer.updateBuffer(0, chunkRenderer.buildBuffer(newChunks, dd));
if(showReasons.isChecked())
renderer.updateBuffer(1,
reasonsRenderer.buildBuffer(newChunkReasons));
}
if(showSetting.includesOld())
{
renderer.updateBuffer(2, chunkRenderer.buildBuffer(oldChunks, dd));
if(showReasons.isChecked())
renderer.updateBuffer(3,
reasonsRenderer.buildBuffer(oldChunkReasons));
}
}
public void afterLoadChunk(int x, int z)
{
if(!isEnabled())
return;
WorldChunk chunk = MC.world.getChunk(x, z);
new Thread(() -> checkLoadedChunk(chunk), "NewChunks " + chunk.getPos())
.start();
}
private void checkLoadedChunk(WorldChunk chunk)
{
ChunkPos chunkPos = chunk.getPos();
if(newChunks.contains(chunkPos) || oldChunks.contains(chunkPos)
|| dontCheckAgain.contains(chunkPos))
return;
int minX = chunkPos.getStartX();
int minY = chunk.getBottomY();
int minZ = chunkPos.getStartZ();
int maxX = chunkPos.getEndX();
int maxY = ChunkUtils.getHighestNonEmptySectionYOffset(chunk) + 16;
int maxZ = chunkPos.getEndZ();
for(int x = minX; x <= maxX; x++)
for(int y = minY; y <= maxY; y++)
for(int z = minZ; z <= maxZ; z++)
{
BlockPos pos = new BlockPos(x, y, z);
FluidState fluidState = chunk.getFluidState(pos);
if(fluidState.isEmpty() || fluidState.isStill())
continue;
// Liquid always generates still, the flowing happens later
// through block updates. Therefore any chunk that contains
// flowing liquids from the start should be an old chunk.
oldChunks.add(chunkPos);
oldChunkReasons.add(pos);
if(logChunks.isChecked())
System.out.println("old chunk at " + chunkPos);
return;
}
// If the whole loop ran through without finding anything, make sure it
// never runs again on that chunk, as that would be a huge waste of CPU
// time.
dontCheckAgain.add(chunkPos);
}
public void afterUpdateBlock(BlockPos pos)
{
if(!isEnabled())
return;
// Liquid starts flowing -> probably a new chunk
FluidState fluidState = BlockUtils.getState(pos).getFluidState();
if(fluidState.isEmpty() || fluidState.isStill())
return;
ChunkPos chunkPos = new ChunkPos(pos);
if(newChunks.contains(chunkPos) || oldChunks.contains(chunkPos))
return;
newChunks.add(chunkPos);
newChunkReasons.add(pos);
if(logChunks.isChecked())
System.out.println("new chunk at " + chunkPos);
}
@Override
public void onRender(MatrixStack matrixStack, float partialTicks)
{
if(MC.world.getDimension() != lastDimension)
reset();
RegionPos region = RenderUtils.getCameraRegion();
if(!region.equals(lastRegion))
{
onUpdate();
lastRegion = region;
}
renderer.render(matrixStack, partialTicks);
}
}