diff options
4 files changed, 88 insertions, 5 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeElytra.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeElytra.java index 1b5367b..d50d084 100644 --- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeElytra.java +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeElytra.java @@ -2,14 +2,15 @@ package shcm.shsupercm.fabric.citresewn.defaults.cit.types; import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer; -import shcm.shsupercm.fabric.citresewn.cit.CIT; -import shcm.shsupercm.fabric.citresewn.cit.CITCondition; -import shcm.shsupercm.fabric.citresewn.cit.CITType; +import shcm.shsupercm.fabric.citresewn.cit.*; +import shcm.shsupercm.fabric.citresewn.defaults.cit.conditions.ConditionItems; import shcm.shsupercm.fabric.citresewn.ex.CITParsingException; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup; import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -17,6 +18,8 @@ public class TypeElytra extends CITType { @Entrypoint(CITTypeContainer.ENTRYPOINT) public static final Container CONTAINER = new Container(); + public Identifier texture; + @Override public Set<PropertyKey> typeProperties() { return Set.of(PropertyKey.of("texture")); @@ -24,7 +27,12 @@ public class TypeElytra extends CITType { @Override public void load(List<CITCondition> conditions, PropertyGroup properties, ResourceManager resourceManager) throws CITParsingException { + if (conditions.removeIf(condition -> condition instanceof ConditionItems)) + warn("Type elytra does not support the items condition", null, properties); + texture = resolveAsset(properties.identifier, properties.getLastWithoutMetadata("citresewn", "texture"), "textures", ".png", resourceManager); + if (texture == null) + throw new CITParsingException("Texture not specified", properties, -1); } public static class Container extends CITTypeContainer<TypeElytra> { @@ -32,14 +40,32 @@ public class TypeElytra extends CITType { super(TypeElytra.class, TypeElytra::new, "elytra"); } + public Set<CIT<TypeElytra>> loaded = new HashSet<>(); + @Override public void load(List<CIT<TypeElytra>> parsedCITs) { - + loaded.addAll(parsedCITs); } @Override public void dispose() { + loaded.clear(); + } + public CIT<TypeElytra> getCIT(CITContext context) { + return ((CITCacheElytra) (Object) context.stack).citresewn$getCacheTypeElytra().get(context).get(); } + + public CIT<TypeElytra> getRealTimeCIT(CITContext context) { + for (CIT<TypeElytra> cit : loaded) + if (cit.test(context)) + return cit; + + return null; + } + } + + public interface CITCacheElytra { + CITCache.Single<TypeElytra> citresewn$getCacheTypeElytra(); } } diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/elytra/ElytraFeatureRendererMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/elytra/ElytraFeatureRendererMixin.java new file mode 100644 index 0000000..ab4d420 --- /dev/null +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/elytra/ElytraFeatureRendererMixin.java @@ -0,0 +1,41 @@ +package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.elytra; + +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.item.Items; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +import shcm.shsupercm.fabric.citresewn.cit.CIT; +import shcm.shsupercm.fabric.citresewn.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; +import shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeElytra; + +import static shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeElytra.CONTAINER; + +@Mixin(ElytraFeatureRenderer.class) +public class ElytraFeatureRendererMixin { + @Shadow @Mutable @Final private static Identifier SKIN; + + private final static Identifier citresewn$ORIGINAL_SKIN = SKIN; + + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("HEAD")) + public void citresewn$render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { + if (!CITResewnConfig.INSTANCE.enabled || !ActiveCITs.isActive()) + return; + + ItemStack equippedStack = livingEntity.getEquippedStack(EquipmentSlot.CHEST); + if (!equippedStack.isOf(Items.ELYTRA)) + return; + + CIT<TypeElytra> cit = CONTAINER.getCIT(new CITContext(equippedStack, livingEntity.getWorld(), livingEntity)); + SKIN = cit == null ? citresewn$ORIGINAL_SKIN : cit.type.texture; + } +}
\ No newline at end of file diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/elytra/ItemStackMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/elytra/ItemStackMixin.java new file mode 100644 index 0000000..a751fb9 --- /dev/null +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/elytra/ItemStackMixin.java @@ -0,0 +1,16 @@ +package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.elytra; + +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import shcm.shsupercm.fabric.citresewn.cit.CITCache; +import shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeElytra; + +@Mixin(ItemStack.class) +public class ItemStackMixin implements TypeElytra.CITCacheElytra { + private final CITCache.Single<TypeElytra> citresewn$cacheTypeElytra = new CITCache.Single<>(TypeElytra.CONTAINER::getRealTimeCIT); + + @Override + public CITCache.Single<TypeElytra> citresewn$getCacheTypeElytra() { + return this.citresewn$cacheTypeElytra; + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java index 468c1cb..c3bb134 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/cit/CITType.java @@ -16,7 +16,7 @@ public abstract class CITType { public abstract void load(List<CITCondition> conditions, PropertyGroup properties, ResourceManager resourceManager) throws CITParsingException; protected void warn(String message, PropertyValue value, PropertyGroup properties) { - CITResewn.logWarnLoading("Warning: " + CITParsingException.descriptionOf(message, properties, value.position())); + CITResewn.logWarnLoading("Warning: " + CITParsingException.descriptionOf(message, properties, value == null ? -1 : value.position())); } /** |