aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-01-11 05:24:52 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-01-11 05:24:52 +0200
commitb6267ae1baa035c9315fcab213b9831351b579c8 (patch)
treef939e563fffdbaf5a99a0080f88197f46b83b43d /src
parent3281ac93e02de78286cef4c98e86dcdde84e84d6 (diff)
downloadCITResewn-b6267ae1baa035c9315fcab213b9831351b579c8.tar.gz
CITResewn-b6267ae1baa035c9315fcab213b9831351b579c8.tar.bz2
CITResewn-b6267ae1baa035c9315fcab213b9831351b579c8.zip
Added support for average and layered enchantment merging methods
Diffstat (limited to 'src')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java3
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java10
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java79
3 files changed, 84 insertions, 8 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
index 0efd6f9..6362764 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
@@ -179,6 +179,9 @@ public class ActiveCITs {
return;
}
+ for (CITEnchantment cit : citEnchantments)
+ cit.applyMethod(stack);
+
CITEnchantment.appliedContext = citEnchantments;
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
index 59f1659..aadf518 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
@@ -2,6 +2,7 @@ package shcm.shsupercm.fabric.citresewn.pack;
import net.minecraft.resource.ResourcePack;
import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
+import shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment;
import java.util.*;
@@ -9,7 +10,7 @@ public class CITPack {
public final ResourcePack resourcePack;
public final Collection<CIT> cits = new ArrayList<>();
- public EnchantmentMergeMethod method = EnchantmentMergeMethod.AVERAGE;
+ public CITEnchantment.MergeMethod method = CITEnchantment.MergeMethod.AVERAGE;
public Integer cap = 8;
public Float fade = 0.5f;
public Boolean useGlint = true;
@@ -20,7 +21,7 @@ public class CITPack {
public void loadGlobalProperties(Properties properties) throws Exception {
try {
- this.method = properties.containsKey("method") ? CITPack.EnchantmentMergeMethod.valueOf(properties.getProperty("method").toUpperCase(Locale.ENGLISH)) : null;
+ this.method = properties.containsKey("method") ? CITEnchantment.MergeMethod.valueOf(properties.getProperty("method").toUpperCase(Locale.ENGLISH)) : null;
if (properties.containsKey("cap")) {
this.cap = Integer.parseInt(properties.getProperty("cap"));
@@ -61,9 +62,4 @@ public class CITPack {
this.useGlint = properties.useGlint;
}
- public enum EnchantmentMergeMethod {
- AVERAGE,
- LAYERED,
- CYCLE
- }
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
index d738570..759d6cc 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
@@ -3,6 +3,12 @@ package shcm.shsupercm.fabric.citresewn.pack.cits;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*;
+import net.minecraft.enchantment.EnchantmentHelper;
+import net.minecraft.item.EnchantedBookItem;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
+import net.minecraft.nbt.NbtCompound;
+import net.minecraft.nbt.NbtElement;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
@@ -33,6 +39,9 @@ public class CITEnchantment extends CIT {
public final boolean useGlint, blur;
public final Blend blend;
+ private final WrappedMethodIntensity methodIntensity = new WrappedMethodIntensity();
+ private final MergeMethod method;
+
public final Map<GlintRenderLayer, RenderLayer> renderLayers = new EnumMap<>(GlintRenderLayer.class);
public CITEnchantment(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
@@ -68,6 +77,8 @@ public class CITEnchantment extends CIT {
};
blend = Blend.getBlend(properties.getProperty("blend", "add"));
+
+ method = !enchantmentsAny && this.enchantments.size() > 0 ? pack.method : null;
} catch (Exception e) {
throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage());
}
@@ -82,6 +93,17 @@ public class CITEnchantment extends CIT {
}
}
+ public void applyMethod(ItemStack stack) {
+ if (this.method != null) {
+ Map<Identifier, Integer> stackEnchantments = new LinkedHashMap<>();
+ for (NbtElement nbtElement : stack.isOf(Items.ENCHANTED_BOOK) ? EnchantedBookItem.getEnchantmentNbt(stack) : stack.getEnchantments())
+ stackEnchantments.put(EnchantmentHelper.getIdFromNbt((NbtCompound) nbtElement), EnchantmentHelper.getLevelFromNbt((NbtCompound) nbtElement));
+
+ this.methodIntensity.intensity = this.method.getIntensity(stackEnchantments, this);
+ } else
+ this.methodIntensity.intensity = 1f;
+ }
+
@Override
public void dispose() {
appliedContext = null;
@@ -142,6 +164,7 @@ public class CITEnchantment extends CIT {
public RenderLayer build(CITEnchantment enchantment) {
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;
//noinspection ConstantConditions
RenderLayer.MultiPhaseParameters.Builder layer = RenderLayer.MultiPhaseParameters.builder()
.texture(new RenderPhase.Texture(enchantment.textureIdentifier, enchantment.blur, false))
@@ -154,7 +177,7 @@ public class CITEnchantment extends CIT {
matrix4f.multiply(Matrix4f.scale(scale, scale, scale));
setTextureMatrix(matrix4f);
- setShaderColor(r, g, b, a);
+ setShaderColor(r, g, b, a * methodIntensity.intensity);
}, () -> {
RenderSystem.resetTextureMatrix();
@@ -279,6 +302,60 @@ public class CITEnchantment extends CIT {
}
}
+ public enum MergeMethod {
+ AVERAGE {
+ @Override
+ public float getIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit) {
+ Identifier enchantment = null;
+ for (Identifier enchantmentMatch : cit.enchantments)
+ if (stackEnchantments.containsKey(enchantmentMatch)) {
+ enchantment = enchantmentMatch;
+ break;
+ }
+ if (enchantment == null)
+ return 0f;
+
+ float sum = 0f;
+ for (Integer value : stackEnchantments.values())
+ sum += value;
+
+ return (float) stackEnchantments.get(enchantment) / sum;
+ }
+ },
+ LAYERED {
+ @Override
+ public float getIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit) {
+ Identifier enchantment = null;
+ for (Identifier enchantmentMatch : cit.enchantments)
+ if (stackEnchantments.containsKey(enchantmentMatch)) {
+ enchantment = enchantmentMatch;
+ break;
+ }
+ if (enchantment == null)
+ return 0f;
+
+ float max = 0f;
+ for (Integer value : stackEnchantments.values())
+ if (value > max)
+ max = value;
+
+ return (float) stackEnchantments.get(enchantment) / max;
+ }
+ },
+ CYCLE {
+ @Override
+ public float getIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit) {
+ return 1f;
+ }
+ };
+
+ public abstract float getIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit);
+ }
+
+ private static class WrappedMethodIntensity {
+ public float intensity = 1f;
+ }
+
public interface Cached {
List<CITEnchantment> citresewn_getCachedCITEnchantment(Supplier<List<CITEnchantment>> realtime);
}