Skip to content

Commit 8182590

Browse files
authored
Treat Bytes in ProspectingTexture#map as UByte & switch to fastutil maps (GregTechCEu#2891)
1 parent 3003993 commit 8182590

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/main/java/gregtech/common/gui/widget/prospector/ProspectingTexture.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
import net.minecraftforge.fluids.FluidRegistry;
1515
import net.minecraftforge.fluids.FluidStack;
1616

17+
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
1718
import org.jetbrains.annotations.Nullable;
1819

1920
import java.awt.*;
2021
import java.awt.image.BufferedImage;
2122
import java.awt.image.WritableRaster;
22-
import java.util.HashMap;
23+
import java.util.Map;
2324

2425
public class ProspectingTexture extends AbstractTexture {
2526

@@ -29,8 +30,8 @@ public class ProspectingTexture extends AbstractTexture {
2930
private boolean darkMode;
3031
private int imageWidth = -1;
3132
private int imageHeight = -1;
32-
public final HashMap<Byte, String>[][] map;
33-
public static HashMap<Byte, String> emptyTag = new HashMap<>();
33+
public final Map<Byte, String>[][] map;
34+
public static Map<Byte, String> emptyTag = new Byte2ObjectOpenHashMap<>();
3435
private int playerXGui;
3536
private int playerYGui;
3637
private final ProspectorMode mode;
@@ -42,10 +43,10 @@ public ProspectingTexture(ProspectorMode mode, int radius, boolean darkMode) {
4243
this.mode = mode;
4344
if (this.mode == ProspectorMode.FLUID) {
4445
// noinspection unchecked
45-
map = new HashMap[(radius * 2 - 1)][(radius * 2 - 1)];
46+
map = new Byte2ObjectOpenHashMap[(radius * 2 - 1)][(radius * 2 - 1)];
4647
} else {
4748
// noinspection unchecked
48-
map = new HashMap[(radius * 2 - 1) * 16][(radius * 2 - 1) * 16];
49+
map = new Byte2ObjectOpenHashMap[(radius * 2 - 1) * 16][(radius * 2 - 1) * 16];
4950
}
5051
}
5152

@@ -102,7 +103,7 @@ private BufferedImage getImage() {
102103

103104
for (int i = 0; i < wh; i++) {
104105
for (int j = 0; j < wh; j++) {
105-
HashMap<Byte, String> data = this.map[this.mode == ProspectorMode.ORE ? i : i / 16][this.mode ==
106+
Map<Byte, String> data = this.map[this.mode == ProspectorMode.ORE ? i : i / 16][this.mode ==
106107
ProspectorMode.ORE ? j : j / 16];
107108
// draw bg
108109
image.setRGB(i, j, ((data == null) ^ darkMode) ? Color.darkGray.getRGB() : Color.WHITE.getRGB());

src/main/java/gregtech/common/gui/widget/prospector/widget/WidgetProspectingMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void drawInForeground(int mouseX, int mouseY) {
271271
if (ProspectingTexture.SELECTED_ALL.equals(texture.getSelected()) ||
272272
texture.getSelected().equals(dict)) {
273273
oreInfo.put(name, oreInfo.getOrDefault(name, 0) + 1);
274-
oreHeight.put(name, oreHeight.getOrDefault(name, 0) + height.intValue());
274+
oreHeight.put(name, oreHeight.getOrDefault(name, 0) + Byte.toUnsignedInt(height));
275275
if (oreInfo.get(name) > maxAmount[0]) {
276276
maxAmount[0] = oreInfo.get(name);
277277
MaterialStack m = OreDictUnifier.getMaterial(OreDictUnifier.get(dict));

0 commit comments

Comments
 (0)