improve: setCreativeCategory & mapping

This commit is contained in:
Reider745
2026-02-06 15:04:34 +03:00
parent 0f7fede838
commit 4775f836cf
4 changed files with 32 additions and 9 deletions
@@ -30,6 +30,8 @@ import org.cloudburstmc.nbt.NbtMap;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import java.io.File;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
@@ -209,6 +211,15 @@ public class BlockPalette {
}
// custom runtime block
final JSONObject EMPTY = new JSONObject();
JSONObject blockMapping = EMPTY;
try {
blockMapping = new JSONObject(Files.readString(new File("block_mapping.json").toPath()));
} catch (Exception e) {
e.printStackTrace();
}
JSONObject statesValues = blockMapping.optJSONObject("states_values", EMPTY);
AtomicReference<Integer> RUNTIME_ID = new AtomicReference<>(Integer.MAX_VALUE);
CustomBlock.blocks.forEach((id, manager) -> {
@@ -224,12 +235,15 @@ public class BlockPalette {
var builderState = NbtMap.builder();
state.keySet().forEach((name) -> {
builderState.putInt(name, state.getInt(name));
JSONObject convert = statesValues.optJSONObject(name, EMPTY);
int value = state.getInt(name);
builderState.put(name, convert.has(String.valueOf(value)) ? convert.get(String.valueOf(value)) : value);
});
builder.put("states", builderState.build());
builder.putString("name", manager.textId);
builder.putInt("version", VERSION_STATE);
var nbt = builder.build();
nbt.hashCode();
if(!blockStateMapping.containsState(nbt)) {
@@ -334,7 +348,7 @@ public class BlockPalette {
runtimeId = legacyToRuntimeId.get(id << Block.DATA_BITS);
if (runtimeId == -1 && id != BlockID.INFO_UPDATE) {
logger.debug("failed to locate state for id: " + id + ":" + meta);
logger.info("failed to locate state for id: " + id + ":" + meta);
runtimeId = legacyToRuntimeId.get(BlockID.INFO_UPDATE << Block.DATA_BITS);
if (runtimeId == -1)
@@ -402,7 +416,7 @@ public class BlockPalette {
for (NbtMap key : paletteMap.keySet()) {
if (key.getString("name").equals(id) && damage == levelDbRuntimeIdToData.getOrDefault(key, 0)) {
logger.warning("Replacing a unit with low compatibility: " + id);
logger.warning("Replacing a unit with low compatibility: " + id + " " + customVanilla.build() + " " + key);
snapshot = paletteMap.get(key);
CACHE_PALETTE.put(vanilla, snapshot);
break;
@@ -12,6 +12,8 @@ import com.zhekasmirnov.innercore.api.mod.adaptedscript.AdaptedScriptAPI.IDRegis
import com.zhekasmirnov.innercore.api.runtime.other.NameTranslation;
import it.unimi.dsi.fastutil.ints.Int2BooleanMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.ArrayList;
import java.util.HashMap;
@@ -65,8 +67,10 @@ public class ItemMethod {
manager.put(PropertiesNames.MAX_STACK, stack);
}
public static void setCreativeCategory(CustomManager manager, int val) {
manager.put(PropertiesNames.CREATIVE_CATEGORY, val);
private static final Int2IntMap CREATIVE_CATEGORY = new Int2IntOpenHashMap();
public static void setCreativeCategory(int id, int val) {
CREATIVE_CATEGORY.put(id, val);
}
public static int getCreativeCategory(int id) {
@@ -69,6 +69,11 @@ public class BlockState {
return null;
}
@JSStaticFunction
public static int getBlockStateCapacity(int id) {
return CAPACITY_STATES.getOrDefault(id, 0);
}
public final int id;
public final int data;
public final int runtimeId;
@@ -101,7 +101,7 @@ public class NativeItem {
}
public void setCreativeCategory(int val) {
setCreativeCategory(properties, val);
setCreativeCategory(id, val);
}
@Deprecated(since = "Zote")
@@ -263,8 +263,8 @@ public class NativeItem {
// JIC if something changed, check PlayerOffhandInventory.OFFHAND_ITEMS
}
public static void setCreativeCategory(CustomManager manager, int val) {
ItemMethod.setCreativeCategory(manager, val);
public static void setCreativeCategory(int id, int val) {
ItemMethod.setCreativeCategory(id, val);
}
@Deprecated(since = "Zote")
@@ -305,7 +305,7 @@ public class NativeItem {
public static void setCreativeCategoryForId(int id, int category) {
ItemMethod.setCreativeCategory(CustomManager.getFor(id), category);
ItemMethod.setCreativeCategory(id, category);
}
public static String getNameForId(int id, int data) {