mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
add mod assets
This commit is contained in:
@@ -57,7 +57,7 @@ artifacts {
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
archiveFileName = "${rootProject.name}-bukkit-plugin-${rootProject.properties["project_version"]}.jar"
|
||||
archiveFileName = "${rootProject.name}-plugin-${rootProject.properties["project_version"]}.jar"
|
||||
destinationDirectory.set(file("$rootDir/target"))
|
||||
relocate("net.kyori", "net.momirealms.craftengine.libraries")
|
||||
relocate("net.momirealms.sparrow.nbt", "net.momirealms.craftengine.libraries.nbt")
|
||||
|
||||
@@ -12,6 +12,9 @@ forced-locale: ''
|
||||
resource-pack:
|
||||
# Should those images in minecraft:default font also work in minecraft:uniform
|
||||
override-uniform-font: true
|
||||
# Generate assets for CraftEngine fabric mod
|
||||
# Note: CraftEngine fabric mod is used for Axiom mod, most users do not need to install it
|
||||
generate-mod-assets: false
|
||||
# Resource pack protection
|
||||
protection:
|
||||
# Warning: Do not attempt to unzip the resource pack with crash tools enabled.
|
||||
|
||||
@@ -45,13 +45,12 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
private static BukkitBlockManager instance;
|
||||
private final BukkitCraftEngine plugin;
|
||||
|
||||
// Used to store override information of json files
|
||||
private final Map<Key, Map<String, JsonElement>> blockStateOverrides = new HashMap<>();
|
||||
|
||||
// A temporary map used to detect whether the same block state corresponds to multiple models.
|
||||
private final Map<Integer, Key> tempRegistryIdConflictMap = new HashMap<>();
|
||||
// A temporary map that converts the custom block registered on the server to the vanilla block ID.
|
||||
private final Map<Integer, Integer> tempBlockAppearanceConvertor = new HashMap<>();
|
||||
// A temporary map that stores the model path of a certain vanilla block state
|
||||
private final Map<Integer, JsonElement> tempVanillaBlockStateModels = new HashMap<>();
|
||||
|
||||
// The total amount of blocks registered
|
||||
private int customBlockCount;
|
||||
@@ -79,6 +78,10 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
|
||||
// a reverted mapper
|
||||
private final Map<Integer, List<Integer>> appearanceToRealState = new HashMap<>();
|
||||
// Used to store override information of json files
|
||||
private final Map<Key, Map<String, JsonElement>> blockStateOverrides = new HashMap<>();
|
||||
// for mod, real block id -> state models
|
||||
private final Map<Key, JsonElement> modBlockStates = new HashMap<>();
|
||||
// Cached command suggestions
|
||||
private final List<Suggestion> cachedSuggestions = new ArrayList<>();
|
||||
// Event listeners
|
||||
@@ -132,6 +135,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
this.id2CraftEngineBlocks.clear();
|
||||
this.cachedSuggestions.clear();
|
||||
this.blockStateOverrides.clear();
|
||||
this.modBlockStates.clear();
|
||||
if (EmptyBlock.INSTANCE != null)
|
||||
Arrays.fill(this.stateId2ImmutableBlockStates, EmptyBlock.INSTANCE.defaultState());
|
||||
}
|
||||
@@ -158,6 +162,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
private void clearCache() {
|
||||
this.tempRegistryIdConflictMap.clear();
|
||||
this.tempBlockAppearanceConvertor.clear();
|
||||
this.tempVanillaBlockStateModels.clear();
|
||||
}
|
||||
|
||||
public void initFastAsyncWorldEditHook() {
|
||||
@@ -181,25 +186,30 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
|
||||
@NotNull
|
||||
public ImmutableBlockState getImmutableBlockStateUnsafe(int stateId) {
|
||||
return stateId2ImmutableBlockStates[stateId - BlockStateUtils.vanillaStateSize()];
|
||||
return this.stateId2ImmutableBlockStates[stateId - BlockStateUtils.vanillaStateSize()];
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ImmutableBlockState getImmutableBlockState(int stateId) {
|
||||
if (!BlockStateUtils.isVanillaBlock(stateId)) {
|
||||
return stateId2ImmutableBlockStates[stateId - BlockStateUtils.vanillaStateSize()];
|
||||
return this.stateId2ImmutableBlockStates[stateId - BlockStateUtils.vanillaStateSize()];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Key, JsonElement> modBlockStates() {
|
||||
return Collections.unmodifiableMap(this.modBlockStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Key, Map<String, JsonElement>> blockOverrides() {
|
||||
return blockStateOverrides;
|
||||
return Collections.unmodifiableMap(this.blockStateOverrides);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Key, CustomBlock> blocks() {
|
||||
return this.id2CraftEngineBlocks;
|
||||
return Collections.unmodifiableMap(this.id2CraftEngineBlocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,7 +219,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
|
||||
@Override
|
||||
public Collection<Suggestion> cachedSuggestions() {
|
||||
return this.cachedSuggestions;
|
||||
return Collections.unmodifiableCollection(this.cachedSuggestions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -421,6 +431,14 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
// bind appearance
|
||||
bindAppearance(block);
|
||||
this.id2CraftEngineBlocks.put(id, block);
|
||||
|
||||
// generate mod assets
|
||||
if (ConfigManager.generateModAssets()) {
|
||||
for (ImmutableBlockState state : block.variantProvider().states()) {
|
||||
Key realBlockId = BlockStateUtils.getBlockOwnerIdFromState(state.customBlockState());
|
||||
this.modBlockStates.put(realBlockId, this.tempVanillaBlockStateModels.get(state.vanillaBlockState().registryId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void bindAppearance(CustomBlock block) {
|
||||
@@ -488,12 +506,14 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
Map<String, JsonElement> paths = this.blockStateOverrides.computeIfAbsent(block, k -> new HashMap<>());
|
||||
if (variants.size() == 1) {
|
||||
paths.put(propertyData, variants.get(0));
|
||||
this.tempVanillaBlockStateModels.put(vanillaStateRegistryId, variants.get(0));
|
||||
} else {
|
||||
JsonArray array = new JsonArray();
|
||||
for (JsonObject object : variants) {
|
||||
array.add(object);
|
||||
}
|
||||
paths.put(propertyData, array);
|
||||
this.tempVanillaBlockStateModels.put(vanillaStateRegistryId, array);
|
||||
}
|
||||
return Pair.of(block, vanillaStateRegistryId);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.AbstractModelGenerator;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractBlockManager extends AbstractModelGenerator implements BlockManager {
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ public interface BlockManager extends Reloadable, ModelGenerator, ConfigSectionP
|
||||
|
||||
Map<Key, Map<String, JsonElement>> blockOverrides();
|
||||
|
||||
Map<Key, JsonElement> modBlockStates();
|
||||
|
||||
Map<Key, CustomBlock> blocks();
|
||||
|
||||
Optional<CustomBlock> getBlock(Key key);
|
||||
|
||||
@@ -758,7 +758,32 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(overridedBlockPath)) {
|
||||
GsonHelper.get().toJson(stateJson, writer);
|
||||
} catch (IOException e) {
|
||||
plugin.logger().warn("Failed to save item model for [" + key + "]");
|
||||
plugin.logger().warn("Failed to create block states for [" + key + "]");
|
||||
}
|
||||
}
|
||||
|
||||
if (!ConfigManager.generateModAssets()) return;
|
||||
for (Map.Entry<Key, JsonElement> entry : plugin.blockManager().modBlockStates().entrySet()) {
|
||||
Key key = entry.getKey();
|
||||
Path overridedBlockPath = generatedPackPath
|
||||
.resolve("assets")
|
||||
.resolve(key.namespace())
|
||||
.resolve("blockstates")
|
||||
.resolve(key.value() + ".json");
|
||||
JsonObject stateJson = new JsonObject();
|
||||
JsonObject variants = new JsonObject();
|
||||
stateJson.add("variants", variants);
|
||||
variants.add("", entry.getValue());
|
||||
try {
|
||||
Files.createDirectories(overridedBlockPath.getParent());
|
||||
} catch (IOException e) {
|
||||
plugin.logger().severe("Error creating " + overridedBlockPath.toAbsolutePath());
|
||||
continue;
|
||||
}
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(overridedBlockPath)) {
|
||||
GsonHelper.get().toJson(stateJson, writer);
|
||||
} catch (IOException e) {
|
||||
plugin.logger().warn("Failed to create block states for [" + key + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ConfigManager implements Reloadable {
|
||||
protected boolean checkUpdate;
|
||||
protected boolean metrics;
|
||||
|
||||
protected boolean resource_pack$generate_mod_assets;
|
||||
protected boolean resource_pack$override_uniform_font;
|
||||
protected List<ConditionalResolution> resource_pack$duplicated_files_handler;
|
||||
protected List<String> resource_pack$merge_external_folders;
|
||||
@@ -68,7 +69,6 @@ public class ConfigManager implements Reloadable {
|
||||
protected List<String> resource_pack$protection$obfuscation$resource_location$bypass_sounds;
|
||||
protected List<String> resource_pack$protection$obfuscation$resource_location$bypass_equipments;
|
||||
|
||||
|
||||
protected float resource_pack$supported_version$min;
|
||||
protected float resource_pack$supported_version$max;
|
||||
|
||||
@@ -174,6 +174,7 @@ public class ConfigManager implements Reloadable {
|
||||
|
||||
// resource pack
|
||||
resource_pack$override_uniform_font = config.getBoolean("resource-pack.override-uniform-font", false);
|
||||
resource_pack$generate_mod_assets = config.getBoolean("resource-pack.generate-mod-assets", false);
|
||||
resource_pack$supported_version$min = getVersion(config.get("resource-pack.supported-version.min", "1.20").toString());
|
||||
resource_pack$supported_version$max = getVersion(config.get("resource-pack.supported-version.max", "LATEST").toString());
|
||||
resource_pack$merge_external_folders = config.getStringList("resource-pack.merge-external-folders");
|
||||
@@ -489,6 +490,10 @@ public class ConfigManager implements Reloadable {
|
||||
return instance.resource_pack$protection$obfuscation$resource_location$bypass_equipments;
|
||||
}
|
||||
|
||||
public static boolean generateModAssets() {
|
||||
return instance.resource_pack$generate_mod_assets;
|
||||
}
|
||||
|
||||
public YamlDocument loadOrCreateYamlData(String fileName) {
|
||||
File file = new File(this.plugin.dataFolderFile(), fileName);
|
||||
if (!file.exists()) {
|
||||
|
||||
@@ -44,7 +44,7 @@ artifacts {
|
||||
tasks {
|
||||
shadowJar {
|
||||
archiveClassifier = ""
|
||||
archiveFileName = "${rootProject.name}-bukkit-mod-${rootProject.properties["project_version"]}.jar"
|
||||
archiveFileName = "${rootProject.name}-ignite-mod-${rootProject.properties["project_version"]}.jar"
|
||||
destinationDirectory.set(file("$rootDir/target"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user