-
Notifications
You must be signed in to change notification settings - Fork 8
feat: bedrock models #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
meowora
wants to merge
3
commits into
development
Choose a base branch
from
feat/bedrock-models
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/me/owdding/catharsis/mixins/ModelManagerMixin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package me.owdding.catharsis.mixins; | ||
|
|
||
| import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; | ||
| import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
| import me.owdding.catharsis.features.models.BedrockModels; | ||
| import net.minecraft.client.resources.model.ModelManager; | ||
| import net.minecraft.server.packs.resources.PreparableReloadListener; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.Executor; | ||
|
|
||
| @Mixin(ModelManager.class) | ||
| public class ModelManagerMixin { | ||
|
|
||
| @WrapMethod(method = "reload") | ||
| public CompletableFuture<Void> reload( | ||
| PreparableReloadListener.SharedState sharedState, | ||
| Executor executor, | ||
| PreparableReloadListener.PreparationBarrier preparationBarrier, | ||
| Executor executor2, | ||
| Operation<CompletableFuture<Void>> original | ||
| ) { | ||
| return BedrockModels.INSTANCE.reload(sharedState, executor, preparationBarrier, executor2).thenCompose(i -> | ||
| original.call(sharedState, executor, preparationBarrier, executor2) | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/kotlin/me/owdding/catharsis/features/models/BedrockModels.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package me.owdding.catharsis.features.models | ||
|
|
||
| import com.google.gson.GsonBuilder | ||
| import com.google.gson.JsonElement | ||
| import me.owdding.catharsis.Catharsis | ||
| import me.owdding.catharsis.utils.extensions.mapBothNotNull | ||
| import me.owdding.catharsis.utils.geometry.BedrockGeometry | ||
| import me.owdding.ktmodules.Module | ||
| import net.minecraft.resources.FileToIdConverter | ||
| import net.minecraft.resources.ResourceLocation | ||
| import net.minecraft.server.packs.resources.ResourceManager | ||
| import net.minecraft.server.packs.resources.SimplePreparableReloadListener | ||
| import net.minecraft.util.profiling.ProfilerFiller | ||
| import tech.thatgravyboat.skyblockapi.utils.json.Json.toDataOrThrow | ||
|
|
||
| @Module | ||
| object BedrockModels : SimplePreparableReloadListener<Map<ResourceLocation, BedrockGeometry>>() { | ||
| private val geoModelConverter = FileToIdConverter("catharsis/geo_models", ".geo.json") | ||
| private val logger = Catharsis.featureLogger("BlockReplacements") | ||
| private val gson = GsonBuilder().create() | ||
|
|
||
| private val models: MutableMap<ResourceLocation, BedrockGeometry> = mutableMapOf() | ||
|
|
||
| override fun prepare( | ||
| resourceManager: ResourceManager, | ||
| profiler: ProfilerFiller, | ||
| ): Map<ResourceLocation, BedrockGeometry> { | ||
| return geoModelConverter.listMatchingResources(resourceManager).mapBothNotNull { (id, resource) -> | ||
| geoModelConverter.fileToId(id) to logger.runCatching("Error loading block replacement definition $id") { | ||
| resource.openAsReader().use { reader -> | ||
| gson.fromJson(reader, JsonElement::class.java).toDataOrThrow(BedrockGeometry.CODEC).first() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun apply( | ||
| loadedModels: Map<ResourceLocation, BedrockGeometry>, | ||
| resourceManager: ResourceManager, | ||
| profiler: ProfilerFiller, | ||
| ) { | ||
| models.clear() | ||
| models.putAll(loadedModels) | ||
| } | ||
|
|
||
| fun getModel(location: ResourceLocation) = models[location] | ||
|
|
||
| init { | ||
| // Utils.registerClientReloadListener(Catharsis.id("bedrock_models"), this, ResourceReloaderKeys.BEFORE_VANILLA) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package me.owdding.catharsis.utils | ||
|
|
||
| import me.owdding.catharsis.Catharsis | ||
| import me.owdding.catharsis.utils.extensions.sendWithPrefix | ||
| import me.owdding.ktmodules.Module | ||
| import net.minecraft.network.chat.MutableComponent | ||
| import net.minecraft.resources.ResourceLocation | ||
| import tech.thatgravyboat.skyblockapi.api.events.base.Subscription | ||
| import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent | ||
| import tech.thatgravyboat.skyblockapi.helpers.McClient | ||
| import tech.thatgravyboat.skyblockapi.utils.DebugToggle | ||
| import tech.thatgravyboat.skyblockapi.utils.DevUtils | ||
| import tech.thatgravyboat.skyblockapi.utils.extentions.parseFormattedInt | ||
| import java.util.* | ||
| import kotlin.io.path.Path | ||
| import kotlin.io.path.notExists | ||
| import kotlin.io.path.reader | ||
|
|
||
| internal fun debugToggle(path: String, description: String = path): DebugToggle { | ||
| return DebugToggle(Catharsis.id(path), description, CatharsisDevUtils) | ||
| } | ||
| @Module | ||
| internal object CatharsisDevUtils : DevUtils() { | ||
| override val commandName: String = "sbapi toggle" | ||
| override fun send(component: MutableComponent) = component.sendWithPrefix() | ||
| val properties: Map<String, String> = loadFromProperties() | ||
|
|
||
| fun getInt(key: String, default: Int = 0): Int { | ||
| return properties[key].parseFormattedInt(default) | ||
| } | ||
|
|
||
| fun getBoolean(key: String): Boolean { | ||
| return properties[key] == "true" | ||
| } | ||
|
|
||
| private fun loadFromProperties(): Map<String, String> { | ||
| val properties = Properties() | ||
| val path = System.getProperty("sbapi.property_path")?.let { Path(it) } ?: McClient.config.resolve("catharsis.properties") | ||
| if (path.notExists()) return emptyMap() | ||
| path.reader(Charsets.UTF_8).use { | ||
| properties.load(it) | ||
| } | ||
| val map = mutableMapOf<String, String>() | ||
| properties.forEach { (key, value) -> | ||
| ResourceLocation.tryBySeparator(key.toString(), '@')?.let { | ||
| if (value.toString() == "true") { | ||
| states[it] = true | ||
| } | ||
| } | ||
| map[key.toString()] = value.toString() | ||
| } | ||
| return map | ||
| } | ||
|
|
||
| @Subscription | ||
| fun commandRegister(event: RegisterCommandsEvent) = super.onCommandRegister(event) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.