Skip to content

Commit f870688

Browse files
committed
Refactors and a render fix.
1 parent da0607c commit f870688

File tree

9 files changed

+89
-36
lines changed

9 files changed

+89
-36
lines changed

src/main/java/net/foxdenstudio/sponge/foxcore/common/util/CacheMap.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,9 @@
3131

3232
public class CacheMap<K, V> extends HashMap<K, V> {
3333
final private BiFunction<Object, Map<K, V>, V> callback;
34-
final private boolean cache;
3534

3635
public CacheMap(BiFunction<Object, Map<K, V>, V> callback) {
3736
this.callback = callback;
38-
this.cache = false;
39-
}
40-
41-
public CacheMap(BiFunction<Object, Map<K, V>, V> callback, boolean cache) {
42-
this.callback = callback;
43-
this.cache = cache;
4437
}
4538

4639
@Override
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of FoxCore, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) gravityfox - https://gravityfox.net/
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
26+
package net.foxdenstudio.sponge.foxcore.common.util;
27+
28+
import java.util.Map;
29+
import java.util.WeakHashMap;
30+
import java.util.function.BiFunction;
31+
32+
public class WeakCacheMap<K, V> extends WeakHashMap<K, V> {
33+
final private BiFunction<Object, Map<K, V>, V> callback;
34+
35+
public WeakCacheMap(BiFunction<Object, Map<K, V>, V> callback) {
36+
this.callback = callback;
37+
}
38+
39+
@Override
40+
public V get(Object key) {
41+
if (containsKey(key)) {
42+
return super.get(key);
43+
} else {
44+
return callback.apply(key, this);
45+
}
46+
}
47+
}

src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/Highlight.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525

2626
package net.foxdenstudio.sponge.foxcore.mod.render;
2727

28+
import com.flowpowered.math.vector.Vector2i;
2829
import com.flowpowered.math.vector.Vector3f;
2930
import com.flowpowered.math.vector.Vector3i;
3031

3132
import static org.lwjgl.opengl.GL11.*;
3233

