-
Notifications
You must be signed in to change notification settings - Fork 2
feat: custom entity textures #23
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
Open
Bloxigus
wants to merge
20
commits into
meowdding:development
Choose a base branch
from
Bloxigus:custom-entitity-textures
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.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
26081ef
feat: initial implementation of custom entity textures
Bloxigus f444738
fix: oops forgot to shoot this
Bloxigus d6f34fc
fix: multiversion build
Bloxigus 78b7e5b
feat: custom entity models (untested) (just to get review :pleading_f…
Bloxigus 06e877c
chore: remove meow
Bloxigus 4938d6b
bad model you cant do that youre only one entity not more than that
Bloxigus 8b33f37
fix: animations now work
Bloxigus 86ae86b
fix: multiversion maybe
Bloxigus ba2cbff
fix: multiversion maybe v2
Bloxigus c597548
fix: safety and geometry finally working
Bloxigus 1e3b9d1
make it look better definition wise
Bloxigus afa9114
fix: oopsie daisy
Bloxigus 7f61a8d
move things around v2
Bloxigus 9639ba3
remove invis check
Bloxigus 9c132d9
move things around, listen for attribute updates and equipment update…
Bloxigus 2554008
name and uuid
Bloxigus 6a48668
soaphy review
Bloxigus 9312a5d
soaphy review v2
Bloxigus b5d0647
soaphy review v3
Bloxigus adc6cd9
docs (dont kill me pls)
Bloxigus 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
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,80 @@ | ||
| --- | ||
| title: Entity Overrides | ||
| lang: en-US | ||
| next: | ||
| text: a | ||
| prev: | ||
| text: o | ||
| --- | ||
|
|
||
| # Entity Overrides | ||
|
|
||
| catharsis has a way to change entities!!!! | ||
|
|
||
| simply provide a file in `{your_name_space}:catharsis/entity_definitions/{entity_name}.json` | ||
|
|
||
| that loosk a bit liek this | ||
|
|
||
| ```json | ||
| { | ||
| "conditions": [ | ||
| { | ||
| "type": "condition_type", | ||
| ... | ||
| } | ||
| ], | ||
| "replacement": "{your_name_space}:{entity_replacement_name}.json" | ||
| } | ||
| ``` | ||
|
|
||
| and another file in `{your_name_here}:catharsis/entities/{entity_replacement_name}.json` | ||
|
|
||
| that looks like this | ||
|
|
||
| ```json | ||
| { | ||
| "texture": "{your_name_space}:textures/{texture path here}.png", | ||
| "model": "{your_name_space}:models/{model_path_here}.geo.json" | ||
| } | ||
| ``` | ||
|
|
||
| and put a `.png` fiel where the texture path leads to and a bedrock entity geometry (`.geo.json`) where that one points to. also if you name the bones right the model will use the main entity's animations!!!! the mod will log if a bone is named wrongly so dont worry about naming things right straight away. | ||
|
|
||
|
|
||
|
|
||
| ## Condition Types | ||
|
|
||
| there are a lot of condition types | ||
|
|
||
| ### `"type": "player"` | ||
| lets you access state about a player entity | ||
| keys: | ||
| `"skin"`: a reference to a skin url, if the entity matches this skin _exactly_ it is used | ||
| `"only_npc"`: the entity matches only if it isnt a real player (useful for npcs) | ||
|
|
||
| ### `"type": "identity"` | ||
| lets you access state about regular entities | ||
| keys: | ||
| `"type"`: matches the entity's type (eg: `minecraft:zombie` for zombies) | ||
| `"uuid"`: matches the entity's uuid. skyblock mostly uses random uuids | ||
| `"name"`: matches the entity's name | ||
|
|
||
| ### `"type": "attribute"` | ||
| allows access to entity attributes (such as max health) | ||
| keys: | ||
| `"attribute"`: which attribute to check | ||
| `"value"` or `"values"`: matches one or multiple values | ||
|
|
||
| ### `"type": "island"` | ||
| matches if you are on an island | ||
| keys: | ||
| `"island"` or `"islands"`: matches one or multiple islands | ||
|
|
||
| ### `"type": "equipment"` | ||
| matches the entity's equipment | ||
| keys: | ||
| `"slot"`: which slot to check | ||
| `"property"`: what BOOLEAN property to check (this can add more keys) | ||
|
|
||
| ## Model quirks | ||
| Cannot handle per-face uv. will break. Everything else _should_ work fine |
14 changes: 14 additions & 0 deletions
14
docs/example_pack/assets/your_name_space/catharsis/entity_definitions/graveyard_zombie.json
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,14 @@ | ||
| { | ||
| "conditions": [ | ||
| { | ||
| "type": "identity", | ||
| "entity_type": "minecraft:zombie" | ||
| }, | ||
| { | ||
| "type": "attribute", | ||
| "attribute": "minecraft:max_health", | ||
| "value": 100 | ||
| } | ||
| ], | ||
| "replacement": "your_name_space:graveyard_zombie" | ||
| } |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/me/owdding/catharsis/hooks/entity/EntityHook.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,14 @@ | ||
| package me.owdding.catharsis.hooks.entity; | ||
|
|
||
| import me.owdding.catharsis.features.entity.models.CustomEntityModel; | ||
|
|
||
| public interface EntityHook { | ||
|
|
||
| default void catharsis$resetCustomModel() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| default CustomEntityModel catharsis$getCustomEntityModel() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/me/owdding/catharsis/hooks/entity/EntityRenderStateHook.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,15 @@ | ||
| package me.owdding.catharsis.hooks.entity; | ||
|
|
||
| import me.owdding.catharsis.features.entity.models.CustomEntityModel; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public interface EntityRenderStateHook { | ||
|
|
||
| default void catharsis$setCustomEntityModel(@Nullable CustomEntityModel textureLocation) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| default @Nullable CustomEntityModel catharsis$getCustomEntityModel() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
src/main/java/me/owdding/catharsis/mixins/entity/EntityMixin.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,45 @@ | ||
| package me.owdding.catharsis.mixins.entity; | ||
|
|
||
| import me.owdding.catharsis.features.entity.CustomEntityDefinitions; | ||
| import me.owdding.catharsis.features.entity.models.CustomEntityModel; | ||
| import me.owdding.catharsis.features.entity.models.CustomEntityModels; | ||
| import me.owdding.catharsis.hooks.entity.EntityHook; | ||
| import net.minecraft.world.entity.Entity; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
|
|
||
| @Mixin(Entity.class) | ||
| public class EntityMixin implements EntityHook { | ||
|
|
||
| @Unique | ||
| private boolean catharsis$hasComputedModel = false; | ||
| @Unique | ||
| private CustomEntityModel catharsis$computedReplacement = null; | ||
|
|
||
| @Override | ||
| public void catharsis$resetCustomModel() { | ||
| catharsis$hasComputedModel = false; | ||
| } | ||
|
|
||
| @Override | ||
| public CustomEntityModel catharsis$getCustomEntityModel() { | ||
| if (catharsis$hasComputedModel) { | ||
| return catharsis$computedReplacement; | ||
| } | ||
|
|
||
| var customEntity = CustomEntityDefinitions.getFor((Entity) (Object) this); | ||
|
|
||
| catharsis$hasComputedModel = true; | ||
|
|
||
| CustomEntityModel customModel = null; | ||
|
|
||
| if (customEntity != null) { | ||
| customModel = CustomEntityModels.getModel(customEntity.getReplacement()); | ||
| } | ||
|
|
||
|
|
||
| catharsis$computedReplacement = customModel; | ||
|
|
||
| return customModel; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/owdding/catharsis/mixins/entity/EntityRenderStateMixin.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,23 @@ | ||
| package me.owdding.catharsis.mixins.entity; | ||
|
|
||
| import me.owdding.catharsis.features.entity.models.CustomEntityModel; | ||
| import me.owdding.catharsis.hooks.entity.EntityRenderStateHook; | ||
| import net.minecraft.client.renderer.entity.state.EntityRenderState; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
|
|
||
| @Mixin(EntityRenderState.class) | ||
| public class EntityRenderStateMixin implements EntityRenderStateHook { | ||
| @Unique | ||
| private CustomEntityModel catharsis$customTexture = null; | ||
|
|
||
| @Override | ||
| public void catharsis$setCustomEntityModel(CustomEntityModel textureLocation) { | ||
| catharsis$customTexture = textureLocation; | ||
| } | ||
|
|
||
| @Override | ||
| public CustomEntityModel catharsis$getCustomEntityModel() { | ||
| return catharsis$customTexture; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/owdding/catharsis/mixins/entity/EntityRendererMixin.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,23 @@ | ||
| package me.owdding.catharsis.mixins.entity; | ||
|
|
||
| import me.owdding.catharsis.features.entity.models.CustomEntityModel; | ||
| import net.minecraft.client.renderer.entity.EntityRenderer; | ||
| import net.minecraft.client.renderer.entity.state.EntityRenderState; | ||
| import net.minecraft.world.entity.Entity; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| @Mixin(EntityRenderer.class) | ||
| public class EntityRendererMixin<T extends Entity, S extends EntityRenderState> { | ||
|
|
||
| @Inject( | ||
| method = "extractRenderState", | ||
| at = @At("TAIL") | ||
| ) | ||
| public void extractRenderState(T entity, S reusedState, float partialTick, CallbackInfo ci) { | ||
| CustomEntityModel customTexture = entity.catharsis$getCustomEntityModel(); | ||
| reusedState.catharsis$setCustomEntityModel(customTexture); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/me/owdding/catharsis/features/entity/CustomEntityDefinition.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,22 @@ | ||
| package me.owdding.catharsis.features.entity | ||
|
|
||
| import me.owdding.catharsis.features.entity.conditions.EntityCondition | ||
| import me.owdding.ktcodecs.GenerateCodec | ||
| import net.minecraft.resources.Identifier | ||
| import net.minecraft.world.entity.Entity | ||
|
|
||
|
|
||
| @GenerateCodec | ||
| data class CustomEntityDefinition( | ||
| val conditions: List<EntityCondition>, | ||
| val replacement: Identifier | ||
| ) { | ||
| fun matches(entity: Entity): Boolean { | ||
| if (conditions.isEmpty()) return false | ||
|
|
||
| for (condition in conditions) { | ||
| if (!condition.matches(entity)) return false | ||
| } | ||
| return true | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/me/owdding/catharsis/features/entity/CustomEntityDefinitions.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,61 @@ | ||
| package me.owdding.catharsis.features.entity | ||
|
|
||
| import com.google.gson.GsonBuilder | ||
| import com.google.gson.JsonElement | ||
| import me.owdding.catharsis.Catharsis | ||
| import me.owdding.catharsis.generated.CatharsisCodecs | ||
| import me.owdding.ktmodules.Module | ||
| import net.minecraft.resources.FileToIdConverter | ||
| import net.minecraft.server.packs.resources.ResourceManager | ||
| import net.minecraft.server.packs.resources.SimplePreparableReloadListener | ||
| import net.minecraft.util.profiling.ProfilerFiller | ||
| import net.minecraft.world.entity.Entity | ||
| import tech.thatgravyboat.skyblockapi.helpers.McClient | ||
| import tech.thatgravyboat.skyblockapi.utils.json.Json.toDataOrThrow | ||
|
|
||
| @Module | ||
| object CustomEntityDefinitions : SimplePreparableReloadListener<List<CustomEntityDefinition>>() { | ||
|
|
||
| private val logger = Catharsis.featureLogger("EntityDefinitions") | ||
| private val converter = FileToIdConverter.json("catharsis/entity_definitions") | ||
| private val gson = GsonBuilder().create() | ||
| private val codec = CatharsisCodecs.getCodec<CustomEntityDefinition>() | ||
|
|
||
| private val definitions = mutableListOf<CustomEntityDefinition>() | ||
|
|
||
| override fun prepare( | ||
| resourceManager: ResourceManager, | ||
| profiler: ProfilerFiller, | ||
| ): List<CustomEntityDefinition> { | ||
| return converter.listMatchingResources(resourceManager) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be the same as gui definitions with the logger and the extensions |
||
| .mapNotNull { (id, resource) -> | ||
| logger.runCatching("Error loading entity definition $id") { | ||
| resource.openAsReader().use { bufferedReader -> | ||
| gson.fromJson(bufferedReader, JsonElement::class.java).toDataOrThrow(codec) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun apply( | ||
| definitions: List<CustomEntityDefinition>, | ||
| resourceManager: ResourceManager, | ||
| profiler: ProfilerFiller, | ||
| ) { | ||
| this.definitions.clear() | ||
| this.definitions.addAll(definitions) | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun getFor(entity: Entity): CustomEntityDefinition? { | ||
| for (definition in definitions) { | ||
| if (definition.matches(entity)) return definition | ||
| } | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| init { | ||
| McClient.registerClientReloadListener(Catharsis.id("custom_entity_definitions"), this) | ||
| } | ||
| } | ||
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/me/owdding/catharsis/features/entity/conditions/AttributeEntityCondition.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,34 @@ | ||
| package me.owdding.catharsis.features.entity.conditions | ||
|
|
||
| import me.owdding.catharsis.Catharsis | ||
| import me.owdding.ktcodecs.Compact | ||
| import me.owdding.ktcodecs.FieldNames | ||
| import me.owdding.ktcodecs.GenerateCodec | ||
| import net.minecraft.core.registries.BuiltInRegistries | ||
| import net.minecraft.resources.Identifier | ||
| import net.minecraft.world.entity.Entity | ||
| import net.minecraft.world.entity.LivingEntity | ||
| import tech.thatgravyboat.skyblockapi.utils.extentions.serverValue | ||
| import kotlin.jvm.optionals.getOrNull | ||
|
|
||
| @GenerateCodec | ||
| data class AttributeEntityCondition( | ||
| val attribute: Identifier, | ||
| @FieldNames("value", "values") @Compact val values: List<Float>, | ||
| ) : EntityCondition { | ||
| private val actualAttribute = BuiltInRegistries.ATTRIBUTE.get(attribute).getOrNull() | ||
|
|
||
| init { | ||
| if (actualAttribute == null) Catharsis.error("Unknown attribute $attribute") | ||
| } | ||
|
|
||
| override fun matches(entity: Entity): Boolean { | ||
| if (entity !is LivingEntity) return false | ||
|
|
||
| val attributeInstance = entity.getAttribute(actualAttribute ?: return false) ?: return false | ||
|
|
||
| val attributeValue = attributeInstance.serverValue | ||
|
|
||
| return values.any { it == attributeValue } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fabric has a generic render state injection so maybe that can be used instead of this? idk if its in 1.21.8 though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not :c