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
|
/*
* 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.miscgui.util;
import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Random;
public class OrbDisplay {
private static final ResourceLocation TEXTURE = new ResourceLocation("notenoughupdates:custom_enchant_gui.png");
private static final int DEFAULT_COUNT = 30;
private final List<ExperienceOrb> experienceOrbList = new ArrayList<>();
public ExperienceOrb spawnExperienceOrb(Random random, Vector2f start, Vector2f target, int baseType) {
ExperienceOrb orb = new ExperienceOrb();
orb.position = new Vector2f(start);
orb.positionLast = new Vector2f(orb.position);
orb.velocity = new Vector2f(
random.nextFloat() * 20 - 10,
random.nextFloat() * 20 - 10
);
orb.target = new Vector2f(target);
orb.type = baseType;
orb.rotationDeg = random.nextInt(4) * 90;
float v = random.nextFloat();
if (v > 0.6) {
orb.type += 1;
}
if (v > 0.9) {
orb.type += 1;
}
experienceOrbList.add(orb);
return orb;
}
public void spawnExperienceOrbs(int startX, int startY, int targetX, int targetY, int baseType) {
spawnExperienceOrbs(new Random(),new Vector2f(startX, startY), new Vector2f(targetX, targetY), baseType, DEFAULT_COUNT);
}
public void spawnExperienceOrbs(Random random, Vector2f start, Vector2f target, int baseType, int count) {
for (int i = 0; i < count; i++) {
spawnExperienceOrb(random, start, target, baseType);
}
}
public void physicsTickOrbs() {
for (ListIterator<ExperienceOrb> it = experienceOrbList.listIterator(); it.hasNext(); ) {
ExperienceOrb orb = it.next();
Vector2f delta = Vector2f.sub(orb.target, orb.position, null);
float length = delta.length();
// Remove close Orbs
if (length < 8 && orb.velocity.lengthSquared() < 20) {
it.remove();
continue;
}
// Update velocity
Vector2f.add(orb.velocity, (Vector2f) delta.scale(2 / length), orb.velocity);
orb.velocity.scale(0.9F);
// Update position
orb.positionLast.set(orb.position);
Vector2f.add(orb.position, orb.velocity, orb.position);
}
}
public void renderOrbs(float partialTicks) {
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
GlStateManager.disableDepth();
for (ExperienceOrb orb : experienceOrbList) {
int orbX = Math.round(LerpUtils.lerp(orb.position.x, orb.positionLast.x, partialTicks));
int orbY = Math.round(LerpUtils.lerp(orb.position.y, orb.positionLast.y, partialTicks));
GlStateManager.pushMatrix();
GlStateManager.translate(orbX, orbY, 0);
GlStateManager.rotate(orb.rotationDeg, 0, 0, 1);
Vector2f delta = Vector2f.sub(orb.position, orb.target, null);
float length = delta.length();
float velocitySquared = orb.velocity.lengthSquared();
float opacity = (float) Math.sqrt(
Math.min(
1,
Math.min(2, Math.max(0.5F, length / 16))
* Math.min(2, Math.max(0.5F, velocitySquared / 40))
));
GlStateManager.color(1, 1, 1, opacity);
int orbU = (orb.type % 3) * 16;
int orbV = (orb.type / 3) * 16 + 217;
Utils.drawTexturedRect(
-8, -8, 16, 16,
orbU / 512f,
(orbU + 16) / 512f,
orbV / 512f,
(orbV + 16) / 512f,
GL11.GL_NEAREST
);
GlStateManager.popMatrix();
}
GlStateManager.enableDepth();
}
}
|