aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java/shcm/shsupercm/fabric
diff options
context:
space:
mode:
Diffstat (limited to 'defaults/src/main/java/shcm/shsupercm/fabric')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java22
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java16
2 files changed, 35 insertions, 3 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 1b0e98e..730c713 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
@@ -3,11 +3,9 @@ package shcm.shsupercm.fabric.citresewn.defaults.cit.types;
import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint;
import net.minecraft.item.Item;
import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer;
+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.cit.CIT;
-import shcm.shsupercm.fabric.citresewn.cit.CITCondition;
-import shcm.shsupercm.fabric.citresewn.cit.CITType;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import java.util.*;
@@ -42,5 +40,23 @@ public class TypeItem extends CITType {
public void dispose() {
loaded.clear();
}
+
+ public CIT<TypeItem> getCIT(CITContext context) {
+ return ((CITCacheItem) (Object) context.stack).citresewn$getCacheTypeItem().get(context).get();
+ }
+
+ public CIT<TypeItem> getRealTimeCIT(CITContext context) {
+ Set<CIT<TypeItem>> loadedForItemType = loaded.get(context.stack.getItem());
+ if (loadedForItemType != null)
+ for (CIT<TypeItem> cit : loadedForItemType)
+ if (cit.test(context))
+ return cit;
+
+ return null;
+ }
+ }
+
+ public interface CITCacheItem {
+ CITCache.Single<TypeItem> citresewn$getCacheTypeItem();
}
} \ No newline at end of file
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
new file mode 100644
index 0000000..450d8a3
--- /dev/null
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ItemStackMixin.java
@@ -0,0 +1,16 @@
+package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.item;
+
+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.TypeItem;
+
+@Mixin(ItemStack.class)
+public class ItemStackMixin implements TypeItem.CITCacheItem {
+ private final CITCache.Single<TypeItem> citresewn$cacheTypeItem = new CITCache.Single<>(TypeItem.CONTAINER::getRealTimeCIT);
+
+ @Override
+ public CITCache.Single<TypeItem> citresewn$getCacheTypeItem() {
+ return this.citresewn$cacheTypeItem;
+ }
+}