diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-02-13 12:49:48 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-02-13 12:49:48 +0200 |
commit | cf735c9f3205208801a9675e6b6217dc84b1ea3c (patch) | |
tree | dc2ac518c145668343593952d6256327a35c7e87 /defaults/src/main/java/shcm | |
parent | fe02178b220ebf57225bd092bfdb0d8b88067c33 (diff) | |
download | CITResewn-cf735c9f3205208801a9675e6b6217dc84b1ea3c.tar.gz CITResewn-cf735c9f3205208801a9675e6b6217dc84b1ea3c.tar.bz2 CITResewn-cf735c9f3205208801a9675e6b6217dc84b1ea3c.zip |
Implemented caching
Diffstat (limited to 'defaults/src/main/java/shcm')
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; + } +} |