mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 19:39:11 +00:00
add mod assets
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user