From c9c67c5e2d69be0a0c702b9f1b6b6e2c0660da21 Mon Sep 17 00:00:00 2001 From: valoeghese Date: Mon, 31 Aug 2020 22:58:49 +1200 Subject: [PATCH] dont register delegates --- .../java/tk/valoeghese/fc0/client/Client2fc.java | 2 +- .../tk/valoeghese/fc0/client/render/Textures.java | 2 +- .../tk/valoeghese/fc0/world/player/ItemType.java | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/tk/valoeghese/fc0/client/Client2fc.java b/src/main/java/tk/valoeghese/fc0/client/Client2fc.java index c1d7aca..7f17e23 100644 --- a/src/main/java/tk/valoeghese/fc0/client/Client2fc.java +++ b/src/main/java/tk/valoeghese/fc0/client/Client2fc.java @@ -204,7 +204,7 @@ private void initGameRendering() { uvRequests = name -> new Vec2i(Textures.ITEM_ATLAS_OBJ.imageLocationMap.get(name)); - for (ItemType item : ItemType.BY_ID) { + for (ItemType item : ItemType.ITEMS) { if (item != null) { item.requestUV(uvRequests); } diff --git a/src/main/java/tk/valoeghese/fc0/client/render/Textures.java b/src/main/java/tk/valoeghese/fc0/client/render/Textures.java index cecd162..8b39fbc 100644 --- a/src/main/java/tk/valoeghese/fc0/client/render/Textures.java +++ b/src/main/java/tk/valoeghese/fc0/client/render/Textures.java @@ -130,7 +130,7 @@ public static void loadGeneratedAtlases() { entries.add("./$break"); // key for tile end, item begin - for (ItemType item : ItemType.BY_ID) { + for (ItemType item : ItemType.ITEMS) { if (item != null) { item.requestUV(str -> { // dummy code to collect textures yet once more entries.add(str); diff --git a/src/main/java/tk/valoeghese/fc0/world/player/ItemType.java b/src/main/java/tk/valoeghese/fc0/world/player/ItemType.java index a965efa..4902051 100644 --- a/src/main/java/tk/valoeghese/fc0/world/player/ItemType.java +++ b/src/main/java/tk/valoeghese/fc0/world/player/ItemType.java @@ -2,12 +2,20 @@ import tk.valoeghese.fc0.util.maths.Vec2i; +import java.util.ArrayList; +import java.util.List; import java.util.function.Function; public class ItemType { public ItemType(String textureName, int id) { this.id = id; - BY_ID[id] = this; + + if (id != -1) { + BY_ID[id] = this; + } + + ITEMS.add(this); + this.textureName = textureName; } @@ -41,7 +49,9 @@ public String toString() { return this.translationKey; } + public static final List ITEMS = new ArrayList<>(); public static final ItemType[] BY_ID = new ItemType[128]; + // An ID of negative one symbolises a delegate item. + public static final ItemType TORCH = new ItemType("torch", -1).setName("torch"); public static final ItemType POMELO = new ItemType("pomelo", 0).setName("pomelo"); - public static final ItemType TORCH = new ItemType("torch", 1).setName("torch"); }