-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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,19 @@ | ||
# Resource Packs | ||
|
||
The cuddling animation this mod uses is available for | ||
external resource packs to make use of in their own models. | ||
You can add the `huggable` property to any item model definition to | ||
make it use this custom arm position. | ||
|
||
```json | ||
{ | ||
"huggable": true, | ||
"parent": ..., | ||
"textures": { | ||
... | ||
}, | ||
"elements": [ | ||
... | ||
] | ||
} | ||
``` |
This file contains 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 |
---|---|---|
@@ -1,29 +1,14 @@ | ||
package dev.enjarai.blahajtotem; | ||
|
||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; | ||
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; | ||
import dev.enjarai.blahajtotem.pond.BakedHuggableModel; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
|
||
public class BlahajFlags implements IdentifiableResourceReloadListener, SimpleSynchronousResourceReloadListener { | ||
public static boolean defaultToTotem = false; | ||
|
||
public static boolean isBlahaj(ItemStack itemStack) { | ||
if (itemStack.isOf(Items.TOTEM_OF_UNDYING)) { | ||
return !BlahajFlags.defaultToTotem || BlahajTotem.getShorkType(itemStack) != null; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Identifier getFabricId() { | ||
return BlahajTotem.id("flags"); | ||
} | ||
|
||
@Override | ||
public void reload(ResourceManager manager) { | ||
defaultToTotem = manager.getResource(BlahajTotem.id("default_to_totem")).isPresent(); | ||
public class BlahajFlags { | ||
public static boolean isHuggable(ItemStack itemStack, LivingEntity entity) { | ||
var model = MinecraftClient.getInstance().getItemRenderer().getModel(itemStack, entity.getWorld(), entity, 0); | ||
return model instanceof BakedHuggableModel huggableModel && huggableModel.blahaj_totem$isHuggable(); | ||
} | ||
} |
This file contains 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
22 changes: 22 additions & 0 deletions
22
src/main/java/dev/enjarai/blahajtotem/mixin/BasicBakedModelMixin.java
This file contains 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 dev.enjarai.blahajtotem.mixin; | ||
|
||
import dev.enjarai.blahajtotem.pond.BakedHuggableModel; | ||
import net.minecraft.client.render.model.BasicBakedModel; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(BasicBakedModel.class) | ||
public class BasicBakedModelMixin implements BakedHuggableModel { | ||
@Unique | ||
private boolean huggable; | ||
|
||
@Override | ||
public void blahaj_totem$setHuggable(boolean huggable) { | ||
this.huggable = huggable; | ||
} | ||
|
||
@Override | ||
public boolean blahaj_totem$isHuggable() { | ||
return huggable; | ||
} | ||
} |
This file contains 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
25 changes: 25 additions & 0 deletions
25
src/main/java/dev/enjarai/blahajtotem/mixin/JsonUnbakedModel$DeserializerMixin.java
This file contains 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,25 @@ | ||
package dev.enjarai.blahajtotem.mixin; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import dev.enjarai.blahajtotem.pond.UnbakedHuggableModel; | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel; | ||
import net.minecraft.util.JsonHelper; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(JsonUnbakedModel.Deserializer.class) | ||
public class JsonUnbakedModel$DeserializerMixin { | ||
@ModifyReturnValue( | ||
method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/client/render/model/json/JsonUnbakedModel;", | ||
at = @At("RETURN") | ||
) | ||
private JsonUnbakedModel deserializeAdditionalField(JsonUnbakedModel original, @Local(argsOnly = true) JsonElement element) { | ||
if (element.getAsJsonObject().has("huggable")) { | ||
((UnbakedHuggableModel) original).blahaj_totem$setHuggable( | ||
JsonHelper.getBoolean(element.getAsJsonObject(), "huggable")); | ||
} | ||
return original; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/dev/enjarai/blahajtotem/mixin/JsonUnbakedModelMixin.java
This file contains 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,46 @@ | ||
package dev.enjarai.blahajtotem.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import dev.enjarai.blahajtotem.pond.BakedHuggableModel; | ||
import dev.enjarai.blahajtotem.pond.UnbakedHuggableModel; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(JsonUnbakedModel.class) | ||
public class JsonUnbakedModelMixin implements UnbakedHuggableModel { | ||
@Shadow @Nullable protected JsonUnbakedModel parent; | ||
@Unique @Nullable | ||
private Boolean huggable; | ||
|
||
@Override | ||
public void blahaj_totem$setHuggable(boolean huggable) { | ||
this.huggable = huggable; | ||
} | ||
|
||
@Override | ||
public boolean blahaj_totem$isHuggable() { | ||
if (huggable != null) { | ||
return huggable; | ||
} else if (parent != null) { | ||
return ((UnbakedHuggableModel) parent).blahaj_totem$isHuggable(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@ModifyReturnValue( | ||
method = "bake(Lnet/minecraft/client/render/model/Baker;Lnet/minecraft/client/render/model/json/JsonUnbakedModel;Ljava/util/function/Function;Lnet/minecraft/client/render/model/ModelBakeSettings;Z)Lnet/minecraft/client/render/model/BakedModel;", | ||
at = @At("RETURN") | ||
) | ||
private BakedModel addFieldToBakedModel(BakedModel original) { | ||
if (original instanceof BakedHuggableModel huggableModel) { | ||
huggableModel.blahaj_totem$setHuggable(blahaj_totem$isHuggable()); | ||
} | ||
return original; | ||
} | ||
} |
This file contains 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
6 changes: 6 additions & 0 deletions
6
src/main/java/dev/enjarai/blahajtotem/pond/BakedHuggableModel.java
This file contains 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,6 @@ | ||
package dev.enjarai.blahajtotem.pond; | ||
|
||
public interface BakedHuggableModel { | ||
void blahaj_totem$setHuggable(boolean huggable); | ||
boolean blahaj_totem$isHuggable(); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/dev/enjarai/blahajtotem/pond/UnbakedHuggableModel.java
This file contains 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,6 @@ | ||
package dev.enjarai.blahajtotem.pond; | ||
|
||
public interface UnbakedHuggableModel { | ||
void blahaj_totem$setHuggable(boolean huggable); | ||
boolean blahaj_totem$isHuggable(); | ||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/assets/blahaj_totem/models/item/astolfo_bean.json
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"huggable": true, | ||
"credit": "Made by Crephan", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"huggable": true, | ||
"credit": "Made by Crephan", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"huggable": true, | ||
"credit": "Made by Crephan", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"huggable": true, | ||
"texture_size": [32, 32], | ||
"textures": { | ||
"0": "blahaj_totem:item/blahaj_skins/shark_shark", | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"huggable": true, | ||
"credit": "Made with Blockbench", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
|
This file contains 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
Empty file.