diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-02-25 10:36:15 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-02-25 10:36:15 +0200 |
commit | 262d14882ec81115b7a73f0bae055e36488dd580 (patch) | |
tree | fd9a60bd9bf7c393d1fa2b2931720e08c3f6151c /defaults | |
parent | 70b04c19b5c6da9d63a095fb7a2e17fd722c9cb1 (diff) | |
download | CITResewn-262d14882ec81115b7a73f0bae055e36488dd580.tar.gz CITResewn-262d14882ec81115b7a73f0bae055e36488dd580.tar.bz2 CITResewn-262d14882ec81115b7a73f0bae055e36488dd580.zip |
Made the enchantment type work
Diffstat (limited to 'defaults')
5 files changed, 226 insertions, 33 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java index 5fd6e3c..d28f441 100644 --- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java @@ -60,11 +60,9 @@ public class TypeEnchantment extends CITType { @Override public void load(List<CITCondition> conditions, PropertyGroup properties, ResourceManager resourceManager) throws CITParsingException { PropertyValue textureProp = properties.getLastWithoutMetadata("citresewn", "texture"); - if (textureProp == null) - throw new CITParsingException("No texture specified", properties, -1); this.texture = resolveAsset(properties.identifier, textureProp, "textures", ".png", resourceManager); if (this.texture == null) - throw new CITParsingException("Could not resolve texture", properties, textureProp.position()); + throw textureProp == null ? new CITParsingException("No texture specified", properties, -1) : new CITParsingException("Could not resolve texture", properties, textureProp.position()); PropertyValue layerProp = properties.getLastWithoutMetadataOrDefault("0", "citresewn", "layer"); try { @@ -73,13 +71,13 @@ public class TypeEnchantment extends CITType { throw new CITParsingException("Could not parse integer", properties, layerProp.position(), e); } - this.speed = parseFloatOrZero("speed", properties); - this.rotation = parseFloatOrZero("rotation", properties); - this.duration = parseFloatOrZero("duration", properties); - this.r = parseFloatOrZero("r", properties); - this.g = parseFloatOrZero("g", properties); - this.b = parseFloatOrZero("b", properties); - this.a = parseFloatOrZero("a", properties); + this.speed = parseFloatOrDefault(1f, "speed", properties); + this.rotation = parseFloatOrDefault(10f, "rotation", properties); + this.duration = Math.max(0f, parseFloatOrDefault(0f, "duration", properties)); + this.r = Math.max(0f, parseFloatOrDefault(1f, "r", properties)); + this.g = Math.max(0f, parseFloatOrDefault(1f, "g", properties)); + this.b = Math.max(0f, parseFloatOrDefault(1f, "b", properties)); + this.a = Math.max(0f, parseFloatOrDefault(1f, "a", properties)); this.useGlint = Boolean.parseBoolean(properties.getLastWithoutMetadataOrDefault("false", "citresewn", "useGlint").value()); this.blur = Boolean.parseBoolean(properties.getLastWithoutMetadataOrDefault("true", "citresewn", "blur").value()); @@ -92,10 +90,10 @@ public class TypeEnchantment extends CITType { } } - private float parseFloatOrZero(String propertyName, PropertyGroup properties) throws CITParsingException { + private float parseFloatOrDefault(float defaultValue, String propertyName, PropertyGroup properties) throws CITParsingException { PropertyValue property = properties.getLastWithoutMetadata("citresewn", propertyName); if (property == null) - return 0f; + return defaultValue; try { return Float.parseFloat(property.value()); } catch (Exception e) { @@ -112,7 +110,7 @@ public class TypeEnchantment extends CITType { public List<List<CIT<TypeEnchantment>>> loadedLayered = new ArrayList<>(); private List<CIT<TypeEnchantment>> appliedContext = null; - public boolean shouldApply = false; + private boolean apply = false, defaultGlint = false; @Override public void load(List<CIT<TypeEnchantment>> parsedCITs) { @@ -147,11 +145,25 @@ public class TypeEnchantment extends CITType { loadedLayered.clear(); } - public void setContext(CITContext context) { - if (context == null) { - appliedContext = null; - return; - } + public void apply() { + if (appliedContext != null) + apply = true; + } + + public boolean shouldApply() { + return apply; + } + + public boolean shouldNotApplyDefaultGlint() { + return apply && !defaultGlint; + } + + public Container setContext(CITContext context) { + apply = false; + defaultGlint = false; + appliedContext = null; + if (context == null) + return this; List<WeakReference<CIT<TypeEnchantment>>> cits = ((CITCacheEnchantment) (Object) context.stack).citresewn$getCacheTypeEnchantment().get(context); @@ -160,12 +172,17 @@ public class TypeEnchantment extends CITType { for (WeakReference<CIT<TypeEnchantment>> citRef : cits) if (citRef != null) { CIT<TypeEnchantment> cit = citRef.get(); - if (cit != null) + if (cit != null) { appliedContext.add(cit); + if (cit.type.useGlint) + defaultGlint = true; + } } if (appliedContext.isEmpty()) appliedContext = null; + + return this; } public List<CIT<TypeEnchantment>> getRealTimeCIT(CITContext context) { @@ -233,21 +250,37 @@ public class TypeEnchantment extends CITType { } public RenderLayer build(TypeEnchantment enchantment, Identifier propertiesIdentifier) { - final float speed = enchantment.speed, rotation = enchantment.rotation, r = enchantment.r, g = enchantment.g, b = enchantment.b, a = enchantment.a; - final WrappedMethodIntensity methodIntensity = enchantment.methodIntensity; + class Texturing implements Runnable { + private final float speed, rotation, r, g, b, a; + private final WrappedMethodIntensity methodIntensity; + + Texturing(float speed, float rotation, float r, float g, float b, float a, WrappedMethodIntensity methodIntensity) { + this.speed = speed; + this.rotation = rotation; + this.r = r; + this.g = g; + this.b = b; + this.a = a; + this.methodIntensity = methodIntensity; + } + + @Override + public void run() { + float l = Util.getMeasuringTimeMs() * CITResewnDefaultsConfig.INSTANCE.type_enchantment_scroll_multiplier * speed; + float x = (l % 110000f) / 110000f; + float y = (l % 30000f) / 30000f; + Matrix4f matrix4f = Matrix4f.translate(-x, y, 0.0f); + matrix4f.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rotation)); + matrix4f.multiply(Matrix4f.scale(scale, scale, scale)); + setTextureMatrix(matrix4f); + + setShaderColor(r, g, b, a * methodIntensity.intensity); + } + } + RenderLayer.MultiPhaseParameters.Builder layer = RenderLayer.MultiPhaseParameters.builder() .texture(new RenderPhase.Texture(enchantment.texture, enchantment.blur, false)) - .texturing(new RenderPhase.Texturing("citresewn_glint_texturing", () -> { - float l = Util.getMeasuringTimeMs() * CITResewnDefaultsConfig.INSTANCE.type_enchantment_scroll_multiplier * speed; - float x = (l % 110000f) / 110000f; - float y = (l % 30000f) / 30000f; - Matrix4f matrix4f = Matrix4f.translate(-x, y, 0.0f); - matrix4f.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rotation + 10f)); - matrix4f.multiply(Matrix4f.scale(scale, scale, scale)); - setTextureMatrix(matrix4f); - - setShaderColor(r, g, b, a * methodIntensity.intensity); - }, () -> { + .texturing(new RenderPhase.Texturing("citresewn_glint_texturing", new Texturing(enchantment.speed, enchantment.rotation, enchantment.r, enchantment.g, enchantment.b, enchantment.a, enchantment.methodIntensity), () -> { RenderSystem.resetTextureMatrix(); setShaderColor(1f, 1f, 1f, 1f); @@ -264,7 +297,7 @@ public class TypeEnchantment extends CITType { } public VertexConsumer tryApply(VertexConsumer base, RenderLayer baseLayer, VertexConsumerProvider provider) { - if (!CONTAINER.shouldApply || CONTAINER.appliedContext == null || CONTAINER.appliedContext.size() == 0) + if (!CONTAINER.apply || CONTAINER.appliedContext == null || CONTAINER.appliedContext.size() == 0) return null; VertexConsumer[] layers = new VertexConsumer[Math.min(CONTAINER.appliedContext.size(), Integer.MAX_VALUE /*todo cap global property*/)]; diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ArmorFeatureRendererMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ArmorFeatureRendererMixin.java new file mode 100644 index 0000000..272463b --- /dev/null +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ArmorFeatureRendererMixin.java @@ -0,0 +1,32 @@ +package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.enchantment; + +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; +import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +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; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +import shcm.shsupercm.fabric.citresewn.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; + +import static shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeEnchantment.CONTAINER; + +@Mixin(ArmorFeatureRenderer.class) +public class ArmorFeatureRendererMixin<T extends LivingEntity, M extends BipedEntityModel<T>, A extends BipedEntityModel<T>> { + @Inject(method = "renderArmor", at = @At("HEAD")) + private void citresewn$enchantment$setAppliedContextAndStartApplyingArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T livingEntity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { + if (CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive()) + CONTAINER.setContext(new CITContext(livingEntity.getEquippedStack(armorSlot), livingEntity.world, livingEntity)).apply(); + } + + @Inject(method = "renderArmor", at = @At("RETURN")) + private void citresewn$enchantment$stopApplyingArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T livingEntity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { + if (CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive()) + CONTAINER.setContext(null); + } +} diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ElytraFeatureRendererMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ElytraFeatureRendererMixin.java new file mode 100644 index 0000000..4966e6f --- /dev/null +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ElytraFeatureRendererMixin.java @@ -0,0 +1,31 @@ +package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.enchantment; + +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 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; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +import shcm.shsupercm.fabric.citresewn.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; + +import static shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeEnchantment.CONTAINER; + +@Mixin(ElytraFeatureRenderer.class) +public class ElytraFeatureRendererMixin { + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("HEAD")) + private void citresewn$enchantment$setAppliedContextAndStartApplyingElytra(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()) + CONTAINER.setContext(new CITContext(livingEntity.getEquippedStack(EquipmentSlot.CHEST), livingEntity.world, livingEntity)).apply(); + } + + @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("RETURN")) + private void citresewn$enchantment$stopApplyingElytra(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()) + CONTAINER.setContext(null); + } +} diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemRendererMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemRendererMixin.java new file mode 100644 index 0000000..138e7f9 --- /dev/null +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemRendererMixin.java @@ -0,0 +1,88 @@ +package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.enchantment; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.*; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.json.ModelTransformation; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +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; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.cit.ActiveCITs; +import shcm.shsupercm.fabric.citresewn.cit.CITContext; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; +import shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeEnchantment; + +import static shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeEnchantment.CONTAINER; + +@Mixin(value = ItemRenderer.class, priority = 200) +public class ItemRendererMixin { + @Inject(method = "getModel", at = @At("HEAD")) + private void citresewn$enchantment$setAppliedContext(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { + if (CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive()) + CONTAINER.setContext(new CITContext(stack, world, entity)); + } + + @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("HEAD")) + private void citresewn$enchantment$startApplyingItem(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { + if (CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive()) + CONTAINER.apply(); + } + + @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("RETURN")) + private void citresewn$enchantment$stopApplyingItem(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { + if (CITResewnConfig.INSTANCE.enabled && ActiveCITs.isActive()) + CONTAINER.setContext(null); + } + + @Inject(method = "getArmorGlintConsumer", cancellable = true, at = @At("RETURN")) + private static void citresewn$enchantment$getArmorGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> cir) { + if (!CONTAINER.shouldApply()) + return; + VertexConsumer vertexConsumer = solid ? TypeEnchantment.GlintRenderLayer.ARMOR_GLINT.tryApply(cir.getReturnValue(), layer, provider) : TypeEnchantment.GlintRenderLayer.ARMOR_ENTITY_GLINT.tryApply(cir.getReturnValue(), layer, provider); + if (vertexConsumer != null) + cir.setReturnValue(vertexConsumer); + } + + @Inject(method = "getCompassGlintConsumer", cancellable = true, at = @At("RETURN")) + private static void citresewn$enchantment$getCompassGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, MatrixStack.Entry entry, CallbackInfoReturnable<VertexConsumer> cir) { + if (!CONTAINER.shouldApply()) + return; + VertexConsumer vertexConsumer = TypeEnchantment.GlintRenderLayer.GLINT.tryApply(null, layer, provider); + if (vertexConsumer != null) + cir.setReturnValue(VertexConsumers.union(new OverlayVertexConsumer(vertexConsumer, entry.getPositionMatrix(), entry.getNormalMatrix()), cir.getReturnValue())); + } + + @Inject(method = "getDirectCompassGlintConsumer", cancellable = true, at = @At("RETURN")) + private static void citresewn$enchantment$getDirectCompassGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, MatrixStack.Entry entry, CallbackInfoReturnable<VertexConsumer> cir) { + if (!CONTAINER.shouldApply()) + return; + VertexConsumer vertexConsumer = TypeEnchantment.GlintRenderLayer.DIRECT_GLINT.tryApply(null, layer, provider); + if (vertexConsumer != null) + cir.setReturnValue(VertexConsumers.union(new OverlayVertexConsumer(vertexConsumer, entry.getPositionMatrix(), entry.getNormalMatrix()), cir.getReturnValue())); + } + + @Inject(method = "getItemGlintConsumer", cancellable = true, at = @At("RETURN")) + private static void citresewn$enchantment$getItemGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> cir) { + if (!CONTAINER.shouldApply()) + return; + VertexConsumer vertexConsumer = MinecraftClient.isFabulousGraphicsOrBetter() && layer == TexturedRenderLayers.getItemEntityTranslucentCull() ? TypeEnchantment.GlintRenderLayer.GLINT_TRANSLUCENT.tryApply(cir.getReturnValue(), layer, provider) : (solid ? TypeEnchantment.GlintRenderLayer.GLINT.tryApply(cir.getReturnValue(), layer, provider) : TypeEnchantment.GlintRenderLayer.ENTITY_GLINT.tryApply(cir.getReturnValue(), layer, provider)); + if (vertexConsumer != null) + cir.setReturnValue(vertexConsumer); + } + + @Inject(method = "getDirectItemGlintConsumer", cancellable = true, at = @At("RETURN")) + private static void citresewn$enchantment$getDirectItemGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> cir) { + if (!CONTAINER.shouldApply()) + return; + VertexConsumer vertexConsumer = solid ? TypeEnchantment.GlintRenderLayer.DIRECT_GLINT.tryApply(cir.getReturnValue(), layer, provider) : TypeEnchantment.GlintRenderLayer.DIRECT_ENTITY_GLINT.tryApply(cir.getReturnValue(), layer, provider); + if (vertexConsumer != null) + cir.setReturnValue(vertexConsumer); + } +}
\ No newline at end of file diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java index bbd61d9..d49e116 100644 --- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java @@ -2,6 +2,9 @@ package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.enchantment; import net.minecraft.item.ItemStack; 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.CallbackInfoReturnable; import shcm.shsupercm.fabric.citresewn.cit.CITCache; import shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeEnchantment; @@ -13,4 +16,10 @@ public class ItemStackMixin implements TypeEnchantment.CITCacheEnchantment { public CITCache.MultiList<TypeEnchantment> citresewn$getCacheTypeEnchantment() { return this.citresewn$cacheTypeEnchantment; } + + @Inject(method = "hasGlint", cancellable = true, at = @At("HEAD")) + private void citresewn$enchantment$disableDefaultGlint(CallbackInfoReturnable<Boolean> cir) { + if (TypeEnchantment.CONTAINER.shouldNotApplyDefaultGlint()) + cir.setReturnValue(false); + } } |