aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-08-28 15:12:37 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-08-28 15:12:37 +0300
commitebf4f4e5bd294b82538de18cdf4c6c2de39a35f6 (patch)
tree79cb6f6eeb773ee6c975d30dbeaa4d0d8f7ff583
parentd5228ab2f1d1ecc36cae0fa056c575c4d85d3b56 (diff)
downloadCITResewn-ebf4f4e5bd294b82538de18cdf4c6c2de39a35f6.tar.gz
CITResewn-ebf4f4e5bd294b82538de18cdf4c6c2de39a35f6.tar.bz2
CITResewn-ebf4f4e5bd294b82538de18cdf4c6c2de39a35f6.zip
v0.2.0: Added type=elytra support
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java9
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java46
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java2
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java9
-rw-r--r--src/main/resources/citresewn.mixins.json1
6 files changed, 67 insertions, 2 deletions
diff --git a/gradle.properties b/gradle.properties
index a7fa024..2eafb12 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,7 +6,7 @@ minecraft_version=1.17.1
yarn_mappings=1.17.1+build.39
loader_version=0.11.6
# Mod Properties
-mod_version=0.1
+mod_version=0.2.0
maven_group=shcm.shsupercm.fabric
archives_base_name=CITResewn
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
index 769749d..9a58a9d 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
@@ -6,6 +6,7 @@ import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
+import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import shcm.shsupercm.fabric.citresewn.pack.cits.*;
@@ -66,4 +67,12 @@ public class ActiveCITs {
return bakedModel;
}
+
+ public Identifier getElytraTexture(ItemStack stack, World world, LivingEntity livingEntity) {
+ for (CITElytra citElytra : citElytra)
+ if (citElytra.test(stack, Hand.MAIN_HAND, world, livingEntity))
+ return citElytra.textureIdentifier;
+
+ return null;
+ }
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java
new file mode 100644
index 0000000..39dfa73
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java
@@ -0,0 +1,46 @@
+package shcm.shsupercm.fabric.citresewn.mixin;
+
+import net.minecraft.client.render.RenderLayer;
+import net.minecraft.client.render.VertexConsumerProvider;
+import net.minecraft.client.render.entity.feature.ElytraFeatureRenderer;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.entity.EquipmentSlot;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.Identifier;
+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.Redirect;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import shcm.shsupercm.fabric.citresewn.CITResewn;
+
+import java.lang.ref.WeakReference;
+
+@Mixin(ElytraFeatureRenderer.class)
+public class ElytraFeatureRendererMixin {
+ private WeakReference<ItemStack> elytraItemCached = new WeakReference<>(null);
+ private WeakReference<LivingEntity> livingEntityCached = new WeakReference<>(null);
+
+ @Inject(method = "render", cancellable = true, at = @At("HEAD"))
+ public void injectCIT(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) {
+ if (CITResewn.INSTANCE.activeCITs == null)
+ return;
+
+ this.elytraItemCached = new WeakReference<>(livingEntity.getEquippedStack(EquipmentSlot.CHEST));
+ this.livingEntityCached = new WeakReference<>(livingEntity);
+ }
+
+ @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getArmorCutoutNoCull(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;"))
+ public RenderLayer getArmorCutoutNoCull(Identifier originalIdentifier) {
+ ItemStack itemStack = this.elytraItemCached.get();
+ LivingEntity livingEntity = livingEntityCached.get();
+ if (itemStack != null && livingEntity != null) {
+ Identifier elytraTexture = CITResewn.INSTANCE.activeCITs.getElytraTexture(itemStack, livingEntity.world, livingEntity);
+ if (elytraTexture != null)
+ return RenderLayer.getArmorCutoutNoCull(elytraTexture);
+ }
+
+ return RenderLayer.getArmorCutoutNoCull(originalIdentifier);
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java
index fd593ee..f2c15ec 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java
@@ -14,7 +14,7 @@ import shcm.shsupercm.fabric.citresewn.CITResewn;
@Mixin(ItemRenderer.class)
public class ItemRendererMixin {
@Inject(method = "getHeldItemModel", cancellable = true, at = @At("RETURN"))
- public void getItemModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) {
+ public void injectCIT(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) {
if (CITResewn.INSTANCE.activeCITs == null)
return;
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
index e09e4fb..8c5bea8 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
@@ -7,7 +7,16 @@ import shcm.shsupercm.fabric.citresewn.pack.CITPack;
import java.util.Properties;
public class CITElytra extends CIT {
+ public final Identifier textureIdentifier;
+
public CITElytra(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
super(pack, identifier, properties);
+ try {
+ textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", pack.resourcePack);
+ if (textureIdentifier == null)
+ throw new Exception("Cannot resolve texture");
+ } catch (Exception e) {
+ throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage());
+ }
}
}
diff --git a/src/main/resources/citresewn.mixins.json b/src/main/resources/citresewn.mixins.json
index fe412be..22f06a1 100644
--- a/src/main/resources/citresewn.mixins.json
+++ b/src/main/resources/citresewn.mixins.json
@@ -4,6 +4,7 @@
"package": "shcm.shsupercm.fabric.citresewn.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
+ "ElytraFeatureRendererMixin",
"IdentifierMixin",
"ItemRendererMixin",
"JsonUnbakedModelAccessor",