From 3ed43eae4f0e8d32bc46ae9d2234e5e70065c764 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 21:25:02 +0700
Subject: [PATCH 01/10] Support for attachable item with custom model.
---
.../resourcepack/AttachableDefinitions.java | 55 +++++++
.../model/resourcepack/ModelDefinitions.java | 16 +-
.../protocol/rewriter/ItemRewriter.java | 24 ++-
.../rewriter/ResourcePackRewriter.java | 6 +
.../CustomAttachableResourceRewriter.java | 138 ++++++++++++++++++
.../CustomEntityResourceRewriter.java | 2 +-
.../storage/ResourcePacksStorage.java | 11 ++
7 files changed, 237 insertions(+), 15 deletions(-)
create mode 100644 src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
create mode 100644 src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
new file mode 100644
index 0000000..03c7f46
--- /dev/null
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
@@ -0,0 +1,55 @@
+/*
+ * This file is part of ViaBedrock - https://github.com/RaphiMC/ViaBedrock
+ * Copyright (C) 2023-2024 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viabedrock.api.model.resourcepack;
+
+import com.viaversion.viaversion.util.Key;
+import net.raphimc.viabedrock.ViaBedrock;
+import net.raphimc.viabedrock.protocol.storage.ResourcePacksStorage;
+import org.oryxel.cube.model.bedrock.data.BedrockAttachableData;
+import org.oryxel.cube.parser.bedrock.data.BedrockAttachableSerializer;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+
+public class AttachableDefinitions {
+
+ private final Map attachableDefinitions = new HashMap<>();
+
+ public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
+ for (ResourcePack pack : resourcePacksStorage.getPackStackBottomToTop()) {
+ for (String attachablePath : pack.content().getFilesDeep("attachables/", ".json")) {
+ try {
+ final BedrockAttachableData attachableData = BedrockAttachableSerializer.deserialize(pack.content().getString(attachablePath));
+ final String identifier = Key.namespaced(attachableData.identifier());
+ this.attachableDefinitions.put(identifier, new AttachableDefinitions.AttachableDefinition(identifier, attachableData));
+ } catch (Throwable e) {
+ ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Failed to parse attachable definition " + attachablePath + " in pack " + pack.packId(), e);
+ }
+ }
+ }
+ }
+
+ public Map attachableDefinitions() {
+ return attachableDefinitions;
+ }
+
+ public record AttachableDefinition(String identifier, BedrockAttachableData attachableData) {
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
index e29a7db..c8381d7 100644
--- a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
@@ -29,15 +29,17 @@
public class ModelDefinitions {
- private final Map entityModels = new HashMap<>();
+ private final Map models = new HashMap<>();
public ModelDefinitions(final ResourcePacksStorage resourcePacksStorage) {
for (ResourcePack pack : resourcePacksStorage.getPackStackBottomToTop()) {
for (String modelPath : pack.content().getFilesDeep("models/", ".json")) {
try {
for (BedrockGeometry bedrockGeometry : BedrockGeometrySerializer.deserialize(pack.content().getString(modelPath))) {
- if (modelPath.startsWith("models/entity/")) {
- this.entityModels.put(bedrockGeometry.identifier(), bedrockGeometry);
+ // Attachable can be in models/entity/ for some reason, even tho it has it own folder for attachable definitions
+ // Just check for models that is not blocks.
+ if (!modelPath.startsWith("models/blocks/")) {
+ this.models.put(bedrockGeometry.identifier(), bedrockGeometry);
}
}
} catch (Throwable e) {
@@ -47,12 +49,12 @@ public ModelDefinitions(final ResourcePacksStorage resourcePacksStorage) {
}
}
- public BedrockGeometry getEntityModel(final String name) {
- return this.entityModels.get(name);
+ public BedrockGeometry getModel(final String name) {
+ return this.models.get(name);
}
- public Map entityModels() {
- return Collections.unmodifiableMap(this.entityModels);
+ public Map models() {
+ return Collections.unmodifiableMap(this.models);
}
}
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
index 739543d..d9c0011 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
@@ -31,6 +31,7 @@
import com.viaversion.viaversion.util.Key;
import net.raphimc.viabedrock.ViaBedrock;
import net.raphimc.viabedrock.api.model.BlockState;
+import net.raphimc.viabedrock.api.model.resourcepack.AttachableDefinitions;
import net.raphimc.viabedrock.api.model.resourcepack.ItemDefinitions;
import net.raphimc.viabedrock.api.util.TextUtil;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
@@ -38,6 +39,7 @@
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
import net.raphimc.viabedrock.protocol.model.BedrockItem;
import net.raphimc.viabedrock.protocol.model.ItemEntry;
+import net.raphimc.viabedrock.protocol.rewriter.resourcepack.CustomAttachableResourceRewriter;
import net.raphimc.viabedrock.protocol.rewriter.resourcepack.CustomItemTextureResourceRewriter;
import net.raphimc.viabedrock.protocol.storage.ResourcePacksStorage;
import net.raphimc.viabedrock.protocol.types.BedrockTypes;
@@ -147,16 +149,24 @@ public Item javaItem(final BedrockItem bedrockItem) {
} else {
data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt(resourcePacksStorage.getTexts().get("item." + Key.stripMinecraftNamespace(identifier) + ".name")));
}
- if (itemDefinition.iconComponent() != null && resourcePacksStorage.isLoadedOnJavaClient()) {
+ }
+
+ if (!resourcePacksStorage.isLoadedOnJavaClient()) {
+ data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
+ javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
+ } else {
+ if (resourcePacksStorage.getAttachableData().containsKey(identifier)) {
+ int javaItemModel = resourcePacksStorage.getAttachableData().get(identifier);
+ data.set(StructuredDataKey.CUSTOM_MODEL_DATA, javaItemModel);
+ javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomAttachableResourceRewriter.ITEM)), bedrockItem.amount(), data);
+ } else if (itemDefinition != null && itemDefinition.iconComponent() != null) {
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomItemTextureResourceRewriter.getCustomModelData(itemDefinition.iconComponent()));
+ javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else {
- data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
+ ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Missing bedrock -> java item mapping for " + identifier);
+ data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt("§cMissing item: " + identifier));
+ javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get("minecraft:paper"), bedrockItem.amount(), data);
}
- javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
- } else {
- ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Missing bedrock -> java item mapping for " + identifier);
- data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt("§cMissing item: " + identifier));
- javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get("minecraft:paper"), bedrockItem.amount(), data);
}
}
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java
index 32320df..7b04c34 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java
@@ -20,11 +20,16 @@
import com.viaversion.viaversion.libs.gson.JsonObject;
import net.raphimc.viabedrock.api.model.resourcepack.ResourcePack;
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
+import net.raphimc.viabedrock.protocol.rewriter.resourcepack.CustomAttachableResourceRewriter;
import net.raphimc.viabedrock.protocol.rewriter.resourcepack.CustomEntityResourceRewriter;
import net.raphimc.viabedrock.protocol.rewriter.resourcepack.CustomItemTextureResourceRewriter;
import net.raphimc.viabedrock.protocol.rewriter.resourcepack.GlyphSheetResourceRewriter;
import net.raphimc.viabedrock.protocol.storage.ResourcePacksStorage;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
public class ResourcePackRewriter {
public static ResourcePack.Content bedrockToJava(final ResourcePacksStorage resourcePacksStorage) {
@@ -32,6 +37,7 @@ public static ResourcePack.Content bedrockToJava(final ResourcePacksStorage reso
GlyphSheetResourceRewriter.apply(resourcePacksStorage, javaContent);
CustomItemTextureResourceRewriter.apply(resourcePacksStorage, javaContent);
+ CustomAttachableResourceRewriter.apply(resourcePacksStorage, javaContent);
CustomEntityResourceRewriter.apply(resourcePacksStorage, javaContent);
javaContent.putJson("pack.mcmeta", createPackManifest());
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
new file mode 100644
index 0000000..61abcfc
--- /dev/null
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
@@ -0,0 +1,138 @@
+/*
+ * This file is part of ViaBedrock - https://github.com/RaphiMC/ViaBedrock
+ * Copyright (C) 2023-2024 RK_01/RaphiMC and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.raphimc.viabedrock.protocol.rewriter.resourcepack;
+
+import com.google.common.collect.Lists;
+import com.viaversion.viaversion.libs.gson.JsonArray;
+import com.viaversion.viaversion.libs.gson.JsonObject;
+import com.viaversion.viaversion.util.GsonUtil;
+import net.raphimc.viabedrock.api.model.resourcepack.AttachableDefinitions;
+import net.raphimc.viabedrock.api.model.resourcepack.ResourcePack;
+import net.raphimc.viabedrock.api.util.StringUtil;
+import net.raphimc.viabedrock.protocol.storage.ResourcePacksStorage;
+import org.oryxel.cube.converter.FormatConverter;
+import org.oryxel.cube.model.bedrock.BedrockGeometry;
+import org.oryxel.cube.model.java.ItemModelData;
+import org.oryxel.cube.parser.java.JavaModelSerializer;
+
+import java.awt.image.BufferedImage;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class CustomAttachableResourceRewriter {
+
+ public static final String ITEM = "leather";
+
+ public static void apply(final ResourcePacksStorage resourcePacksStorage, final ResourcePack.Content javaContent) {
+ final Map overridesMap = new TreeMap<>();
+
+ for (Map.Entry entry : resourcePacksStorage.getAttachable().attachableDefinitions().entrySet()) {
+ for (String bedrockPath : entry.getValue().attachableData().textures().values()) {
+ final String javaPath = "attachable_texture/" + StringUtil.makeIdentifierValueSafe(bedrockPath.replace("textures/", ""));
+ for (ResourcePack pack : resourcePacksStorage.getPackStackTopToBottom()) {
+ final ResourcePack.Content bedrockContent = pack.content();
+ final BufferedImage texture = bedrockContent.getShortnameImage(bedrockPath);
+ if (texture == null) continue;
+
+ javaContent.putImage("assets/viabedrock/textures/item/" + javaPath + ".png", texture);
+ break;
+ }
+ }
+
+ final AttachableDefinitions.AttachableDefinition attachableDefinition = entry.getValue();
+ for (Map.Entry modelEntry : attachableDefinition.attachableData().geometries().entrySet()) {
+ final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().models().get(modelEntry.getValue());
+ if (bedrockGeometry == null) continue;
+ if (!attachableDefinition.attachableData().textures().containsKey(modelEntry.getKey())) continue;
+
+ final String javaTexturePath = "attachable_texture/" + StringUtil.makeIdentifierValueSafe(
+ attachableDefinition.attachableData().textures().get(modelEntry.getKey()).replace("textures/", ""));
+
+ final List cubeConverterItemModels = Lists.newArrayList(FormatConverter.bedrockToJava("viabedrock:item/" +
+ javaTexturePath, bedrockGeometry));
+
+ // It doesn't matter even if there is multiple models, it's item so only 1 model is supported.
+ if (cubeConverterItemModels.size() < 1) continue;
+ ItemModelData model = cubeConverterItemModels.get(0);
+ if (model == null) continue;
+
+ String json = JavaModelSerializer.serialize(model).toString();
+ if (json == null || json.isEmpty()) continue;
+ JsonObject object = GsonUtil.getGson().fromJson(json.trim(), JsonObject.class);
+
+ // Scaling up the model...
+ JsonObject display = new JsonObject();
+ JsonArray scaling = new JsonArray();
+ scaling.add(model.scale());
+ scaling.add(model.scale());
+ scaling.add(model.scale());
+
+ JsonObject value = new JsonObject();
+ value.add("scale", scaling);
+
+ display.add("firstperson_righthand", value);
+ display.add("firstperson_lefthand", value);
+ display.add("thirdperson_righthand", value);
+ display.add("thirdperson_lefthand", value);
+ display.add("head", value);
+ display.add("gui", value);
+ display.add("ground", value);
+ display.add("fixed", value);
+
+ object.add("display", display);
+
+ final String key = "attachable_" + entry.getKey() + "_" + modelEntry.getKey();
+ final String javaModelName = StringUtil.makeIdentifierValueSafe(key);
+
+ javaContent.putString("assets/viabedrock/models/attachable/" + javaModelName + ".json", object.toString());
+
+ final int javaModelData = getCustomModelData(key);
+ final JsonObject override = new JsonObject();
+ override.addProperty("model", "viabedrock:attachable/" + javaModelName);
+ final JsonObject predicate = new JsonObject();
+ predicate.addProperty("custom_model_data", javaModelData);
+ override.add("predicate", predicate);
+
+ if (overridesMap.put(javaModelData, override) != null) {
+ throw new IllegalStateException("Duplicate custom model data: " + override);
+ } else {
+ resourcePacksStorage.getAttachableData().put(entry.getKey(), javaModelData);
+ }
+ }
+ }
+
+ if (!overridesMap.isEmpty()) {
+ final JsonArray overrides = new JsonArray();
+ overridesMap.values().forEach(overrides::add);
+
+ final JsonObject attachableDefinition = new JsonObject();
+ attachableDefinition.addProperty("parent", "minecraft:item/generated");
+ attachableDefinition.add("overrides", overrides);
+ final JsonObject layer0 = new JsonObject();
+ layer0.addProperty("layer0", "minecraft:item/" + ITEM);
+ attachableDefinition.add("textures", layer0);
+ javaContent.putJson("assets/minecraft/models/item/" + ITEM + ".json", attachableDefinition);
+ }
+ }
+
+ public static int getCustomModelData(final String iconName) {
+ return Math.abs(iconName.hashCode() + 1); // 0 is used for the default model
+ }
+
+}
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java
index 48b1b76..f626f5c 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java
@@ -56,7 +56,7 @@ public static void apply(final ResourcePacksStorage resourcePacksStorage, final
final EntityDefinitions.EntityDefinition entityDefinition = entityEntry.getValue();
for (Map.Entry modelEntry : entityDefinition.entityData().geometries().entrySet()) {
- final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().entityModels().get(modelEntry.getValue());
+ final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().models().get(modelEntry.getValue());
if (bedrockGeometry == null) continue;
if (!entityDefinition.entityData().textures().containsKey(modelEntry.getKey())) continue;
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
index 46ceff5..9a4fd4d 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
@@ -48,10 +48,12 @@ public class ResourcePacksStorage extends StoredObject {
private boolean javaClientWaitingForPack;
private boolean loadedOnJavaClient;
private final Map converterData = new HashMap<>();
+ private final Map attachableData = new HashMap<>();
private TextDefinitions texts;
private BlockDefinitions blocks;
private ItemDefinitions items;
+ private AttachableDefinitions attachable;
private TextureDefinitions textures;
private SoundDefinitions sounds;
private ParticleDefinitions particles;
@@ -149,6 +151,7 @@ public void setPackStack(final UUID[] resourcePackStack, final UUID[] behaviourP
this.texts = new TextDefinitions(this);
this.blocks = new BlockDefinitions(this);
this.items = new ItemDefinitions(this);
+ this.attachable = new AttachableDefinitions(this);
this.textures = new TextureDefinitions(this);
this.sounds = new SoundDefinitions(this);
this.particles = new ParticleDefinitions(this);
@@ -185,6 +188,10 @@ public Map getConverterData() {
return this.converterData;
}
+ public Map getAttachableData() {
+ return attachableData;
+ }
+
public boolean hasFinishedLoading() {
return this.texts != null;
}
@@ -201,6 +208,10 @@ public ItemDefinitions getItems() {
return this.items;
}
+ public AttachableDefinitions getAttachable() {
+ return attachable;
+ }
+
public TextureDefinitions getTextures() {
return this.textures;
}
From fb8f32413ba817bd25f0b28b6ff690a16bc72bc0 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:12:37 +0700
Subject: [PATCH 02/10] Revert some changes.
---
.../viabedrock/api/model/resourcepack/ModelDefinitions.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
index c8381d7..c04db1c 100644
--- a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
@@ -36,9 +36,7 @@ public ModelDefinitions(final ResourcePacksStorage resourcePacksStorage) {
for (String modelPath : pack.content().getFilesDeep("models/", ".json")) {
try {
for (BedrockGeometry bedrockGeometry : BedrockGeometrySerializer.deserialize(pack.content().getString(modelPath))) {
- // Attachable can be in models/entity/ for some reason, even tho it has it own folder for attachable definitions
- // Just check for models that is not blocks.
- if (!modelPath.startsWith("models/blocks/")) {
+ if (modelPath.startsWith("models/entity/")) {
this.models.put(bedrockGeometry.identifier(), bedrockGeometry);
}
}
From 9589912cb7417a7ab97225a7db6df4bebe8aa952 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:16:06 +0700
Subject: [PATCH 03/10] Revert some changes.
---
.../api/model/resourcepack/ModelDefinitions.java | 14 +++++++-------
.../CustomAttachableResourceRewriter.java | 2 +-
.../resourcepack/CustomEntityResourceRewriter.java | 2 +-
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
index c04db1c..436b4fa 100644
--- a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/ModelDefinitions.java
@@ -29,7 +29,7 @@
public class ModelDefinitions {
- private final Map models = new HashMap<>();
+ private final Map entityModels = new HashMap<>();
public ModelDefinitions(final ResourcePacksStorage resourcePacksStorage) {
for (ResourcePack pack : resourcePacksStorage.getPackStackBottomToTop()) {
@@ -37,7 +37,7 @@ public ModelDefinitions(final ResourcePacksStorage resourcePacksStorage) {
try {
for (BedrockGeometry bedrockGeometry : BedrockGeometrySerializer.deserialize(pack.content().getString(modelPath))) {
if (modelPath.startsWith("models/entity/")) {
- this.models.put(bedrockGeometry.identifier(), bedrockGeometry);
+ this.entityModels.put(bedrockGeometry.identifier(), bedrockGeometry);
}
}
} catch (Throwable e) {
@@ -47,12 +47,12 @@ public ModelDefinitions(final ResourcePacksStorage resourcePacksStorage) {
}
}
- public BedrockGeometry getModel(final String name) {
- return this.models.get(name);
+ public BedrockGeometry getEntityModel(final String name) {
+ return this.entityModels.get(name);
}
- public Map models() {
- return Collections.unmodifiableMap(this.models);
+ public Map entityModels() {
+ return Collections.unmodifiableMap(this.entityModels);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
index 61abcfc..b4e0fb7 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
@@ -57,7 +57,7 @@ public static void apply(final ResourcePacksStorage resourcePacksStorage, final
final AttachableDefinitions.AttachableDefinition attachableDefinition = entry.getValue();
for (Map.Entry modelEntry : attachableDefinition.attachableData().geometries().entrySet()) {
- final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().models().get(modelEntry.getValue());
+ final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().entityModels().get(modelEntry.getValue());
if (bedrockGeometry == null) continue;
if (!attachableDefinition.attachableData().textures().containsKey(modelEntry.getKey())) continue;
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java
index f626f5c..48b1b76 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomEntityResourceRewriter.java
@@ -56,7 +56,7 @@ public static void apply(final ResourcePacksStorage resourcePacksStorage, final
final EntityDefinitions.EntityDefinition entityDefinition = entityEntry.getValue();
for (Map.Entry modelEntry : entityDefinition.entityData().geometries().entrySet()) {
- final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().models().get(modelEntry.getValue());
+ final BedrockGeometry bedrockGeometry = resourcePacksStorage.getModels().entityModels().get(modelEntry.getValue());
if (bedrockGeometry == null) continue;
if (!entityDefinition.entityData().textures().containsKey(modelEntry.getKey())) continue;
From af09546c1cdcfea3c0b2def6ea64132093de586f Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:22:56 +0700
Subject: [PATCH 04/10] Changes.
---
.../api/model/resourcepack/AttachableDefinitions.java | 9 +++++----
.../viabedrock/protocol/rewriter/ItemRewriter.java | 6 +++---
.../resourcepack/CustomAttachableResourceRewriter.java | 6 ++----
.../protocol/storage/ResourcePacksStorage.java | 5 -----
4 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
index 03c7f46..8ba5555 100644
--- a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
@@ -23,13 +23,14 @@
import org.oryxel.cube.model.bedrock.data.BedrockAttachableData;
import org.oryxel.cube.parser.bedrock.data.BedrockAttachableSerializer;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
public class AttachableDefinitions {
- private final Map attachableDefinitions = new HashMap<>();
+ private final Map attachableDefinitions = new HashMap<>();
public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
for (ResourcePack pack : resourcePacksStorage.getPackStackBottomToTop()) {
@@ -37,7 +38,7 @@ public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
try {
final BedrockAttachableData attachableData = BedrockAttachableSerializer.deserialize(pack.content().getString(attachablePath));
final String identifier = Key.namespaced(attachableData.identifier());
- this.attachableDefinitions.put(identifier, new AttachableDefinitions.AttachableDefinition(identifier, attachableData));
+ this.attachableDefinitions.put(identifier, new AttachableDefinition(identifier, "attachable_" + identifier + "_default", attachableData));
} catch (Throwable e) {
ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Failed to parse attachable definition " + attachablePath + " in pack " + pack.packId(), e);
}
@@ -46,10 +47,10 @@ public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
}
public Map attachableDefinitions() {
- return attachableDefinitions;
+ return Collections.unmodifiableMap(attachableDefinitions);
}
- public record AttachableDefinition(String identifier, BedrockAttachableData attachableData) {
+ public record AttachableDefinition(String identifier, String key, BedrockAttachableData attachableData) {
}
}
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
index d9c0011..d740beb 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
@@ -155,9 +155,9 @@ public Item javaItem(final BedrockItem bedrockItem) {
data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else {
- if (resourcePacksStorage.getAttachableData().containsKey(identifier)) {
- int javaItemModel = resourcePacksStorage.getAttachableData().get(identifier);
- data.set(StructuredDataKey.CUSTOM_MODEL_DATA, javaItemModel);
+ if (resourcePacksStorage.getAttachable().attachableDefinitions().containsKey(identifier)) {
+ final String key = resourcePacksStorage.getAttachable().attachableDefinitions().get(identifier).key();
+ data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomAttachableResourceRewriter.getCustomModelData(key));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomAttachableResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else if (itemDefinition != null && itemDefinition.iconComponent() != null) {
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomItemTextureResourceRewriter.getCustomModelData(itemDefinition.iconComponent()));
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
index b4e0fb7..aa9c578 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
@@ -111,8 +111,6 @@ public static void apply(final ResourcePacksStorage resourcePacksStorage, final
if (overridesMap.put(javaModelData, override) != null) {
throw new IllegalStateException("Duplicate custom model data: " + override);
- } else {
- resourcePacksStorage.getAttachableData().put(entry.getKey(), javaModelData);
}
}
}
@@ -131,8 +129,8 @@ public static void apply(final ResourcePacksStorage resourcePacksStorage, final
}
}
- public static int getCustomModelData(final String iconName) {
- return Math.abs(iconName.hashCode() + 1); // 0 is used for the default model
+ public static int getCustomModelData(final String key) {
+ return Math.abs(key.hashCode() + 1); // 0 is used for the default model
}
}
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
index 9a4fd4d..466d89d 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
@@ -48,7 +48,6 @@ public class ResourcePacksStorage extends StoredObject {
private boolean javaClientWaitingForPack;
private boolean loadedOnJavaClient;
private final Map converterData = new HashMap<>();
- private final Map attachableData = new HashMap<>();
private TextDefinitions texts;
private BlockDefinitions blocks;
@@ -188,10 +187,6 @@ public Map getConverterData() {
return this.converterData;
}
- public Map getAttachableData() {
- return attachableData;
- }
-
public boolean hasFinishedLoading() {
return this.texts != null;
}
From 3dbb43aa8643db9d710f956d13bb2e9439b6e726 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:24:40 +0700
Subject: [PATCH 05/10] Changes.
---
.../api/model/resourcepack/AttachableDefinitions.java | 8 ++++----
.../viabedrock/protocol/rewriter/ItemRewriter.java | 5 ++---
.../resourcepack/CustomAttachableResourceRewriter.java | 2 +-
3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
index 8ba5555..6dc10ca 100644
--- a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
@@ -30,7 +30,7 @@
public class AttachableDefinitions {
- private final Map attachableDefinitions = new HashMap<>();
+ private final Map attachables = new HashMap<>();
public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
for (ResourcePack pack : resourcePacksStorage.getPackStackBottomToTop()) {
@@ -38,7 +38,7 @@ public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
try {
final BedrockAttachableData attachableData = BedrockAttachableSerializer.deserialize(pack.content().getString(attachablePath));
final String identifier = Key.namespaced(attachableData.identifier());
- this.attachableDefinitions.put(identifier, new AttachableDefinition(identifier, "attachable_" + identifier + "_default", attachableData));
+ this.attachables.put(identifier, new AttachableDefinition(identifier, "attachable_" + identifier + "_default", attachableData));
} catch (Throwable e) {
ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Failed to parse attachable definition " + attachablePath + " in pack " + pack.packId(), e);
}
@@ -46,8 +46,8 @@ public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
}
}
- public Map attachableDefinitions() {
- return Collections.unmodifiableMap(attachableDefinitions);
+ public Map attachables() {
+ return Collections.unmodifiableMap(this.attachables);
}
public record AttachableDefinition(String identifier, String key, BedrockAttachableData attachableData) {
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
index d740beb..4df1114 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
@@ -31,7 +31,6 @@
import com.viaversion.viaversion.util.Key;
import net.raphimc.viabedrock.ViaBedrock;
import net.raphimc.viabedrock.api.model.BlockState;
-import net.raphimc.viabedrock.api.model.resourcepack.AttachableDefinitions;
import net.raphimc.viabedrock.api.model.resourcepack.ItemDefinitions;
import net.raphimc.viabedrock.api.util.TextUtil;
import net.raphimc.viabedrock.protocol.BedrockProtocol;
@@ -155,8 +154,8 @@ public Item javaItem(final BedrockItem bedrockItem) {
data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else {
- if (resourcePacksStorage.getAttachable().attachableDefinitions().containsKey(identifier)) {
- final String key = resourcePacksStorage.getAttachable().attachableDefinitions().get(identifier).key();
+ if (resourcePacksStorage.getAttachable().attachables().containsKey(identifier)) {
+ final String key = resourcePacksStorage.getAttachable().attachables().get(identifier).key();
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomAttachableResourceRewriter.getCustomModelData(key));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomAttachableResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else if (itemDefinition != null && itemDefinition.iconComponent() != null) {
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
index aa9c578..dbb97ed 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
@@ -42,7 +42,7 @@ public class CustomAttachableResourceRewriter {
public static void apply(final ResourcePacksStorage resourcePacksStorage, final ResourcePack.Content javaContent) {
final Map overridesMap = new TreeMap<>();
- for (Map.Entry entry : resourcePacksStorage.getAttachable().attachableDefinitions().entrySet()) {
+ for (Map.Entry entry : resourcePacksStorage.getAttachable().attachables().entrySet()) {
for (String bedrockPath : entry.getValue().attachableData().textures().values()) {
final String javaPath = "attachable_texture/" + StringUtil.makeIdentifierValueSafe(bedrockPath.replace("textures/", ""));
for (ResourcePack pack : resourcePacksStorage.getPackStackTopToBottom()) {
From 9f1fe6706f9d9f84a9bc52dd3a94eb8385992e63 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:33:26 +0700
Subject: [PATCH 06/10] Changes.
---
.../api/model/resourcepack/AttachableDefinitions.java | 4 ++--
.../viabedrock/protocol/rewriter/ItemRewriter.java | 5 ++---
.../protocol/rewriter/ResourcePackRewriter.java | 4 ----
.../resourcepack/CustomAttachableResourceRewriter.java | 2 +-
.../viabedrock/protocol/storage/ResourcePacksStorage.java | 8 ++++----
5 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
index 6dc10ca..ccc696c 100644
--- a/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
+++ b/src/main/java/net/raphimc/viabedrock/api/model/resourcepack/AttachableDefinitions.java
@@ -38,7 +38,7 @@ public AttachableDefinitions(final ResourcePacksStorage resourcePacksStorage) {
try {
final BedrockAttachableData attachableData = BedrockAttachableSerializer.deserialize(pack.content().getString(attachablePath));
final String identifier = Key.namespaced(attachableData.identifier());
- this.attachables.put(identifier, new AttachableDefinition(identifier, "attachable_" + identifier + "_default", attachableData));
+ this.attachables.put(identifier, new AttachableDefinition(identifier, attachableData));
} catch (Throwable e) {
ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Failed to parse attachable definition " + attachablePath + " in pack " + pack.packId(), e);
}
@@ -50,7 +50,7 @@ public Map attachables() {
return Collections.unmodifiableMap(this.attachables);
}
- public record AttachableDefinition(String identifier, String key, BedrockAttachableData attachableData) {
+ public record AttachableDefinition(String identifier, BedrockAttachableData attachableData) {
}
}
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
index 4df1114..86b1a76 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
@@ -154,9 +154,8 @@ public Item javaItem(final BedrockItem bedrockItem) {
data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else {
- if (resourcePacksStorage.getAttachable().attachables().containsKey(identifier)) {
- final String key = resourcePacksStorage.getAttachable().attachables().get(identifier).key();
- data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomAttachableResourceRewriter.getCustomModelData(key));
+ if (resourcePacksStorage.getAttachables().attachables().containsKey(identifier)) {
+ data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomAttachableResourceRewriter.getCustomModelData("attachable_" + identifier + "_default"));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomAttachableResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else if (itemDefinition != null && itemDefinition.iconComponent() != null) {
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomItemTextureResourceRewriter.getCustomModelData(itemDefinition.iconComponent()));
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java
index 7b04c34..f56f253 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ResourcePackRewriter.java
@@ -26,10 +26,6 @@
import net.raphimc.viabedrock.protocol.rewriter.resourcepack.GlyphSheetResourceRewriter;
import net.raphimc.viabedrock.protocol.storage.ResourcePacksStorage;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-
public class ResourcePackRewriter {
public static ResourcePack.Content bedrockToJava(final ResourcePacksStorage resourcePacksStorage) {
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
index dbb97ed..46493fb 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/resourcepack/CustomAttachableResourceRewriter.java
@@ -42,7 +42,7 @@ public class CustomAttachableResourceRewriter {
public static void apply(final ResourcePacksStorage resourcePacksStorage, final ResourcePack.Content javaContent) {
final Map overridesMap = new TreeMap<>();
- for (Map.Entry entry : resourcePacksStorage.getAttachable().attachables().entrySet()) {
+ for (Map.Entry entry : resourcePacksStorage.getAttachables().attachables().entrySet()) {
for (String bedrockPath : entry.getValue().attachableData().textures().values()) {
final String javaPath = "attachable_texture/" + StringUtil.makeIdentifierValueSafe(bedrockPath.replace("textures/", ""));
for (ResourcePack pack : resourcePacksStorage.getPackStackTopToBottom()) {
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
index 466d89d..6240dc5 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
@@ -52,7 +52,7 @@ public class ResourcePacksStorage extends StoredObject {
private TextDefinitions texts;
private BlockDefinitions blocks;
private ItemDefinitions items;
- private AttachableDefinitions attachable;
+ private AttachableDefinitions attachables;
private TextureDefinitions textures;
private SoundDefinitions sounds;
private ParticleDefinitions particles;
@@ -150,7 +150,7 @@ public void setPackStack(final UUID[] resourcePackStack, final UUID[] behaviourP
this.texts = new TextDefinitions(this);
this.blocks = new BlockDefinitions(this);
this.items = new ItemDefinitions(this);
- this.attachable = new AttachableDefinitions(this);
+ this.attachables = new AttachableDefinitions(this);
this.textures = new TextureDefinitions(this);
this.sounds = new SoundDefinitions(this);
this.particles = new ParticleDefinitions(this);
@@ -203,8 +203,8 @@ public ItemDefinitions getItems() {
return this.items;
}
- public AttachableDefinitions getAttachable() {
- return attachable;
+ public AttachableDefinitions getAttachables() {
+ return attachables;
}
public TextureDefinitions getTextures() {
From c8655215f3e13504f57d98dd124c8a1c96a93edc Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:43:59 +0700
Subject: [PATCH 07/10] this.
---
.../viabedrock/protocol/storage/ResourcePacksStorage.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
index 6240dc5..3aef1bb 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/storage/ResourcePacksStorage.java
@@ -204,7 +204,7 @@ public ItemDefinitions getItems() {
}
public AttachableDefinitions getAttachables() {
- return attachables;
+ return this.attachables;
}
public TextureDefinitions getTextures() {
From 7c368677fd4f3b1f276c006f1e636ffcb4334c89 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:51:51 +0700
Subject: [PATCH 08/10] Update CubeConverter.
---
build.gradle | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build.gradle b/build.gradle
index aa34407..333ee9f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -75,7 +75,7 @@ dependencies {
exclude group: "com.google.guava"
}
api "org.lz4:lz4-pure-java:1.8.0"
- api("com.github.Oryxel:CubeConverter:859c2cfa71") {
+ api("com.github.Oryxel:CubeConverter:5ae1e90e4f") {
transitive = false
}
}
From 8ed5ceb9046ea9fedec449d7c4f7129a08223686 Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 22:54:35 +0700
Subject: [PATCH 09/10] Invert if.
---
.../viabedrock/protocol/rewriter/ItemRewriter.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
index 86b1a76..e17282d 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
@@ -150,10 +150,7 @@ public Item javaItem(final BedrockItem bedrockItem) {
}
}
- if (!resourcePacksStorage.isLoadedOnJavaClient()) {
- data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
- javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
- } else {
+ if (resourcePacksStorage.isLoadedOnJavaClient()) {
if (resourcePacksStorage.getAttachables().attachables().containsKey(identifier)) {
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomAttachableResourceRewriter.getCustomModelData("attachable_" + identifier + "_default"));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomAttachableResourceRewriter.ITEM)), bedrockItem.amount(), data);
@@ -165,6 +162,9 @@ public Item javaItem(final BedrockItem bedrockItem) {
data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt("§cMissing item: " + identifier));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get("minecraft:paper"), bedrockItem.amount(), data);
}
+ } else {
+ data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
+ javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
}
}
From b786a26a864cfaaac34a926d69f350d6aa281e5f Mon Sep 17 00:00:00 2001
From: Oryxel <172038521+Oryxel@users.noreply.github.com>
Date: Sun, 8 Sep 2024 23:39:24 +0700
Subject: [PATCH 10/10] Changes.
---
.../viabedrock/protocol/rewriter/ItemRewriter.java | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
index e17282d..502c888 100644
--- a/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
+++ b/src/main/java/net/raphimc/viabedrock/protocol/rewriter/ItemRewriter.java
@@ -148,23 +148,21 @@ public Item javaItem(final BedrockItem bedrockItem) {
} else {
data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt(resourcePacksStorage.getTexts().get("item." + Key.stripMinecraftNamespace(identifier) + ".name")));
}
- }
- if (resourcePacksStorage.isLoadedOnJavaClient()) {
- if (resourcePacksStorage.getAttachables().attachables().containsKey(identifier)) {
+ if (resourcePacksStorage.getAttachables().attachables().containsKey(identifier) && resourcePacksStorage.isLoadedOnJavaClient()) {
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomAttachableResourceRewriter.getCustomModelData("attachable_" + identifier + "_default"));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomAttachableResourceRewriter.ITEM)), bedrockItem.amount(), data);
- } else if (itemDefinition != null && itemDefinition.iconComponent() != null) {
+ } else if (itemDefinition.iconComponent() != null && resourcePacksStorage.isLoadedOnJavaClient()) {
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, CustomItemTextureResourceRewriter.getCustomModelData(itemDefinition.iconComponent()));
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
} else {
- ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Missing bedrock -> java item mapping for " + identifier);
- data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt("§cMissing item: " + identifier));
+ data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get("minecraft:paper"), bedrockItem.amount(), data);
}
} else {
- data.set(StructuredDataKey.LORE, new Tag[]{TextUtil.stringToNbt("§7[ViaBedrock] Custom item: " + identifier)});
- javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get(Key.namespaced(CustomItemTextureResourceRewriter.ITEM)), bedrockItem.amount(), data);
+ ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Missing bedrock -> java item mapping for " + identifier);
+ data.set(StructuredDataKey.ITEM_NAME, TextUtil.stringToNbt("§cMissing item: " + identifier));
+ javaItem = new StructuredItem(BedrockProtocol.MAPPINGS.getJavaItems().get("minecraft:paper"), bedrockItem.amount(), data);
}
}