aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-03-18 11:01:54 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-03-18 11:01:54 +0200
commitd93d0cf00dc07d3e8b4534d4f6247afcc85232ef (patch)
tree7d028a63010bbc7e5ae2ffb6956ba49f35893838 /defaults/src/main/java
parentdb592ed372f22e71206a6debab11389898c69f01 (diff)
downloadCITResewn-d93d0cf00dc07d3e8b4534d4f6247afcc85232ef.tar.gz
CITResewn-d93d0cf00dc07d3e8b4534d4f6247afcc85232ef.tar.bz2
CITResewn-d93d0cf00dc07d3e8b4534d4f6247afcc85232ef.zip
Rewrote mojank model handling
Fixes #111
Diffstat (limited to 'defaults/src/main/java')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java13
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/BakedModelManagerMixin.java29
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemRendererMixin.java36
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java12
4 files changed, 44 insertions, 46 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
index bd490d3..fe0bafb 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
@@ -500,17 +500,11 @@ public class TypeItem extends CITType {
}
public CIT<TypeItem> getRealTimeCIT(CITContext context) {
- ((CITCacheItem) (Object) context.stack).citresewn$setMojankCITTypeItem(false);
-
Set<CIT<TypeItem>> loadedForItemType = loadedTyped.get(context.stack.getItem());
if (loadedForItemType != null)
for (CIT<TypeItem> cit : loadedForItemType)
- if (cit.test(context)) {
- if (context.stack.isOf(Items.TRIDENT) || context.stack.isOf(Items.SPYGLASS))
- ((CITCacheItem) (Object) context.stack).citresewn$setMojankCITTypeItem(true);
-
+ if (cit.test(context))
return cit;
- }
return null;
}
@@ -518,8 +512,9 @@ public class TypeItem extends CITType {
public interface CITCacheItem {
CITCache.Single<TypeItem> citresewn$getCacheTypeItem();
+ }
- boolean citresewn$isMojankCITTypeItem();
- void citresewn$setMojankCITTypeItem(boolean mojankCIT);
+ public interface BakedModelManagerMixinAccess {
+ void citresewn$forceMojankModel(BakedModel model);
}
} \ No newline at end of file
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/BakedModelManagerMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/BakedModelManagerMixin.java
new file mode 100644
index 0000000..f7f6b48
--- /dev/null
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/BakedModelManagerMixin.java
@@ -0,0 +1,29 @@
+package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.item;
+
+import net.minecraft.client.render.model.BakedModel;
+import net.minecraft.client.render.model.BakedModelManager;
+import net.minecraft.client.util.ModelIdentifier;
+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.defaults.cit.types.TypeItem;
+
+@Mixin(BakedModelManager.class)
+public class BakedModelManagerMixin implements TypeItem.BakedModelManagerMixinAccess {
+ private BakedModel citresewn$forcedMojankModel = null;
+
+ @Inject(method = "getModel", cancellable = true, at =
+ @At("HEAD"))
+ private void citresewn$getCITMojankModel(ModelIdentifier id, CallbackInfoReturnable<BakedModel> cir) {
+ if (citresewn$forcedMojankModel != null) {
+ cir.setReturnValue(citresewn$forcedMojankModel);
+ citresewn$forcedMojankModel = null;
+ }
+ }
+
+ @Override
+ public void citresewn$forceMojankModel(BakedModel model) {
+ this.citresewn$forcedMojankModel = model;
+ }
+}
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemRendererMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemRendererMixin.java
index 4a57445..5f59329 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemRendererMixin.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemRendererMixin.java
@@ -5,7 +5,6 @@ import net.minecraft.client.render.item.ItemModels;
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.ModelIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
@@ -16,7 +15,6 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import shcm.shsupercm.fabric.citresewn.cit.CIT;
@@ -44,39 +42,27 @@ public class ItemRendererMixin {
CITContext context = new CITContext(stack, world, entity);
CIT<TypeItem> cit = CONTAINER.getCIT(context, seed);
+ citresewn$mojankCITModel = null;
if (cit != null) {
BakedModel citModel = cit.type.getItemModel(context, seed);
- if (citModel != null)
- cir.setReturnValue(citModel);
+ if (citModel != null) {
+ if (stack.isOf(Items.TRIDENT) || stack.isOf(Items.SPYGLASS)) {
+ citresewn$mojankCITModel = new WeakReference<>(citModel);
+ } else
+ cir.setReturnValue(citModel);
+ }
}
}
@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$fixMojankCITsContext(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) {
- if (!CONTAINER.active())
+ if (!CONTAINER.active() || citresewn$mojankCITModel == null)
return;
- citresewn$mojankCITModel = null;
- if (((TypeItem.CITCacheItem) (Object) stack).citresewn$isMojankCITTypeItem()) {
- boolean bl = renderMode == ModelTransformation.Mode.GUI || renderMode == ModelTransformation.Mode.GROUND || renderMode == ModelTransformation.Mode.FIXED;
- if (bl)
- citresewn$mojankCITModel = new WeakReference<>(model);
- else { // rendered in hand model of trident/spyglass
- if (stack.isOf(Items.TRIDENT))
- citresewn$mojankCITModel = new WeakReference<>(this.models.getModelManager().getModel(new ModelIdentifier("minecraft:trident_in_hand#inventory")));
- else if (stack.isOf(Items.SPYGLASS))
- citresewn$mojankCITModel = new WeakReference<>(this.models.getModelManager().getModel(new ModelIdentifier("minecraft:spyglass_in_hand#inventory")));
- }
- } else
- citresewn$mojankCITModel = null;
- }
-
- @ModifyVariable(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(value = "LOAD", ordinal = 0, target = "Lnet/minecraft/client/render/model/BakedModel;getTransformation()Lnet/minecraft/client/render/model/json/ModelTransformation;"), argsOnly = true)
- private BakedModel citresewn$fixMojankCITs(BakedModel original) {
- if (CONTAINER.active() && citresewn$mojankCITModel != null)
- return citresewn$mojankCITModel.get();
+ if (renderMode == ModelTransformation.Mode.GUI || renderMode == ModelTransformation.Mode.GROUND || renderMode == ModelTransformation.Mode.FIXED)
+ ((TypeItem.BakedModelManagerMixinAccess) this.models.getModelManager()).citresewn$forceMojankModel(citresewn$mojankCITModel.get());
- return original;
+ citresewn$mojankCITModel = null;
}
}
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java
index 2fb5396..450d8a3 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java
@@ -9,20 +9,8 @@ import shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeItem;
public class ItemStackMixin implements TypeItem.CITCacheItem {
private final CITCache.Single<TypeItem> citresewn$cacheTypeItem = new CITCache.Single<>(TypeItem.CONTAINER::getRealTimeCIT);
- private boolean citresewn$mojankCITTypeItem = false;
-
@Override
public CITCache.Single<TypeItem> citresewn$getCacheTypeItem() {
return this.citresewn$cacheTypeItem;
}
-
- @Override
- public boolean citresewn$isMojankCITTypeItem() {
- return this.citresewn$mojankCITTypeItem;
- }
-
- @Override
- public void citresewn$setMojankCITTypeItem(boolean mojankCITTypeItem) {
- this.citresewn$mojankCITTypeItem = mojankCITTypeItem;
- }
}