3334
public class Highlight implements IRenderable {
3435

35-
private static final double OFFSET = 0.005;
36+
private static final double OFFSET = 0.01;
3637
private static final int PERIOD = 2000;
3738
public transient double distance;
3839
boolean[][][] filled = new boolean[3][3][3];
@@ -58,22 +59,22 @@ public Highlight(Vector3i pos, Vector3f color, float phase) {
5859
this.phase = phase;
5960
}
6061

61-
public void render() {
62+
public void render(Vector2i offset) {
6263
final float alpha = (1f - ((System.currentTimeMillis()) % PERIOD) / (float) PERIOD + phase) % 1f;
6364
glColor4f(color.getX(), color.getY(), color.getZ(), alpha);
64-
drawBoxLines();
65+
drawBoxLines(offset);
6566
glColor4f(color.getX(), color.getY(), color.getZ(), alpha / 4 + 0.1f);
66-
drawBoxFaces();
67+
drawBoxFaces(offset);
6768
}
6869

69-
public void drawBoxFaces() {
70+
public void drawBoxFaces(Vector2i offset) {
7071

71-
final double x1 = pos.getX() - OFFSET;
72+
final double x1 = pos.getX() + offset.getX() - OFFSET;
7273
final double y1 = pos.getY() - OFFSET;
73-
final double z1 = pos.getZ() - OFFSET;
74-
final double x2 = pos.getX() + OFFSET + 1;
74+
final double z1 = pos.getZ() + offset.getY() - OFFSET;
75+
final double x2 = pos.getX() + offset.getX() + OFFSET + 1;
7576
final double y2 = pos.getY() + OFFSET + 1;
76-
final double z2 = pos.getZ() + OFFSET + 1;
77+
final double z2 = pos.getZ() + offset.getY() + OFFSET + 1;
7778

7879
glBegin(GL_QUADS);
7980
if (!filled[0][1][1]) {
@@ -121,13 +122,13 @@ public void drawBoxFaces() {
121122
glEnd();
122123
}
123124

124-
public void drawBoxLines() {
125-
final double x1 = pos.getX() - OFFSET;
125+
public void drawBoxLines(Vector2i offset) {
126+
final double x1 = pos.getX() + offset.getX() - OFFSET;
126127
final double y1 = pos.getY() - OFFSET;
127-
final double z1 = pos.getZ() - OFFSET;
128-
final double x2 = pos.getX() + OFFSET + 1;
128+
final double z1 = pos.getZ() + offset.getY() - OFFSET;
129+
final double x2 = pos.getX() + offset.getX() + OFFSET + 1;
129130
final double y2 = pos.getY() + OFFSET + 1;
130-
final double z2 = pos.getZ() + OFFSET + 1;
131+
final double z2 = pos.getZ() + offset.getY() + OFFSET + 1;
131132

132133
glEnable(GL_LINE_SMOOTH);
133134
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/HighlightList.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package net.foxdenstudio.sponge.foxcore.mod.render;
2727

28+
import com.flowpowered.math.vector.Vector2i;
2829
import net.minecraft.client.Minecraft;
2930

3031
import java.util.ArrayList;
@@ -42,7 +43,7 @@ public HighlightList(Minecraft mc) {
4243
}
4344

4445
@Override
45-
public void render() {
46+
public void render(Vector2i offset) {
4647
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT);
4748

4849
glDisable(GL_LIGHTING);
@@ -55,7 +56,7 @@ public void render() {
5556

5657
glLineWidth(2f);
5758
try {
58-
this.forEach(Highlight::render);
59+
this.forEach(highlight -> highlight.render(offset));
5960
} catch (ConcurrentModificationException ignored) {
6061
}
6162

src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/IRenderable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
package net.foxdenstudio.sponge.foxcore.mod.render;
2727

28+
import com.flowpowered.math.vector.Vector2i;
29+
2830
public interface IRenderable {
2931

30-
void render();
32+
void render(Vector2i offset);
3133

3234
}

src/main/java/net/foxdenstudio/sponge/foxcore/mod/render/RenderHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525

2626
package net.foxdenstudio.sponge.foxcore.mod.render;
2727

28+
import com.flowpowered.math.vector.Vector2i;
2829
import com.flowpowered.math.vector.Vector3f;
2930
import com.flowpowered.math.vector.Vector3i;
3031
import net.minecraft.client.Minecraft;
3132
import net.minecraft.client.entity.EntityPlayerSP;
3233
import net.minecraftforge.client.event.RenderWorldLastEvent;
3334
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
35+
import net.minecraftforge.fml.relauncher.Side;
36+
import net.minecraftforge.fml.relauncher.SideOnly;
3437

3538
import java.util.HashMap;
3639
import java.util.Iterator;
@@ -53,6 +56,7 @@ public RenderHandler(Minecraft mc) {
5356
list = new HighlightList(mc);
5457
}
5558

59+
@SideOnly(Side.CLIENT)
5660
@SubscribeEvent
5761
public void render(RenderWorldLastEvent event) {
5862

@@ -66,9 +70,10 @@ public void render(RenderWorldLastEvent event) {
6670

6771
glPushMatrix();
6872

69-
glTranslated(-playerX, -playerY, -playerZ);
73+
Vector2i offset = new Vector2i(-playerX, -playerZ);
7074

71-
list.render();
75+
glTranslated(-playerX - offset.getX(), -playerY, -playerZ - offset.getY());
76+
list.render(offset);
7277
glPopMatrix();
7378
}
7479

src/main/java/net/foxdenstudio/sponge/foxcore/plugin/FoxCoreMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private void registerPackets() {
194194

195195
private void registerWands() {
196196
FCWandRegistry registry = FCWandRegistry.getInstance();
197-
registry.registerBuilder(PositionWand.type, new PositionWand.Factory());
197+
registry.registerBuilder(PositionWand.TYPE, new PositionWand.Factory());
198198
registry.registerBuilder(CounterWand.type, new CounterWand.Factory());
199199
}
200200

src/main/java/net/foxdenstudio/sponge/foxcore/plugin/state/SelectionStateField.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ public boolean isEmpty() {
9090
public ISelection getSelection() {
9191
return currentSelection;
9292
}
93+
94+
public void setCurrentSelection(ISelection currentSelection) {
95+
this.currentSelection = currentSelection;
96+
}
9397
}

src/main/java/net/foxdenstudio/sponge/foxcore/plugin/wand/types/PositionWand.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
*/
3939
public class PositionWand implements IWand {
4040

41-
public static final String type = "position";
41+
public static final String TYPE = "position";
4242

43-
public static final DataQuery colorQuery = DataQuery.of("color");
44-
public static final DataQuery rainbowQuery = DataQuery.of("rainbow");
43+
public static final DataQuery COLOR_QUERY = DataQuery.of("color");
44+
public static final DataQuery RAINBOW_QUERY = DataQuery.of("rainbow");
4545

4646
private Position.Color color;
4747
private boolean rainbow;
@@ -134,7 +134,7 @@ private Text getColorText(){
134134

135135
@Override
136136
public String type() {
137-
return type;
137+
return TYPE;
138138
}
139139

140140
@Override
@@ -145,8 +145,8 @@ public int getContentVersion() {
145145
@Override
146146
public DataContainer toContainer() {
147147
return new MemoryDataContainer()
148-
.set(colorQuery, color.name())
149-
.set(rainbowQuery, rainbow);
148+
.set(COLOR_QUERY, color.name())
149+
.set(RAINBOW_QUERY, rainbow);
150150
}
151151

152152
public static class Factory implements IWandFactory {
@@ -197,14 +197,14 @@ public List<String> createSuggestions(String arguments, CommandSource source, @N
197197

198198
@Override
199199
public IWand build(DataView dataView) {
200-
if (dataView.contains(colorQuery) && dataView.contains(rainbowQuery))
201-
return new PositionWand(Position.Color.from(dataView.getString(colorQuery).orElse(null)), dataView.getBoolean(rainbowQuery).orElse(false));
200+
if (dataView.contains(COLOR_QUERY) && dataView.contains(RAINBOW_QUERY))
201+
return new PositionWand(Position.Color.from(dataView.getString(COLOR_QUERY).orElse(null)), dataView.getBoolean(RAINBOW_QUERY).orElse(false));
202202
else return new PositionWand();
203203
}
204204

205205
@Override
206206
public String type() {
207-
return type;
207+
return TYPE;
208208
}
209209

210210
@Override

0 commit comments

Comments
 (0)