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
|
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates 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.
*
* NotEnoughUpdates 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 NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates.miscfeatures;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils;
import io.github.moulberry.notenoughupdates.overlays.MiningOverlay;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.SpecialColour;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.Map;
@NEUAutoSubscribe
public class MiningStuff {
private static BlockPos overlayLoc = null;
private static long titaniumNotifMillis = 0;
private static Minecraft mc;
public MiningStuff() {
mc = Minecraft.getMinecraft();
}
public static void processBlockChangePacket(S23PacketBlockChange packetIn) {
if (!NotEnoughUpdates.INSTANCE.config.mining.titaniumAlert) {
return;
}
IBlockState state = packetIn.getBlockState();
if (SBInfo.getInstance().getLocation() != null &&
SBInfo.getInstance().getLocation().startsWith("mining_") &&
state.getBlock() == Blocks.stone && state.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH) {
for (Map.Entry<String, Float> entry : MiningOverlay.commissionProgress.entrySet()) {
String s = entry.getKey();
if (s.contains("Titanium")) {
if (entry.getValue() == 1f) {
return;
}
BlockPos pos = packetIn.getBlockPosition();
IBlockState existingBlock = Minecraft.getMinecraft().theWorld.getBlockState(pos);
if (existingBlock == null) return;
if (existingBlock.getBlock() == Blocks.stone &&
existingBlock.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH)
return;
if (!checkIfAnyIsAir(getAttachedBlocks(pos)) &&
NotEnoughUpdates.INSTANCE.config.mining.titaniumAlertMustBeVisible)
return;
BlockPos player = Minecraft.getMinecraft().thePlayer.getPosition();
double distSq = pos.distanceSq(player);
if (distSq < 12 * 12) {
titaniumNotifMillis = System.currentTimeMillis();
}
return;
}
}
}
}
private static BlockPos[] getAttachedBlocks(BlockPos block) {
BlockPos[] blocks = new BlockPos[6];
blocks[0] = new BlockPos(block.getX() - 1, block.getY(), block.getZ());
blocks[1] = new BlockPos(block.getX() + 1, block.getY(), block.getZ());
blocks[2] = new BlockPos(block.getX(), block.getY() - 1, block.getZ());
blocks[3] = new BlockPos(block.getX(), block.getY() + 1, block.getZ());
blocks[4] = new BlockPos(block.getX(), block.getY(), block.getZ() - 1);
blocks[5] = new BlockPos(block.getX(), block.getY(), block.getZ() + 1);
return blocks;
}
private static boolean checkIfAnyIsAir(BlockPos[] blocks) {
for (BlockPos block : blocks) {
if (mc.theWorld.getBlockState(block).getBlock() instanceof BlockAir) {
return true;
}
}
return false;
}
@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent.Post event) {
if (!NotEnoughUpdates.INSTANCE.config.mining.titaniumAlert) {
return;
}
if (titaniumNotifMillis <= 0) return;
int delta = (int) (System.currentTimeMillis() - titaniumNotifMillis);
int notifLen = 5000;
int fadeLen = 500;
if (delta > 0 && delta < notifLen && event.type == RenderGameOverlayEvent.ElementType.ALL) {
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int width = scaledResolution.getScaledWidth();
int height = scaledResolution.getScaledHeight();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
GlStateManager.pushMatrix();
GlStateManager.translate((float) (width / 2), (float) (height / 2), 0.0F);
GlStateManager.scale(4.0F, 4.0F, 4.0F);
int colour1 = 0xcc;
int colour2 = 0xff;
double factor = (Math.sin(delta * 2 * Math.PI / 1000) + 1) / 2;
int colour = (int) (colour1 * factor + colour2 * (1 - factor));
int alpha = 255;
if (delta < fadeLen) {
alpha = delta * 255 / fadeLen;
} else if (delta > notifLen - fadeLen) {
alpha = (notifLen - delta) * 255 / fadeLen;
}
if (alpha > 10) {
TextRenderUtils.drawStringCenteredScaledMaxWidth(
"Titanium has spawned nearby!",
0, 0, true, width / 4 - 20, colour | (colour << 8) | (colour << 16) | (alpha << 24)
);
}
GlStateManager.popMatrix();
}
}
@SubscribeEvent
public void renderWorldLast(RenderWorldLastEvent event) {
if (overlayLoc == null) return;
Entity viewer = Minecraft.getMinecraft().getRenderViewEntity();
double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * event.partialTicks;
double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * event.partialTicks;
double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * event.partialTicks;
AxisAlignedBB bb = new AxisAlignedBB(
overlayLoc.getX() - viewerX,
overlayLoc.getY() - viewerY,
overlayLoc.getZ() - viewerZ,
overlayLoc.getX() + 1 - viewerX,
overlayLoc.getY() + 1 - viewerY,
overlayLoc.getZ() + 1 - viewerZ
).expand(0.01f, 0.01f, 0.01f);
GlStateManager.disableCull();
CustomItemEffects.drawFilledBoundingBox(bb, 1f, SpecialColour.special(0, 100, 0xff0000));
GlStateManager.enableCull();
GlStateManager.enableTexture2D();
}
@SubscribeEvent
public void onLoadWorld(WorldEvent.Load event) {
overlayLoc = null;
}
@SubscribeEvent
public void onChatReceived(ClientChatReceivedEvent event) {
if (!NotEnoughUpdates.INSTANCE.config.mining.puzzlerSolver) {
overlayLoc = null;
return;
}
if (event.message.getFormattedText().startsWith("\u00A7e[NPC] \u00A7dPuzzler") &&
event.message.getUnformattedText().contains(":")) {
String clean = Utils.cleanColour(event.message.getUnformattedText());
clean = clean.split(":")[1].trim();
BlockPos pos = new BlockPos(181, 195, 135);
for (int i = 0; i < clean.length(); i++) {
char c = clean.charAt(i);
if (c == '\u25C0') { //Left
pos = pos.add(1
|