├── .github └── workflows │ ├── publish.yml │ └── validate.yml ├── .gitignore ├── .idea └── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── extra_jar_def.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── guidelines ├── lba.checkstyle └── lba.importorder ├── javadoc.options ├── misc └── LICENSE_HEADER.txt ├── settings.gradle └── src ├── fatjar ├── java │ └── alexiil │ │ └── mc │ │ └── lib │ │ └── attributes │ │ └── fatjar │ │ └── FatJarChecker.java └── resources │ ├── LICENSE_FATJAR.txt │ └── LICENSE_WHOLE.txt ├── main ├── java │ └── alexiil │ │ └── mc │ │ └── lib │ │ └── attributes │ │ ├── AbstractAttributeList.java │ │ ├── AggregateFilterType.java │ │ ├── Attribute.java │ │ ├── AttributeCombiner.java │ │ ├── AttributeList.java │ │ ├── AttributeProvider.java │ │ ├── AttributeProviderBlockEntity.java │ │ ├── AttributeProviderItem.java │ │ ├── AttributeSourceType.java │ │ ├── AttributeUtil.java │ │ ├── Attributes.java │ │ ├── BlockEntityAttributeAdder.java │ │ ├── CacheInfo.java │ │ ├── CombinableAttribute.java │ │ ├── CompatLeveledMap.java │ │ ├── Convertible.java │ │ ├── CustomAttributeAdder.java │ │ ├── DefaultedAttribute.java │ │ ├── ItemAttributeAdder.java │ │ ├── ItemAttributeList.java │ │ ├── ListenerRemovalToken.java │ │ ├── ListenerToken.java │ │ ├── NullAttributeAdder.java │ │ ├── SearchOption.java │ │ ├── SearchOptionDirectional.java │ │ ├── SearchOptionDirectionalVoxel.java │ │ ├── SearchOptionInVoxel.java │ │ ├── SearchOptions.java │ │ ├── Simulation.java │ │ ├── fluid │ │ ├── FixedFluidInv.java │ │ ├── FixedFluidInvView.java │ │ ├── FluidAttributes.java │ │ ├── FluidContainerRegistry.java │ │ ├── FluidExtractable.java │ │ ├── FluidInsertable.java │ │ ├── FluidInvAmountChangeListener.java │ │ ├── FluidInvAmountChangeListener_F.java │ │ ├── FluidInvTankChangeListener.java │ │ ├── FluidInvUtil.java │ │ ├── FluidItemBase.java │ │ ├── FluidItemUtil.java │ │ ├── FluidProviderItem.java │ │ ├── FluidTransferable.java │ │ ├── FluidVolumeUtil.java │ │ ├── GroupedFluidInv.java │ │ ├── GroupedFluidInvView.java │ │ ├── ICustomBucketItem.java │ │ ├── LbaFluidsConfig.java │ │ ├── LimitedFixedFluidInv.java │ │ ├── LimitedGroupedFluidInv.java │ │ ├── SingleFluidTank.java │ │ ├── SingleFluidTankView.java │ │ ├── amount │ │ │ ├── BigFluidAmount.java │ │ │ ├── FluidAmount.java │ │ │ └── FluidAmountBase.java │ │ ├── compat │ │ │ └── mod │ │ │ │ ├── LbaFluidModCompatLoader.java │ │ │ │ ├── transfer │ │ │ │ ├── TransferFluidApiCompat.java │ │ │ │ └── TransferFluidInvCompatLoader.java │ │ │ │ └── vanilla │ │ │ │ └── VanillaFluidCompat.java │ │ ├── filter │ │ │ ├── AggregateFluidFilter.java │ │ │ ├── ConstantFluidFilter.java │ │ │ ├── ExactFluidFilter.java │ │ │ ├── FluidFilter.java │ │ │ ├── FluidFilterUtil.java │ │ │ ├── FluidInsertableFilter.java │ │ │ ├── FluidSetFilter.java │ │ │ ├── FluidTagFilter.java │ │ │ ├── FluidTypeFilter.java │ │ │ ├── InvertedFluidFilter.java │ │ │ ├── RawFluidTagFilter.java │ │ │ ├── ReadableFluidFilter.java │ │ │ └── ResolvableFluidFilter.java │ │ ├── impl │ │ │ ├── AbstractPartialFixedFluidInvView.java │ │ │ ├── CombinedFixedFluidInv.java │ │ │ ├── CombinedFixedFluidInvView.java │ │ │ ├── CombinedFluidExtractable.java │ │ │ ├── CombinedFluidInsertable.java │ │ │ ├── CombinedGroupedFluidInv.java │ │ │ ├── CombinedGroupedFluidInvView.java │ │ │ ├── DelegatingFixedFluidInv.java │ │ │ ├── DelegatingGroupedFluidInv.java │ │ │ ├── EmptyFixedFluidInv.java │ │ │ ├── EmptyFluidExtractable.java │ │ │ ├── EmptyFluidTransferable.java │ │ │ ├── EmptyGroupedFluidInv.java │ │ │ ├── FilteredFluidExtractable.java │ │ │ ├── FilteredFluidInsertable.java │ │ │ ├── FilteredFluidTransferable.java │ │ │ ├── FluidInvModificationTracker.java │ │ │ ├── GroupedFluidInvFixedWrapper.java │ │ │ ├── GroupedFluidInvViewFixedWrapper.java │ │ │ ├── JumboFixedFluidInv.java │ │ │ ├── MappedFixedFluidInv.java │ │ │ ├── MappedFixedFluidInvView.java │ │ │ ├── RejectingFluidInsertable.java │ │ │ ├── SimpleFixedFluidInv.java │ │ │ ├── SimpleFixedFluidInvExtractable.java │ │ │ ├── SimpleFixedFluidInvInsertable.java │ │ │ ├── SimpleLimitedFixedFluidInv.java │ │ │ ├── SimpleLimitedGroupedFluidInv.java │ │ │ ├── SubFixedFluidInv.java │ │ │ └── SubFixedFluidInvView.java │ │ ├── init │ │ │ ├── ClientFluidInit.java │ │ │ └── LbaFluidProxy.java │ │ ├── item │ │ │ └── ItemBasedSingleFluidInv.java │ │ ├── mixin │ │ │ ├── api │ │ │ │ └── IBucketItem.java │ │ │ └── impl │ │ │ │ ├── BiomeEffectsAccessor.java │ │ │ │ ├── BucketItemMixin.java │ │ │ │ ├── FlowableFluidAccessor.java │ │ │ │ ├── FluidBlockMixin.java │ │ │ │ ├── GlassBottleItemMixin.java │ │ │ │ ├── PotionItemMixin.java │ │ │ │ └── RenderLayerAccessor.java │ │ ├── package-info.java │ │ ├── render │ │ │ ├── DefaultFluidVolumeRenderer.java │ │ │ ├── EnchantmentGlintFluidRenderer.java │ │ │ ├── FluidFaceSplitter.java │ │ │ ├── FluidRenderFace.java │ │ │ ├── FluidVolumeRenderer.java │ │ │ └── ImplicitVanillaFluidVolumeRenderer.java │ │ ├── volume │ │ │ ├── BiomeSourcedFluidKey.java │ │ │ ├── BiomeSourcedFluidVolume.java │ │ │ ├── ColouredFluidKey.java │ │ │ ├── ColouredFluidVolume.java │ │ │ ├── FluidEntry.java │ │ │ ├── FluidKey.java │ │ │ ├── FluidKeyCustomiser.java │ │ │ ├── FluidKeys.java │ │ │ ├── FluidProperty.java │ │ │ ├── FluidRegistryEntry.java │ │ │ ├── FluidTemperature.java │ │ │ ├── FluidTooltipContext.java │ │ │ ├── FluidUnit.java │ │ │ ├── FluidUnitBase.java │ │ │ ├── FluidUnitSet.java │ │ │ ├── FluidVolume.java │ │ │ ├── NormalFluidKey.java │ │ │ ├── NormalFluidVolume.java │ │ │ ├── PotionFluidKey.java │ │ │ ├── PotionFluidVolume.java │ │ │ ├── SimpleFluidKey.java │ │ │ ├── SimpleFluidVolume.java │ │ │ ├── WaterFluidKey.java │ │ │ ├── WaterFluidVolume.java │ │ │ ├── WeightedFluidKey.java │ │ │ └── WeightedFluidVolume.java │ │ └── world │ │ │ ├── FluidWorldUtil.java │ │ │ ├── IFluidBlockMixin.java │ │ │ └── IFluidVolumeDrainable.java │ │ ├── item │ │ ├── AbstractItemInvView.java │ │ ├── FixedItemInv.java │ │ ├── FixedItemInvView.java │ │ ├── GroupedItemInv.java │ │ ├── GroupedItemInvView.java │ │ ├── InvMarkDirtyListener.java │ │ ├── ItemAttributes.java │ │ ├── ItemExtractable.java │ │ ├── ItemInsertable.java │ │ ├── ItemInvAmountChangeListener.java │ │ ├── ItemInvSlotChangeListener.java │ │ ├── ItemInvUtil.java │ │ ├── ItemStackCollections.java │ │ ├── ItemStackUtil.java │ │ ├── ItemTransferable.java │ │ ├── LimitedFixedItemInv.java │ │ ├── LimitedGroupedItemInv.java │ │ ├── SingleCopyingItemSlot.java │ │ ├── SingleItemSlot.java │ │ ├── SingleItemSlotView.java │ │ ├── compat │ │ │ ├── FixedInventoryVanillaWrapper.java │ │ │ ├── FixedInventoryViewVanillaWrapper.java │ │ │ ├── FixedSidedInventoryVanillaWrapper.java │ │ │ ├── InventoryFixedWrapper.java │ │ │ ├── SidedInventoryFixedWrapper.java │ │ │ ├── SlotFixedItemInv.java │ │ │ └── mod │ │ │ │ ├── LbaItemModCompat.java │ │ │ │ ├── dank │ │ │ │ ├── DankItemInvCompat.java │ │ │ │ └── DankItemInvCompatLoader.java │ │ │ │ ├── emi │ │ │ │ ├── iteminv │ │ │ │ │ ├── EmiEmptyItemInventory.java │ │ │ │ │ ├── EmiItemInvCompat.java │ │ │ │ │ ├── EmiItemInvCompatLoader.java │ │ │ │ │ └── FixedInvEmiItemInv.java │ │ │ │ └── package-info.java │ │ │ │ └── transfer │ │ │ │ ├── TransferItemApiCompat.java │ │ │ │ └── TransferItemInvCompatLoader.java │ │ ├── entity │ │ │ ├── ItemEntityAttributeUtil.java │ │ │ ├── ItemExtractableProjectileEntity.java │ │ │ └── ItemTransferableItemEntity.java │ │ ├── filter │ │ │ ├── AggregateItemFilter.java │ │ │ ├── ConstantItemFilter.java │ │ │ ├── ExactItemFilter.java │ │ │ ├── ExactItemSetFilter.java │ │ │ ├── ExactItemStackFilter.java │ │ │ ├── InvertedItemFilter.java │ │ │ ├── ItemClassFilter.java │ │ │ ├── ItemFilter.java │ │ │ ├── ItemInsertableFilter.java │ │ │ ├── ItemStackFilterUtil.java │ │ │ ├── ItemTagFilter.java │ │ │ ├── ReadableItemFilter.java │ │ │ └── ResolvableItemFilter.java │ │ ├── impl │ │ │ ├── AbstractPartialFixedItemInvView.java │ │ │ ├── CombinedFixedItemInv.java │ │ │ ├── CombinedFixedItemInvView.java │ │ │ ├── CombinedGroupedItemInv.java │ │ │ ├── CombinedGroupedItemInvView.java │ │ │ ├── CombinedItemExtractable.java │ │ │ ├── CombinedItemInsertable.java │ │ │ ├── DelegatingFixedItemInv.java │ │ │ ├── DelegatingGroupedItemInv.java │ │ │ ├── DirectFixedItemInv.java │ │ │ ├── EmptyFixedItemInv.java │ │ │ ├── EmptyGroupedItemInv.java │ │ │ ├── EmptyItemExtractable.java │ │ │ ├── EmptyItemTransferable.java │ │ │ ├── FilteredItemExtractable.java │ │ │ ├── FilteredItemInsertable.java │ │ │ ├── FilteredItemTransferable.java │ │ │ ├── FullFixedItemInv.java │ │ │ ├── GroupedItemInvFixedWrapper.java │ │ │ ├── GroupedItemInvViewFixedWrapper.java │ │ │ ├── ItemInvModificationTracker.java │ │ │ ├── MappedFixedItemInv.java │ │ │ ├── MappedFixedItemInvView.java │ │ │ ├── RejectingItemInsertable.java │ │ │ ├── SimpleFixedItemInv.java │ │ │ ├── SimpleFixedItemInvExtractable.java │ │ │ ├── SimpleFixedItemInvInsertable.java │ │ │ ├── SimpleGroupedItemInv.java │ │ │ ├── SimpleLimitedFixedItemInv.java │ │ │ ├── SimpleLimitedGroupedItemInv.java │ │ │ ├── SubFixedItemInv.java │ │ │ └── SubFixedItemInvView.java │ │ └── mixin │ │ │ ├── HopperHooks.java │ │ │ └── impl │ │ │ ├── DropperBlockMixin.java │ │ │ └── HopperBlockEntityMixin.java │ │ ├── misc │ │ ├── AbstractCombined.java │ │ ├── AbstractItemBasedAttribute.java │ │ ├── CallableRef.java │ │ ├── Combined.java │ │ ├── DestroyableRef.java │ │ ├── LibBlockAttributes.java │ │ ├── LimitedConsumer.java │ │ ├── NullVariant.java │ │ ├── OpenWrapper.java │ │ ├── PlayerInvUtil.java │ │ ├── Ref.java │ │ ├── Reference.java │ │ ├── Saveable.java │ │ ├── SimulatableRef.java │ │ ├── StackReference.java │ │ ├── UnmodifiableRef.java │ │ └── compat │ │ │ └── mod │ │ │ └── LbaModCompatLoader.java │ │ └── mixin │ │ ├── api │ │ └── UnloadableBlockEntity.java │ │ └── impl │ │ └── mx │ │ ├── ClientWorldMixin.java │ │ └── ServerWorldMixin.java └── resources │ ├── assets │ ├── libblockattributes │ │ ├── icon.png │ │ ├── icon_512.png │ │ ├── icon_all.png │ │ ├── icon_fat.png │ │ ├── icon_fluids.png │ │ ├── icon_items.png │ │ ├── lang │ │ │ └── en_us.json │ │ └── textures │ │ │ └── fluid │ │ │ ├── potion.png │ │ │ └── potion.png.mcmeta │ └── minecraft │ │ └── atlases │ │ └── blocks.json │ ├── changelog │ ├── 0.1.0.txt │ ├── 0.1.1.txt │ ├── 0.1.10.txt │ ├── 0.1.11.txt │ ├── 0.1.12.txt │ ├── 0.1.13.txt │ ├── 0.1.14.txt │ ├── 0.1.15.txt │ ├── 0.1.16.txt │ ├── 0.1.17.txt │ ├── 0.1.18.txt │ ├── 0.1.19.txt │ ├── 0.1.2.txt │ ├── 0.1.20.txt │ ├── 0.1.21.txt │ ├── 0.1.22.txt │ ├── 0.1.23.txt │ ├── 0.1.3.txt │ ├── 0.1.4.txt │ ├── 0.1.5.txt │ ├── 0.1.6.txt │ ├── 0.1.7.txt │ ├── 0.1.8.txt │ ├── 0.1.9.txt │ ├── 0.10.0.txt │ ├── 0.10.2.txt │ ├── 0.11.0.txt │ ├── 0.11.1.txt │ ├── 0.12.0.txt │ ├── 0.13.0.txt │ ├── 0.14.0.txt │ ├── 0.2.0.txt │ ├── 0.2.1.txt │ ├── 0.2.2.txt │ ├── 0.3.0.txt │ ├── 0.3.1.txt │ ├── 0.3.3.txt │ ├── 0.3.4.txt │ ├── 0.3.5.txt │ ├── 0.4.0.txt │ ├── 0.4.1.txt │ ├── 0.4.10.txt │ ├── 0.4.11.txt │ ├── 0.4.13.txt │ ├── 0.4.14.txt │ ├── 0.4.15.txt │ ├── 0.4.2.txt │ ├── 0.4.3.txt │ ├── 0.4.4.txt │ ├── 0.4.5.txt │ ├── 0.4.6.txt │ ├── 0.4.7.txt │ ├── 0.4.8.txt │ ├── 0.4.9.txt │ ├── 0.5.0.txt │ ├── 0.5.1.txt │ ├── 0.6.0.txt │ ├── 0.6.3.txt │ ├── 0.6.4.txt │ ├── 0.6.6.txt │ ├── 0.7.0.txt │ ├── 0.8.0.txt │ ├── 0.8.2.txt │ ├── 0.8.4.txt │ ├── 0.8.5.txt │ ├── 0.8.6.txt │ ├── 0.8.7.txt │ ├── 0.8.8.txt │ ├── 0.8.9.txt │ ├── 0.9.0.txt │ ├── 0.9.1.txt │ └── 0.9.2.txt │ ├── fabric.mod.json │ ├── libblockattributes_core.client.json │ ├── libblockattributes_core.common.json │ ├── libblockattributes_fluid.client.json │ ├── libblockattributes_fluid.common.json │ └── libblockattributes_item.common.json └── test ├── java └── alexiil │ └── mc │ └── lib │ └── attributes │ ├── Tester.java │ ├── VanillaSetupBaseTester.java │ ├── fluid │ ├── amount │ │ └── FluidAmountTester.java │ ├── item │ │ └── FluidContainerTester.java │ ├── render │ │ └── FluidFaceSplitterTester.java │ └── volume │ │ ├── FluidPropertyTester.java │ │ └── FluidUnitSetTester.java │ └── item │ └── impl │ ├── DirectFixedItemInvTester.java │ ├── FixedItemInvTester.java │ ├── ItemInvTester.java │ ├── SimpleLimitedFixedItemInvTester.java │ └── SimpleLimitedGroupedItemInvTester.java └── resources └── fabric.mod.json /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | 7 | # idea 8 | 9 | .idea/ 10 | *.iml 11 | *.ipr 12 | *.iws 13 | 14 | # vscode 15 | 16 | .settings/ 17 | .vscode/ 18 | bin/ 19 | .classpath 20 | .project 21 | *.launch 22 | 23 | # fabric 24 | 25 | run/ 26 | logs/ 27 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | 5 | install: ./gradlew build publishToMavenLocal 6 | script: ./gradlew test 7 | 8 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Gradle keeps running out of heap space 2 | org.gradle.jvmargs=-Xmx1G 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /guidelines/lba.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /guidelines/lba.importorder: -------------------------------------------------------------------------------- 1 | #Organize Import Order 2 | #Tue Aug 18 21:02:47 BST 2020 3 | 11=alexiil 4 | 12=alexiil.mc.lib.modmail 5 | 13=alexiil.mc.lib.net 6 | 14=alexiil.mc.lib.attributes 7 | 15=alexiil.mc.lib.multipart 8 | 16=buildcraft.api 9 | 17=buildcraft.lib 10 | 18=buildcraft 11 | 0=java 12 | 1=javax 13 | 2=com 14 | 3=gnu 15 | 4=io 16 | 5=org 17 | 6=net 18 | 7=net.fabricmc.loader 19 | 8=net.fabricmc 20 | 9=net.minecraft 21 | 10=net.minecraftforge 22 | -------------------------------------------------------------------------------- /javadoc.options: -------------------------------------------------------------------------------- 1 | -use 2 | -Xdoclint:syntax 3 | -Xmaxwarns 1 4 | -------------------------------------------------------------------------------- /misc/LICENSE_HEADER.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 AlexIIL 2 | 3 | This Source Code Form is subject to the terms of the Mozilla Public 4 | License, v. 2.0. If a copy of the MPL was not distributed with this 5 | file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | mavenLocal() 4 | mavenCentral() 5 | maven { 6 | name = 'Fabric' 7 | url = 'https://maven.fabricmc.net/' 8 | } 9 | maven { 10 | name = "AlexIIL" 11 | url = "https://maven.alexiil.uk/" 12 | } 13 | gradlePluginPortal() 14 | } 15 | } 16 | rootProject.name = "LibBlockAttributes" 17 | -------------------------------------------------------------------------------- /src/fatjar/java/alexiil/mc/lib/attributes/fatjar/FatJarChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fatjar; 9 | 10 | /** Internal class - used to store the constant {@link #FATJAR_ERROR}. (Never actually loaded by the vm). */ 11 | public final class FatJarChecker { 12 | private FatJarChecker() {} 13 | 14 | public static final String FATJAR_ERROR = "\n\nLoaded the LBA FatJar outside of a development environment!" 15 | + "\nThis can cause stability issues when older or newer versions" 16 | + "\nof the different submodules are present on the classpath, as" 17 | + "\nfabric loader cannot load the seperate modules correctly. (Which" 18 | + "\nthen causes NoSuchMethodError's, or other strange behaviour)"; 19 | } 20 | -------------------------------------------------------------------------------- /src/fatjar/resources/LICENSE_FATJAR.txt: -------------------------------------------------------------------------------- 1 | FatJar Development Only License 2 | =============================== 3 | 4 | Every file under this license, once compiled, may only be used inside of a development environment. 5 | 6 | In particular they must not be shared to be used outside of a development environment, nor can they be 7 | -------------------------------------------------------------------------------- /src/fatjar/resources/LICENSE_WHOLE.txt: -------------------------------------------------------------------------------- 1 | This "Fat Jar" contains works licensed under two different licenses: 2 | 3 | * The majority of the code is licensed under Mozilla Public License Version 2.0 4 | (Which is reproduced in the "LICENSE" file). 5 | * A small amount of it (in the "alexiil.mc.lib.fatjar" package only) is licensed 6 | under a custom license, provided in the "LICENSE_FATJAR.txt" file located next 7 | to this one. 8 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AggregateFilterType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | public enum AggregateFilterType { 11 | ANY, 12 | ALL; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AttributeCombiner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import java.util.List; 11 | 12 | import javax.annotation.Nonnull; 13 | 14 | import alexiil.mc.lib.attributes.misc.Combined; 15 | 16 | @FunctionalInterface 17 | public interface AttributeCombiner { 18 | 19 | /** Combines the given list of attributes down into a single one. It is recommended that implementations return 20 | * instances that implement {@link Combined}. */ 21 | @Nonnull 22 | T combine(List attributes); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AttributeProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import net.minecraft.block.Block; 11 | import net.minecraft.block.BlockState; 12 | import net.minecraft.util.math.BlockPos; 13 | import net.minecraft.world.World; 14 | 15 | /** A {@link Block} that contains attributes. */ 16 | public interface AttributeProvider { 17 | 18 | /** Adds every instance of the given attribute in this block to the resulting list. Note that this must never add 19 | * wrapped versions of an attribute to the resulting list as the caller is responsible for doing that instead. */ 20 | void addAllAttributes(World world, BlockPos pos, BlockState state, AttributeList to); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AttributeProviderBlockEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import net.minecraft.block.Block; 11 | import net.minecraft.block.entity.BlockEntity; 12 | 13 | /** A {@link BlockEntity} that contains attributes. 14 | *

15 | * Note that {@link AttributeProvider} is called before this, if the {@link Block} implements it. However if 16 | * the {@link Block} doesn't actually add any objects of the correct type then this will still be called. */ 17 | public interface AttributeProviderBlockEntity { 18 | 19 | /** Adds every instance of the given attribute in this block entity to the resulting list. Note that this must never 20 | * add wrapped versions of an attribute to the resulting list as the caller is responsible for doing that 21 | * instead. */ 22 | void addAllAttributes(AttributeList to); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AttributeProviderItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import net.minecraft.item.Item; 11 | import net.minecraft.item.ItemStack; 12 | 13 | import alexiil.mc.lib.attributes.misc.LimitedConsumer; 14 | import alexiil.mc.lib.attributes.misc.Reference; 15 | 16 | /** An {@link Item} that contains attributes. */ 17 | public interface AttributeProviderItem { 18 | 19 | /** Adds every attribute instance to the given list that the item itself cannot be expected to add support for. 20 | * 21 | * @param stack A {@link Reference} to the stack to test for. If any of the added attributes need to modify the 22 | * stack then they should do that by setting the given {@link Reference#set(Object)}, rather than 23 | * modifying the stack directly. 24 | * @param excess If interacting with any of the returned attributes produces excess {@link ItemStack}'s then they 25 | * should be added to this {@link LimitedConsumer}. */ 26 | void addAllAttributes(Reference stack, LimitedConsumer excess, ItemAttributeList to); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AttributeSourceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | /** Defines the priority used for custom attribute adders. */ 11 | public enum AttributeSourceType { 12 | 13 | /** Highest priority of all the source types - when the object itself implements/extends the attribute 14 | * class/interface, or stores it in a field or (etc). 15 | *

16 | * The main point is that instance must be designed directly for the given attribute, or the implementation must be 17 | * the best possible version for the actual instance. */ 18 | INSTANCE, 19 | 20 | // Should any more be defined? I'm not sure what other kinds of implementations will actually happen. 21 | 22 | /** Lowest priority of all the source types - when the implementation is just a wrapper over a different API, and as 23 | * such it may suffer from poorer performance or be a poor fit for the target interface/class. */ 24 | COMPAT_WRAPPER; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/AttributeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | /** Misleadingly named class: this only stores the boolean checker {@link #EXPENSIVE_DEBUG_CHECKS}, and doesn't actually 11 | * have any other utility methods. */ 12 | public final class AttributeUtil { 13 | private AttributeUtil() {} 14 | 15 | // Ensure that it defaults to true, unless some-one explicitly goes looking for this 16 | public static final boolean EXPENSIVE_DEBUG_CHECKS 17 | = !Boolean.getBoolean("libblockattributes.disable_expensive_debug_checks"); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/Attributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | /** Static factories for {@link Attribute} instances. */ 13 | public final class Attributes { 14 | private Attributes() {} 15 | 16 | public static Attribute create(Class clazz) { 17 | return new Attribute<>(clazz); 18 | } 19 | 20 | public static Attribute create(Class clazz, CustomAttributeAdder customAdder) { 21 | return create(clazz).appendBlockAdder(customAdder); 22 | } 23 | 24 | public static DefaultedAttribute createDefaulted(Class clazz, @Nonnull T defaultValue) { 25 | return new DefaultedAttribute<>(clazz, defaultValue); 26 | } 27 | 28 | public static DefaultedAttribute createDefaulted( 29 | Class clazz, @Nonnull T defaultValue, CustomAttributeAdder customAdder 30 | ) { 31 | return createDefaulted(clazz, defaultValue).appendBlockAdder(customAdder); 32 | } 33 | 34 | public static CombinableAttribute createCombinable( 35 | Class clazz, @Nonnull T defaultValue, AttributeCombiner combiner 36 | ) { 37 | return new CombinableAttribute<>(clazz, defaultValue, combiner); 38 | } 39 | 40 | public static CombinableAttribute createCombinable( 41 | Class clazz, @Nonnull T defaultValue, AttributeCombiner combiner, CustomAttributeAdder customAdder 42 | ) { 43 | return createCombinable(clazz, defaultValue, combiner).appendBlockAdder(customAdder); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/CacheInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | /** Placeholder class until caches are worked out. */ 11 | public final class CacheInfo { 12 | 13 | public static final CacheInfo NOT_CACHABLE = new CacheInfo(); 14 | 15 | private CacheInfo() { 16 | // Private because we're going to change this in the future. 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/CustomAttributeAdder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import net.minecraft.block.BlockState; 11 | import net.minecraft.util.math.BlockPos; 12 | import net.minecraft.world.World; 13 | 14 | @FunctionalInterface 15 | public interface CustomAttributeAdder { 16 | /* Note that we do have the type parameter (unlike AttributeProvider) because instances are registered to a specific 17 | * Attribute so it's actually useful for implementors. */ 18 | 19 | /** Adds every attribute instance to the given list that the block itself cannot be expected to add support for. */ 20 | void addAll(World world, BlockPos pos, BlockState state, AttributeList to); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/ItemAttributeAdder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import java.util.function.Consumer; 11 | 12 | import javax.annotation.Nullable; 13 | 14 | import net.minecraft.item.ItemStack; 15 | 16 | import alexiil.mc.lib.attributes.misc.LimitedConsumer; 17 | import alexiil.mc.lib.attributes.misc.Reference; 18 | 19 | @FunctionalInterface 20 | public interface ItemAttributeAdder { 21 | /* Note that we do have the type parameter (unlike AttributeProviderItem) because instances are registered to a 22 | * specific Attribute so it's actually useful for implementors. */ 23 | 24 | /** Adds every attribute instance to the given list that the item itself cannot be expected to add support for. 25 | * 26 | * @param stack A {@link Reference} to the stack to test for. If any of the added attributes need to modify the 27 | * stack then they should do that by setting the given {@link Reference#set(Object)}, rather than 28 | * modifying the stack directly. 29 | * @param excess If interacting with any of the returned attributes produces excess itemstacks then they should be 30 | * added to this {@link Consumer}. */ 31 | void addAll(Reference stack, @Nullable LimitedConsumer excess, ItemAttributeList to); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/ListenerRemovalToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | /** A token for any registered listener in LibBlockAttributes. */ 11 | @FunctionalInterface 12 | public interface ListenerRemovalToken { 13 | /** Callback after any listener was removed. */ 14 | void onListenerRemoved(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/ListenerToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | /** A token for any registered listener in LibBlockAttributes. */ 11 | @FunctionalInterface 12 | public interface ListenerToken { 13 | /** Removes the listener from wherever it's registered. */ 14 | void removeListener(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/NullAttributeAdder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import net.minecraft.block.BlockState; 11 | import net.minecraft.block.entity.BlockEntity; 12 | import net.minecraft.item.ItemStack; 13 | import net.minecraft.util.math.BlockPos; 14 | import net.minecraft.world.World; 15 | 16 | import alexiil.mc.lib.attributes.misc.LimitedConsumer; 17 | import alexiil.mc.lib.attributes.misc.Reference; 18 | 19 | final class NullAttributeAdder 20 | implements CustomAttributeAdder, ItemAttributeAdder, BlockEntityAttributeAdder { 21 | 22 | private NullAttributeAdder() {} 23 | 24 | private static final NullAttributeAdder INSTANCE = new NullAttributeAdder<>(); 25 | 26 | @SuppressWarnings("unchecked") 27 | public static NullAttributeAdder get() { 28 | // Safe because we don't actually do anything with the type. 29 | return (NullAttributeAdder) INSTANCE; 30 | } 31 | 32 | @Override 33 | public void addAll(Reference stack, LimitedConsumer excess, ItemAttributeList to) { 34 | // NO-OP 35 | } 36 | 37 | @Override 38 | public void addAll(World world, BlockPos pos, BlockState state, AttributeList to) { 39 | // NO-OP 40 | } 41 | 42 | @Override 43 | public void addAll(BlockEntity blockEntity, AttributeList to) { 44 | // NO-OP 45 | } 46 | 47 | @Override 48 | public Class getBlockEntityClass() { 49 | return BlockEntity.class; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/SearchOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import java.util.function.Predicate; 11 | 12 | import net.minecraft.util.shape.VoxelShape; 13 | import net.minecraft.util.shape.VoxelShapes; 14 | 15 | /** The base class for block search options. This only contains filtration for objects that are added to the attribute 16 | * list via a {@link Predicate}. Instances can be constructed/obtained from {@link SearchOptions}, and all javadoc for 17 | * the various implementations is on those static factories. */ 18 | public class SearchOption { 19 | 20 | /** Use {@link SearchOptions#ALL}. */ 21 | static final SearchOption ALL = new SearchOption<>(); 22 | 23 | private final Predicate searchMatcher; 24 | 25 | SearchOption() { 26 | this.searchMatcher = null; 27 | } 28 | 29 | SearchOption(Predicate searchMatcher) { 30 | this.searchMatcher = searchMatcher; 31 | } 32 | 33 | /** Checks to see if the given object matches this {@link #searchMatcher}. This method will normally be called by 34 | * LBA automatically, so users are discouraged from calling this. */ 35 | public final boolean matches(T obj) { 36 | return searchMatcher != null ? searchMatcher.test(obj) : true; 37 | } 38 | 39 | /** Returns the {@link VoxelShape} to use for bounds checking. This defaults to a full block, but custom search 40 | * options (like {@link SearchOptionInVoxel}) override this. */ 41 | public VoxelShape getShape() { 42 | return VoxelShapes.fullCube(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/SearchOptionDirectional.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import java.util.EnumMap; 11 | import java.util.function.Predicate; 12 | 13 | import net.minecraft.util.math.Direction; 14 | 15 | public class SearchOptionDirectional extends SearchOption { 16 | 17 | private static final EnumMap> SIDES; 18 | 19 | /** The direction that this search is going in. */ 20 | public final Direction direction; 21 | 22 | SearchOptionDirectional(Direction direction) { 23 | this.direction = direction; 24 | } 25 | 26 | SearchOptionDirectional(Direction direction, Predicate searchMatcher) { 27 | super(searchMatcher); 28 | this.direction = direction; 29 | } 30 | 31 | static SearchOptionDirectional of(Direction dir) { 32 | return SIDES.get(dir); 33 | } 34 | 35 | static { 36 | SIDES = new EnumMap<>(Direction.class); 37 | for (Direction dir : Direction.values()) { 38 | SIDES.put(dir, new SearchOptionDirectional<>(dir)); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/SearchOptionDirectionalVoxel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import java.util.function.Predicate; 11 | 12 | import net.minecraft.util.math.Direction; 13 | import net.minecraft.util.shape.VoxelShape; 14 | 15 | public final class SearchOptionDirectionalVoxel extends SearchOptionDirectional { 16 | 17 | /** If true then the {@link AttributeList} will sort itself based on the direction and shape. */ 18 | public final boolean ordered; 19 | public final VoxelShape shape; 20 | 21 | SearchOptionDirectionalVoxel(Direction direction, boolean ordered, VoxelShape shape) { 22 | super(direction); 23 | this.ordered = ordered; 24 | this.shape = shape; 25 | } 26 | 27 | SearchOptionDirectionalVoxel(Direction direction, boolean ordered, VoxelShape shape, Predicate searchMatcher) { 28 | super(direction, searchMatcher); 29 | this.ordered = ordered; 30 | this.shape = shape; 31 | } 32 | 33 | @Override 34 | public VoxelShape getShape() { 35 | return shape; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/SearchOptionInVoxel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import java.util.function.Predicate; 11 | 12 | import net.minecraft.util.shape.VoxelShape; 13 | 14 | public final class SearchOptionInVoxel extends SearchOption { 15 | public final VoxelShape shape; 16 | 17 | SearchOptionInVoxel(VoxelShape shape) { 18 | this.shape = shape; 19 | } 20 | 21 | SearchOptionInVoxel(VoxelShape shape, Predicate searchMatcher) { 22 | super(searchMatcher); 23 | this.shape = shape; 24 | } 25 | 26 | @Override 27 | public VoxelShape getShape() { 28 | return shape; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/Simulation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | /** Used in various places for testing [...] */ 11 | // TODO: grammar! 12 | public enum Simulation { 13 | // TODO: Better names! 14 | // for all 3 here... 15 | SIMULATE, 16 | ACTION; 17 | 18 | public boolean isSimulate() { 19 | return this == SIMULATE; 20 | } 21 | 22 | public boolean isAction() { 23 | return this == ACTION; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/FluidInvAmountChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid; 9 | 10 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 11 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 12 | 13 | /** Replaced by {@link FluidInvAmountChangeListener_F}. */ 14 | @FunctionalInterface 15 | @Deprecated(since = "0.6.0", forRemoval = true) 16 | public interface FluidInvAmountChangeListener { 17 | 18 | /** @param inv The inventory that changed 19 | * @param fluid The {@link FluidKey} whose amount changed. 20 | * @param previous The previous {@link FluidVolume}. 21 | * @param current The new {@link FluidVolume}. The {@link FluidVolume#getFluidKey()} will either be the empty fluid 22 | * key, or equal to the passed {@link FluidKey} . */ 23 | void onChange(GroupedFluidInvView inv, FluidKey fluid, int previous, int current); 24 | 25 | public static FluidInvAmountChangeListener_F asNew(FluidInvAmountChangeListener old) { 26 | return (inv, fluid, previous, current) -> old.onChange(inv, fluid, previous.as1620(), current.as1620()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/FluidInvAmountChangeListener_F.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid; 9 | 10 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 11 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 12 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 13 | 14 | @FunctionalInterface 15 | public interface FluidInvAmountChangeListener_F { 16 | 17 | /** @param inv The inventory that changed 18 | * @param fluid The {@link FluidKey} whose amount changed. 19 | * @param previous The previous {@link FluidVolume}. 20 | * @param current The new {@link FluidVolume}. The {@link FluidVolume#getFluidKey()} will either be the empty fluid 21 | * key, or equal to the passed {@link FluidKey} . */ 22 | void onChange(GroupedFluidInvView inv, FluidKey fluid, FluidAmount previous, FluidAmount current); 23 | 24 | @Deprecated(since = "0.6.0", forRemoval = true) 25 | public static FluidInvAmountChangeListener asOld(FluidInvAmountChangeListener_F listener) { 26 | return (inv, fluid, previous, current) -> { 27 | listener.onChange(inv, fluid, FluidAmount.of1620(previous), FluidAmount.of1620(current)); 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/FluidInvTankChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid; 9 | 10 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 11 | 12 | public interface FluidInvTankChangeListener { 13 | 14 | /** @param inv The inventory that changed 15 | * @param tank The tank that changed 16 | * @param previous The previous {@link FluidVolume}. 17 | * @param current The new {@link FluidVolume} */ 18 | void onChange(FixedFluidInvView inv, int tank, FluidVolume previous, FluidVolume current); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/FluidItemUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid; 9 | 10 | import java.util.Set; 11 | 12 | import net.minecraft.item.ItemStack; 13 | 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 15 | import alexiil.mc.lib.attributes.fluid.volume.FluidKeys; 16 | 17 | /** Various utilities for dealing with fluids contained in single {@link ItemStack}s. */ 18 | public final class FluidItemUtil { 19 | private FluidItemUtil() {} 20 | 21 | /** Retrieves the first fluid contained by the given {@link ItemStack}. 22 | * 23 | * @return The {@link FluidKey} if the {@link ItemStack} contained any, or {@link FluidKeys#EMPTY} if none were 24 | * present. */ 25 | public static FluidKey getContainedFluid(ItemStack stack) { 26 | GroupedFluidInvView inv = FluidAttributes.GROUPED_INV_VIEW.get(stack); 27 | Set set = inv.getStoredFluids(); 28 | if (set.isEmpty()) { 29 | return FluidKeys.EMPTY; 30 | } 31 | return set.iterator().next(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/GroupedFluidInv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid; 9 | 10 | import alexiil.mc.lib.attributes.fluid.filter.ConstantFluidFilter; 11 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 12 | import alexiil.mc.lib.attributes.fluid.impl.SimpleLimitedGroupedFluidInv; 13 | 14 | /** A modifiable version of {@link GroupedFluidInvView}, except that all modification methods are provided by 15 | * {@link FluidExtractable} and {@link FluidInsertable}. */ 16 | public interface GroupedFluidInv extends GroupedFluidInvView, FluidTransferable { 17 | 18 | /** @return A new {@link LimitedGroupedFluidInv} that provides a more controllable version of this 19 | * {@link GroupedFluidInv}. */ 20 | default LimitedGroupedFluidInv createLimitedGroupedInv() { 21 | return new SimpleLimitedGroupedFluidInv(this); 22 | } 23 | 24 | /** @return a {@link GroupedFluidInv} that can only have the given filter of fluids inserted or extracted. */ 25 | @Override 26 | default GroupedFluidInv filtered(FluidFilter filter) { 27 | if (filter == ConstantFluidFilter.ANYTHING) { 28 | return this; 29 | } 30 | LimitedGroupedFluidInv limited = createLimitedGroupedInv(); 31 | limited.getRule(filter.negate()).disallowTransfer(); 32 | return limited.markFinal(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/ICustomBucketItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid; 9 | 10 | import net.minecraft.fluid.Fluid; 11 | import net.minecraft.item.BucketItem; 12 | import net.minecraft.item.ItemStack; 13 | 14 | /** Items that implement {@link BucketItem} should implement this interface to ensure that LBA gets the correct 15 | * {@link ItemStack} from filling this with a fluid. */ 16 | public interface ICustomBucketItem { 17 | ItemStack getFilledBucket(Fluid fluid); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/compat/mod/LbaFluidModCompatLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.compat.mod; 9 | 10 | import alexiil.mc.lib.attributes.fluid.compat.mod.transfer.TransferFluidInvCompatLoader; 11 | import alexiil.mc.lib.attributes.fluid.compat.mod.vanilla.VanillaFluidCompat; 12 | 13 | public final class LbaFluidModCompatLoader { 14 | private LbaFluidModCompatLoader() {} 15 | 16 | public static void load() { 17 | VanillaFluidCompat.load(); 18 | TransferFluidInvCompatLoader.load(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/ConstantFluidFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 11 | 12 | /** A {@link FluidFilter} that either matches everything ({@link #ANYTHING}) or matches nothing ({@link #NOTHING}) */ 13 | public enum ConstantFluidFilter implements ReadableFluidFilter { 14 | /** A {@link FluidFilter} that matches everything. */ 15 | ANYTHING(true), 16 | /** A {@link FluidFilter} that matches nothing. */ 17 | NOTHING(false); 18 | 19 | private final boolean result; 20 | 21 | private ConstantFluidFilter(boolean result) { 22 | this.result = result; 23 | } 24 | 25 | public static ConstantFluidFilter of(boolean result) { 26 | return result ? ANYTHING : NOTHING; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "ConstantFluidFilter." + name(); 32 | } 33 | 34 | @Override 35 | public boolean matches(FluidKey fluid) { 36 | if (fluid.isEmpty()) { 37 | throw new IllegalArgumentException("You should never test a FluidFilter with an empty fluid!"); 38 | } 39 | return result; 40 | } 41 | 42 | @Override 43 | public FluidFilter negate() { 44 | return of(!result); 45 | } 46 | 47 | @Override 48 | public FluidFilter and(FluidFilter other) { 49 | if (result) { 50 | return other; 51 | } else { 52 | return NOTHING; 53 | } 54 | } 55 | 56 | @Override 57 | public FluidFilter or(FluidFilter other) { 58 | if (result) { 59 | return ANYTHING; 60 | } else { 61 | return other; 62 | } 63 | } 64 | 65 | // Don't override asPredicate so that we still get the better version that calls our own negate(), and(), or() 66 | // methods. 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/ExactFluidFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import net.minecraft.fluid.Fluid; 11 | import net.minecraft.potion.Potion; 12 | 13 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidKeys; 15 | 16 | /** An {@link FluidFilter} that only matches on a single {@link FluidKey}. */ 17 | public final class ExactFluidFilter implements ReadableFluidFilter { 18 | 19 | public final FluidKey fluid; 20 | 21 | /** Creates a new {@link ExactFluidFilter}. There's generally little point in using this, as every {@link FluidKey} 22 | * contains a field for storing this ({@link FluidKey#exactFilter}). */ 23 | public ExactFluidFilter(FluidKey fluid) { 24 | this.fluid = fluid; 25 | } 26 | 27 | @Override 28 | public boolean matches(FluidKey other) { 29 | return fluid.equals(other); 30 | } 31 | 32 | public static ReadableFluidFilter of(Fluid fluid) { 33 | return FluidKeys.get(fluid).exactFilter; 34 | } 35 | 36 | public static ReadableFluidFilter of(Potion potion) { 37 | return FluidKeys.get(potion).exactFilter; 38 | } 39 | 40 | public static ReadableFluidFilter of(FluidKey fluid) { 41 | return fluid.exactFilter; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/FluidInsertableFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FluidInsertable; 12 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 13 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | 16 | /** A {@link FluidFilter} that checks to see if the given {@link FluidInsertable} could have the fluid inserted into it, 17 | * right now. (Note that this doesn't match the definition of {@link FluidInsertable#getInsertionFilter()}, so you 18 | * should never use it a return value from that). */ 19 | public final class FluidInsertableFilter implements FluidFilter { 20 | 21 | public final FluidInsertable insertable; 22 | 23 | public FluidInsertableFilter(FluidInsertable insertable) { 24 | this.insertable = insertable; 25 | } 26 | 27 | @Override 28 | public boolean matches(FluidKey fluidKey) { 29 | FluidVolume volume = fluidKey.withAmount(FluidAmount.A_MILLION); 30 | return insertable.attemptInsertion(volume, Simulation.SIMULATE).getAmount_F().isLessThan(FluidAmount.A_MILLION); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/FluidSetFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import java.util.Collections; 11 | import java.util.Set; 12 | 13 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 14 | 15 | /** A {@link FluidFilter} that matches any {@link FluidKey} in a {@link Set} of {@link FluidKey}s. */ 16 | public final class FluidSetFilter implements ReadableFluidFilter { 17 | 18 | private final Set fluids; 19 | 20 | public FluidSetFilter(Set fluids) { 21 | this.fluids = Collections.unmodifiableSet(fluids); 22 | } 23 | 24 | @Override 25 | public boolean matches(FluidKey fluidKey) { 26 | return fluids.contains(fluidKey); 27 | } 28 | 29 | /** @return The set of fluids that this matches. */ 30 | public Set getFluids() { 31 | return fluids; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/FluidTagFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 11 | 12 | /** A {@link FluidFilter} that operates on tags of LBA's {@link FluidKey}'s. 13 | *

14 | * Note that this has not been implemented yet! Instead you'll have to use the 15 | * {@link RawFluidTagFilter} to use tags (but only for raw vanilla minecraft fluids) */ 16 | public final class FluidTagFilter implements ResolvableFluidFilter { 17 | private FluidTagFilter() {} 18 | 19 | @Override 20 | public boolean matches(FluidKey fluidKey) { 21 | return false; 22 | } 23 | 24 | @Override 25 | public ReadableFluidFilter resolve() { 26 | return ConstantFluidFilter.NOTHING; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/InvertedFluidFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 11 | 12 | /** The default implementation for {@link FluidFilter#negate()} */ 13 | public final class InvertedFluidFilter implements ReadableFluidFilter { 14 | 15 | public final FluidFilter delegate; 16 | 17 | public InvertedFluidFilter(FluidFilter delegate) { 18 | this.delegate = delegate; 19 | } 20 | 21 | @Override 22 | public boolean matches(FluidKey fluidKey) { 23 | return !delegate.matches(fluidKey); 24 | } 25 | 26 | @Override 27 | public FluidFilter negate() { 28 | return delegate; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/RawFluidTagFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import java.util.HashSet; 11 | 12 | import net.minecraft.fluid.Fluid; 13 | import net.minecraft.registry.Registries; 14 | import net.minecraft.registry.entry.RegistryEntry; 15 | import net.minecraft.registry.tag.TagKey; 16 | 17 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 18 | import alexiil.mc.lib.attributes.fluid.volume.FluidKeys; 19 | 20 | /** A {@link FluidFilter} that operates on a {@link TagKey} of vanilla minecraft's {@link Fluid}'s. */ 21 | public final class RawFluidTagFilter implements ResolvableFluidFilter { 22 | 23 | private TagKey tagKey; 24 | 25 | public RawFluidTagFilter(TagKey tagKey) { 26 | this.tagKey = tagKey; 27 | } 28 | 29 | @Override 30 | public boolean matches(FluidKey fluidKey) { 31 | Fluid raw = fluidKey.getRawFluid(); 32 | if (raw == null) { 33 | return false; 34 | } 35 | return raw.isIn(tagKey); 36 | } 37 | 38 | @Override 39 | public ReadableFluidFilter resolve() { 40 | HashSet set = new HashSet<>(); 41 | for (RegistryEntry entry : Registries.FLUID.iterateEntries(tagKey)) { 42 | set.add(FluidKeys.get(entry.value())); 43 | } 44 | return new FluidSetFilter(set); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/ReadableFluidFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import alexiil.mc.lib.attributes.AttributeUtil; 11 | 12 | /** Marker interface for {@link FluidFilter} that indicates that object obtaining instances of this might be able to 13 | * read the real contents. 14 | *

15 | * NOTE: This can only be implemented by classes included in LibBlockAttributes!. (As many 16 | * implementations must implement direct support for subclasses of this). 17 | *

18 | * As such you should pretend that this interface is "sealed", and the only valid subtypes are: 19 | *

    20 | *
  1. {@link ConstantFluidFilter}
  2. 21 | *
  3. {@link ExactFluidFilter}
  4. 22 | *
  5. {@link AggregateFluidFilter}
  6. 23 | *
  7. {@link FluidSetFilter}
  8. 24 | *
  9. {@link InvertedFluidFilter}
  10. 25 | *
  11. {@link ResolvableFluidFilter}
  12. 26 | *
27 | * Note that {@link ResolvableFluidFilter} is not sealed, but it must only return {@link ReadableFluidFilter}s 28 | * that are {@link ReadableFluidFilter}s, other than {@link ResolvableFluidFilter}. */ 29 | public interface ReadableFluidFilter extends FluidFilter { 30 | 31 | public static void checkValidity(ReadableFluidFilter filter) { 32 | if (AttributeUtil.EXPENSIVE_DEBUG_CHECKS) { 33 | String clsName = ReadableFluidFilter.class.getName(); 34 | String expectedPackage = clsName.substring(0, clsName.lastIndexOf('.')); 35 | if (!filter.getClass().getName().startsWith(expectedPackage)) { 36 | throw new IllegalStateException( 37 | "The owner of " + filter.getClass() + " has incorrectly implemented ReadableFluidFilter!\n" 38 | + "Note that only LibBlockAttributes should define readable fluid filters, " 39 | + "as otherwise there's no way to guarentee compatibility!" 40 | ); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/filter/ResolvableFluidFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.filter; 9 | 10 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 11 | 12 | /** A type of {@link ReadableFluidFilter} that may be resolved at a later time to a fixed {@link ReadableFluidFilter}, 13 | * but which isn't constant over time. (For example item tags may be reloaded, but are stored in a static field and so 14 | * don't need to be re-created often. (And can be read)). */ 15 | @FunctionalInterface 16 | public interface ResolvableFluidFilter extends ReadableFluidFilter { 17 | 18 | /** Resolves this {@link ReadableFluidFilter}. Note that this must return one of the valid types of 19 | * {@link ReadableFluidFilter}, except this! 20 | *

21 | * This is intended for use-cases where you actually need to read the filter - for other cases there's usually 22 | * little reason to call this, as "matches" should be faster for most reasonable implementations. (However some 23 | * implementations - for example lambdas - might be faster to call multiple times if you resolve them before 24 | * checking them). */ 25 | ReadableFluidFilter resolve(); 26 | 27 | /** {@inheritDoc} 28 | *

29 | * This is overridden primarily for lambdas - most implementing classes are expected to override this, because it 30 | * will most likely be faster. */ 31 | @Override 32 | default boolean matches(FluidKey fluid) { 33 | ReadableFluidFilter resolved = resolve(); 34 | if (resolved instanceof ResolvableFluidFilter) { 35 | throw new IllegalStateException( 36 | getClass() + "'s 'resolve()' method returned " + resolved + ", which isn't a fixed filter!" 37 | ); 38 | } 39 | ReadableFluidFilter.checkValidity(resolved); 40 | return resolved.matches(fluid); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/AbstractPartialFixedFluidInvView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.fluid.FixedFluidInvView; 11 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 12 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 13 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | 16 | /** Base class for {@link SubFixedFluidInvView} and {@link MappedFixedFluidInvView}. */ 17 | public abstract class AbstractPartialFixedFluidInvView implements FixedFluidInvView { 18 | 19 | /** The inventory that is wrapped. */ 20 | protected final FixedFluidInvView inv; 21 | 22 | protected AbstractPartialFixedFluidInvView(FixedFluidInvView inv) { 23 | this.inv = inv; 24 | } 25 | 26 | /** @return The tank that the internal {@link #inv} should use. */ 27 | protected abstract int getInternalTank(int tank); 28 | 29 | @Override 30 | public FluidVolume getInvFluid(int tank) { 31 | return inv.getInvFluid(getInternalTank(tank)); 32 | } 33 | 34 | @Override 35 | public boolean isFluidValidForTank(int tank, FluidKey fluid) { 36 | return inv.isFluidValidForTank(getInternalTank(tank), fluid); 37 | } 38 | 39 | @Override 40 | public FluidFilter getFilterForTank(int tank) { 41 | return inv.getFilterForTank(getInternalTank(tank)); 42 | } 43 | 44 | @Override 45 | @Deprecated(since = "0.6.0", forRemoval = true) 46 | public int getMaxAmount(int tank) { 47 | return inv.getMaxAmount(getInternalTank(tank)); 48 | } 49 | 50 | @Override 51 | public FluidAmount getMaxAmount_F(int tank) { 52 | return inv.getMaxAmount_F(getInternalTank(tank)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/CombinedFixedFluidInv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import java.util.List; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.fluid.FixedFluidInv; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | 16 | /** An {@link FixedFluidInv} that delegates to a list of them instead of storing items directly. */ 17 | public class CombinedFixedFluidInv extends CombinedFixedFluidInvView 18 | implements FixedFluidInv { 19 | 20 | public CombinedFixedFluidInv(List views) { 21 | super(views); 22 | } 23 | 24 | @Override 25 | public boolean setInvFluid(int tank, FluidVolume to, Simulation simulation) { 26 | return getInv(tank).setInvFluid(getSubTank(tank), to, simulation); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/FilteredFluidExtractable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FluidExtractable; 12 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 13 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | 16 | public final class FilteredFluidExtractable implements FluidExtractable { 17 | private final FluidExtractable real; 18 | public final FluidFilter filter; 19 | 20 | public FilteredFluidExtractable(FluidExtractable real, FluidFilter filter) { 21 | this.real = real; 22 | this.filter = filter; 23 | } 24 | 25 | @Override 26 | public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) { 27 | FluidFilter realFilter = this.filter.and(filter); 28 | return real.attemptExtraction(realFilter, maxAmount, simulation); 29 | } 30 | 31 | @Override 32 | public FluidExtractable filtered(FluidFilter filter) { 33 | return new FilteredFluidExtractable(real, this.filter.and(filter)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/FilteredFluidInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FluidInsertable; 12 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 13 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | 16 | /** A {@link FluidInsertable} that delegates to another {@link FluidInsertable}, but has an additional filter as to what 17 | * can be inserted. */ 18 | public final class FilteredFluidInsertable implements FluidInsertable { 19 | 20 | private final FluidInsertable real; 21 | public final FluidFilter filter; 22 | 23 | public FilteredFluidInsertable(FluidInsertable real, FluidFilter filter) { 24 | this.real = real; 25 | this.filter = filter; 26 | } 27 | 28 | @Override 29 | public FluidFilter getInsertionFilter() { 30 | return real.getInsertionFilter().and(filter); 31 | } 32 | 33 | @Override 34 | public FluidAmount getMinimumAcceptedAmount() { 35 | return real.getMinimumAcceptedAmount(); 36 | } 37 | 38 | @Override 39 | public FluidVolume attemptInsertion(FluidVolume fluid, Simulation simulation) { 40 | if (!filter.matches(fluid.fluidKey)) { 41 | return fluid; 42 | } 43 | return real.attemptInsertion(fluid, simulation); 44 | } 45 | 46 | @Override 47 | public FluidInsertable filtered(FluidFilter filter) { 48 | return new FilteredFluidInsertable(real, filter.and(this.filter)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/FilteredFluidTransferable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FluidTransferable; 12 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 13 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | 16 | public final class FilteredFluidTransferable implements FluidTransferable { 17 | private final FluidTransferable real; 18 | public final FluidFilter filter; 19 | 20 | public FilteredFluidTransferable(FluidTransferable real, FluidFilter filter) { 21 | this.real = real; 22 | this.filter = filter; 23 | } 24 | 25 | // FluidExtractable 26 | 27 | @Override 28 | public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) { 29 | FluidFilter realFilter = this.filter.and(filter); 30 | return real.attemptExtraction(realFilter, maxAmount, simulation); 31 | } 32 | 33 | // FluidInsertable 34 | 35 | @Override 36 | public FluidFilter getInsertionFilter() { 37 | return real.getInsertionFilter().and(filter); 38 | } 39 | 40 | @Override 41 | public FluidAmount getMinimumAcceptedAmount() { 42 | return real.getMinimumAcceptedAmount(); 43 | } 44 | 45 | @Override 46 | public FluidVolume attemptInsertion(FluidVolume fluid, Simulation simulation) { 47 | if (!filter.matches(fluid.fluidKey)) { 48 | return fluid; 49 | } 50 | return real.attemptInsertion(fluid, simulation); 51 | } 52 | 53 | // FluidTransferable 54 | 55 | @Override 56 | public FluidTransferable filtered(FluidFilter filter) { 57 | return new FilteredFluidTransferable(real, filter.and(this.filter)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/FluidInvModificationTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.fluid.FixedFluidInv; 11 | 12 | /** A tracker object that tries to ensure that the "no modification" rule that methods like 13 | * {@link FixedFluidInv#getInvFluid(int)} use is followed. */ 14 | public final class FluidInvModificationTracker { 15 | // TODO: Implement tracking! 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/JumboFixedFluidInv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.fluid.FluidExtractable; 11 | import alexiil.mc.lib.attributes.fluid.FluidInsertable; 12 | import alexiil.mc.lib.attributes.fluid.GroupedFluidInvView; 13 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 14 | 15 | /** A {@link SimpleFixedFluidInv} with a few optimisations to make the {@link FluidInsertable}, 16 | * {@link FluidExtractable}, and {@link GroupedFluidInvView} implementations much faster than a simple inventory search 17 | * for larger inventories. */ 18 | public class JumboFixedFluidInv extends SimpleFixedFluidInv { 19 | 20 | /** @deprecated Replaced by {@link #JumboFixedFluidInv(int, FluidAmount)}. */ 21 | @Deprecated(since = "0.6.0", forRemoval = true) 22 | public JumboFixedFluidInv(int invSize, int tankCapacity) { 23 | super(invSize, tankCapacity); 24 | } 25 | 26 | public JumboFixedFluidInv(int invSize, FluidAmount tankCapacity) { 27 | super(invSize, tankCapacity); 28 | } 29 | 30 | // TODO: Optimisations! 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/MappedFixedFluidInv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FixedFluidInv; 12 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 13 | 14 | public class MappedFixedFluidInv extends MappedFixedFluidInvView implements FixedFluidInv { 15 | 16 | public MappedFixedFluidInv(FixedFluidInv inv, int[] tanks) { 17 | super(inv, tanks); 18 | } 19 | 20 | @Override 21 | public boolean setInvFluid(int tank, FluidVolume to, Simulation simulation) { 22 | return ((FixedFluidInv) inv).setInvFluid(getInternalTank(tank), to, simulation); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/RejectingFluidInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FluidInsertable; 12 | import alexiil.mc.lib.attributes.fluid.filter.ConstantFluidFilter; 13 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 14 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 15 | import alexiil.mc.lib.attributes.misc.NullVariant; 16 | 17 | /** An {@link FluidInsertable} that always refuses to accept any inserted {@link FluidVolume}. */ 18 | public enum RejectingFluidInsertable implements FluidInsertable, NullVariant { 19 | NULL, 20 | EXTRACTOR; 21 | 22 | @Override 23 | public FluidVolume attemptInsertion(FluidVolume stack, Simulation simulation) { 24 | return stack; 25 | } 26 | 27 | @Override 28 | public FluidFilter getInsertionFilter() { 29 | return ConstantFluidFilter.NOTHING; 30 | } 31 | 32 | @Override 33 | public FluidInsertable getPureInsertable() { 34 | return this; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/SimpleFixedFluidInvExtractable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FixedFluidInv; 12 | import alexiil.mc.lib.attributes.fluid.FluidExtractable; 13 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 14 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 15 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 16 | 17 | /** @deprecated This has been replaced with {@link FixedFluidInv#getMappedInv(int...)} followed by 18 | * {@link FixedFluidInv#getExtractable()}. (And optionally {@link FluidExtractable#getPureExtractable()} if 19 | * you only want to expose it as an extractable). */ 20 | @Deprecated(since = "0.4.0", forRemoval = true) 21 | public final class SimpleFixedFluidInvExtractable implements FluidExtractable { 22 | 23 | private final FluidExtractable real; 24 | 25 | public SimpleFixedFluidInvExtractable(FixedFluidInv inv, int[] tanks) { 26 | this.real = (tanks == null ? inv : inv.getMappedInv(tanks)).getExtractable(); 27 | } 28 | 29 | @Override 30 | public FluidVolume attemptExtraction(FluidFilter filter, FluidAmount maxAmount, Simulation simulation) { 31 | return real.attemptExtraction(filter, maxAmount, simulation); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/SimpleFixedFluidInvInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FixedFluidInv; 12 | import alexiil.mc.lib.attributes.fluid.FluidInsertable; 13 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 14 | import alexiil.mc.lib.attributes.fluid.filter.FluidFilter; 15 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 16 | 17 | /** @deprecated This has been replaced with {@link FixedFluidInv#getMappedInv(int...)} followed by 18 | * {@link FixedFluidInv#getInsertable()}. (And optionally {@link FluidInsertable#getPureInsertable()} if you 19 | * only want to expose it as an insertable). */ 20 | @Deprecated(since = "0.4.0", forRemoval = true) 21 | public final class SimpleFixedFluidInvInsertable implements FluidInsertable { 22 | 23 | private final FluidInsertable real; 24 | 25 | public SimpleFixedFluidInvInsertable(FixedFluidInv inv, int[] tanks) { 26 | this.real = (tanks == null ? inv : inv.getMappedInv(tanks)).getInsertable(); 27 | } 28 | 29 | @Override 30 | public FluidVolume attemptInsertion(FluidVolume fluid, Simulation simulation) { 31 | return real.attemptInsertion(fluid, simulation); 32 | } 33 | 34 | @Override 35 | public FluidAmount getMinimumAcceptedAmount() { 36 | return real.getMinimumAcceptedAmount(); 37 | } 38 | 39 | @Override 40 | public FluidFilter getInsertionFilter() { 41 | return real.getInsertionFilter(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/impl/SubFixedFluidInv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.impl; 9 | 10 | import alexiil.mc.lib.attributes.Simulation; 11 | import alexiil.mc.lib.attributes.fluid.FixedFluidInv; 12 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 13 | 14 | public class SubFixedFluidInv extends SubFixedFluidInvView implements FixedFluidInv { 15 | 16 | public SubFixedFluidInv(FixedFluidInv inv, int fromIndex, int toIndex) { 17 | super(inv, fromIndex, toIndex); 18 | } 19 | 20 | @Override 21 | public boolean setInvFluid(int tank, FluidVolume to, Simulation simulation) { 22 | return ((FixedFluidInv) inv).setInvFluid(getInternalTank(tank), to, simulation); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/init/ClientFluidInit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.init; 9 | 10 | import net.fabricmc.api.ClientModInitializer; 11 | 12 | import net.minecraft.client.MinecraftClient; 13 | 14 | public class ClientFluidInit implements ClientModInitializer { 15 | @Override 16 | public void onInitializeClient() { 17 | LbaFluidProxy.MC_TOOLTIPS_ADVANCED = () -> { 18 | MinecraftClient mc = MinecraftClient.getInstance(); 19 | if (mc == null) { 20 | return false; 21 | } 22 | return mc.options == null ? false : mc.options.advancedItemTooltips; 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/init/LbaFluidProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.init; 9 | 10 | import java.util.function.BooleanSupplier; 11 | 12 | public class LbaFluidProxy { 13 | public static BooleanSupplier MC_TOOLTIPS_ADVANCED = () -> false; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/mixin/impl/BiomeEffectsAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.mixin.impl; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.gen.Accessor; 12 | 13 | import net.minecraft.world.biome.BiomeEffects; 14 | 15 | @Mixin(BiomeEffects.class) 16 | public interface BiomeEffectsAccessor { 17 | 18 | @Accessor("waterColor") 19 | int libblockattributes_getWaterColour(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/mixin/impl/FlowableFluidAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.mixin.impl; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.gen.Invoker; 12 | 13 | import net.minecraft.fluid.FlowableFluid; 14 | import net.minecraft.world.WorldView; 15 | 16 | @Mixin(FlowableFluid.class) 17 | public interface FlowableFluidAccessor { 18 | @Invoker("getFlowSpeed") 19 | int lba_getFlowSpeed(WorldView worldView); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/mixin/impl/FluidBlockMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.mixin.impl; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.Shadow; 12 | 13 | import net.minecraft.block.Block; 14 | import net.minecraft.block.FluidBlock; 15 | import net.minecraft.fluid.FlowableFluid; 16 | 17 | import alexiil.mc.lib.attributes.fluid.world.IFluidBlockMixin; 18 | 19 | @Mixin(FluidBlock.class) 20 | public class FluidBlockMixin extends Block implements IFluidBlockMixin { 21 | @Shadow 22 | protected FlowableFluid fluid; 23 | 24 | public FluidBlockMixin(Settings block$Settings_1) { 25 | super(block$Settings_1); 26 | } 27 | 28 | @Override 29 | public FlowableFluid __fluid() { 30 | return fluid; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/mixin/impl/RenderLayerAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.mixin.impl; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.gen.Accessor; 12 | 13 | import net.minecraft.client.render.RenderLayer; 14 | 15 | @Mixin(RenderLayer.class) 16 | public interface RenderLayerAccessor { 17 | 18 | @Accessor("translucent") 19 | public boolean libblockattributes_isTranslucent(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | /** The base package for {@link net.minecraft.fluid.Fluid fluid} management. 9 | *

10 | * As vanilla minecraft doesn't use fluids as much as items there are a few key differences between how this package 11 | * works verses {@link alexiil.mc.lib.attributes.item}: 12 | *

    13 | *
  • Instead of {@link net.minecraft.item.ItemStack ItemStack} we have 14 | * {@link alexiil.mc.lib.attributes.fluid.volume.FluidVolume FluidVolume} (with an amount) and 15 | * {@link alexiil.mc.lib.attributes.fluid.volume.FluidKey FluidKey} (without an amount)
  • 16 | *
  • Slots are called "tanks"
  • 17 | *
  • Tanks/Slots do not have a pre-defined maximum amount (and neither do fluids themselves as that depends wholly on 18 | * the container).
  • 19 | *
  • The units for fluids are fractional amounts based on 1+0/1 being equal to 1 bucket, stored in 20 | * {@link alexiil.mc.lib.attributes.fluid.amount.FluidAmount}.
  • 21 | *
22 | */ 23 | package alexiil.mc.lib.attributes.fluid; 24 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/render/DefaultFluidVolumeRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.render; 9 | 10 | import java.util.List; 11 | 12 | import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; 13 | 14 | import net.minecraft.client.render.RenderLayer; 15 | import net.minecraft.client.render.VertexConsumerProvider; 16 | import net.minecraft.client.texture.Sprite; 17 | import net.minecraft.client.util.math.MatrixStack; 18 | import net.minecraft.fluid.Fluid; 19 | 20 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 21 | 22 | /** Default {@link FluidVolumeRenderer} that can handle most default fluid types - if the {@link FluidVolume} is for a 23 | * non-null minecraft {@link Fluid} then this will use the sprites provided from the {@link FluidRenderHandlerRegistry}. 24 | * Otherwise this will fallback to the sprites in {@link FluidVolume#getStillSprite()} and 25 | * {@link FluidVolume#getFlowingSprite()}. */ 26 | public class DefaultFluidVolumeRenderer extends FluidVolumeRenderer { 27 | 28 | public static final DefaultFluidVolumeRenderer INSTANCE = new DefaultFluidVolumeRenderer(); 29 | 30 | protected DefaultFluidVolumeRenderer() {} 31 | 32 | @Override 33 | public void render( 34 | FluidVolume fluid, List faces, VertexConsumerProvider vcp, MatrixStack matrices 35 | ) { 36 | Sprite[] sprites = getSprites(fluid); 37 | RenderLayer layer = getRenderLayer(fluid); 38 | renderSimpleFluid(faces, vcp.getBuffer(layer), matrices, sprites[0], sprites[1], fluid.getRenderColor()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/render/EnchantmentGlintFluidRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.render; 9 | 10 | import java.util.List; 11 | 12 | import net.minecraft.client.render.RenderLayer; 13 | import net.minecraft.client.render.VertexConsumer; 14 | import net.minecraft.client.render.VertexConsumerProvider; 15 | import net.minecraft.client.render.item.ItemRenderer; 16 | import net.minecraft.client.texture.Sprite; 17 | import net.minecraft.client.util.math.MatrixStack; 18 | 19 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 20 | 21 | public class EnchantmentGlintFluidRenderer extends FluidVolumeRenderer { 22 | 23 | public static final EnchantmentGlintFluidRenderer INSTANCE = new EnchantmentGlintFluidRenderer(); 24 | 25 | protected EnchantmentGlintFluidRenderer() {} 26 | 27 | @Override 28 | public void render( 29 | FluidVolume fluid, List faces, VertexConsumerProvider vcp, MatrixStack matrices 30 | ) { 31 | Sprite[] sprites = getSprites(fluid); 32 | RenderLayer layer = getRenderLayer(fluid); 33 | VertexConsumer vc = ItemRenderer.getItemGlintConsumer(vcp, layer, true, true); 34 | renderSimpleFluid(faces, vc, matrices, sprites[0], sprites[1], fluid.getRenderColor()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/render/ImplicitVanillaFluidVolumeRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.render; 9 | 10 | import java.util.List; 11 | 12 | import net.minecraft.client.render.VertexConsumerProvider; 13 | import net.minecraft.client.util.math.MatrixStack; 14 | 15 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 16 | 17 | /** @deprecated Because {@link DefaultFluidVolumeRenderer} does everything that this does. */ 18 | @Deprecated(since = "0.6.0", forRemoval = true) 19 | public class ImplicitVanillaFluidVolumeRenderer extends FluidVolumeRenderer { 20 | 21 | public static final ImplicitVanillaFluidVolumeRenderer INSTANCE = new ImplicitVanillaFluidVolumeRenderer(); 22 | 23 | @Override 24 | public void render( 25 | FluidVolume fluid, List faces, VertexConsumerProvider vcp, MatrixStack matrices 26 | ) { 27 | DefaultFluidVolumeRenderer.INSTANCE.render(fluid, faces, vcp, matrices); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/BiomeSourcedFluidVolume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import com.google.gson.JsonObject; 11 | 12 | import net.minecraft.nbt.NbtCompound; 13 | import net.minecraft.world.biome.Biome; 14 | 15 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 16 | 17 | /** A fluid that changes it's makup based on the {@link Biome}s that it is taken from. */ 18 | public class BiomeSourcedFluidVolume extends ColouredFluidVolume { 19 | 20 | public BiomeSourcedFluidVolume(BiomeSourcedFluidKey key, Biome source, FluidAmount amount) { 21 | super(key, amount); 22 | setColourFromBiome(source); 23 | } 24 | 25 | @Deprecated(since = "0.6.4", forRemoval = true) 26 | public BiomeSourcedFluidVolume(BiomeSourcedFluidKey key, Biome source, int amount) { 27 | super(key, amount); 28 | setColourFromBiome(source); 29 | } 30 | 31 | public BiomeSourcedFluidVolume(BiomeSourcedFluidKey key, FluidAmount amount) { 32 | super(key, amount); 33 | } 34 | 35 | @Deprecated(since = "0.6.4", forRemoval = true) 36 | public BiomeSourcedFluidVolume(BiomeSourcedFluidKey key, int amount) { 37 | super(key, amount); 38 | } 39 | 40 | public BiomeSourcedFluidVolume(BiomeSourcedFluidKey key, NbtCompound tag) { 41 | super(key, tag); 42 | } 43 | 44 | public BiomeSourcedFluidVolume(BiomeSourcedFluidKey key, JsonObject json) { 45 | super(key, json); 46 | } 47 | 48 | @Override 49 | public BiomeSourcedFluidKey getFluidKey() { 50 | return (BiomeSourcedFluidKey) this.fluidKey; 51 | } 52 | 53 | public void setColourFromBiome(Biome source) { 54 | setArgb(getFluidKey().getColourFromBiome(source)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/FluidKeyCustomiser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import net.minecraft.fluid.Fluid; 11 | 12 | import alexiil.mc.lib.attributes.fluid.volume.FluidKey.FluidKeyBuilder; 13 | 14 | /** Interface for minecraft {@link Fluid} to implement to customise the implicit {@link FluidKey} that gets created for 15 | * them. Note that this is not a replacement for registering a {@link FluidKey} yourself: this only supports customising 16 | * {@link SimpleFluidKey}. */ 17 | public interface FluidKeyCustomiser { 18 | 19 | /** Customises the {@link SimpleFluidKey} that is created implicitly for this {@link Fluid}. */ 20 | void customiseKey(FluidKeyBuilder builder); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/NormalFluidVolume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import javax.annotation.Nonnull; 11 | 12 | import com.google.gson.JsonObject; 13 | 14 | import net.minecraft.fluid.Fluid; 15 | import net.minecraft.item.ItemStack; 16 | import net.minecraft.nbt.NbtCompound; 17 | 18 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 19 | 20 | /** {@link ItemStack} equivalent for {@link Fluid fluids}. Instances must be constructed via 21 | * {@link FluidKeys#get(Fluid)}.{@link FluidKey#withAmount(FluidAmount) withAmount(FluidAmount)}. 22 | * 23 | * @deprecated Because any {@link FluidKey} can map to a single {@link Fluid}, and {@link SimpleFluidVolume} has a much 24 | * better name than this. */ 25 | @Deprecated(since = "0.6.0", forRemoval = true) 26 | public class NormalFluidVolume extends FluidVolume { 27 | 28 | @Deprecated(since = "0.6.0", forRemoval = true) 29 | NormalFluidVolume(NormalFluidKey fluid, int amount) { 30 | super(fluid, amount); 31 | } 32 | 33 | NormalFluidVolume(NormalFluidKey fluid, FluidAmount amount) { 34 | super(fluid, amount); 35 | } 36 | 37 | NormalFluidVolume(NormalFluidKey fluid, NbtCompound tag) { 38 | super(fluid, tag); 39 | } 40 | 41 | NormalFluidVolume(NormalFluidKey fluid, JsonObject json) { 42 | super(fluid, json); 43 | } 44 | 45 | @Override 46 | @Nonnull 47 | public final Fluid getRawFluid() { 48 | return getFluidKey().fluid; 49 | } 50 | 51 | @Override 52 | public NormalFluidKey getFluidKey() { 53 | return (NormalFluidKey) fluidKey; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/SimpleFluidKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import com.google.gson.JsonObject; 11 | import com.google.gson.JsonSyntaxException; 12 | 13 | import net.minecraft.nbt.NbtCompound; 14 | 15 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 16 | 17 | /** Simple implementation of a {@link FluidKey} that doesn't do anything special. */ 18 | public class SimpleFluidKey extends FluidKey { 19 | 20 | public SimpleFluidKey(FluidKeyBuilder builder) { 21 | super(builder); 22 | } 23 | 24 | @Override 25 | public FluidVolume readVolume(NbtCompound tag) { 26 | return new SimpleFluidVolume(this, tag); 27 | } 28 | 29 | @Override 30 | public FluidVolume readVolume(JsonObject json) throws JsonSyntaxException { 31 | return new SimpleFluidVolume(this, json); 32 | } 33 | 34 | @Override 35 | public FluidVolume withAmount(FluidAmount amount) { 36 | return new SimpleFluidVolume(this, amount); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/SimpleFluidVolume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import com.google.gson.JsonObject; 11 | 12 | import net.minecraft.nbt.NbtCompound; 13 | 14 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 15 | 16 | /** Simple implementation of a {@link FluidVolume} that doesn't do anything special. */ 17 | public class SimpleFluidVolume extends FluidVolume { 18 | 19 | protected SimpleFluidVolume(SimpleFluidKey key, FluidAmount amount) { 20 | super(key, amount); 21 | } 22 | 23 | @Deprecated(since = "0.6.4", forRemoval = true) 24 | protected SimpleFluidVolume(SimpleFluidKey key, int amount) { 25 | super(key, amount); 26 | } 27 | 28 | protected SimpleFluidVolume(SimpleFluidKey key, NbtCompound tag) { 29 | super(key, tag); 30 | } 31 | 32 | protected SimpleFluidVolume(SimpleFluidKey key, JsonObject json) { 33 | super(key, json); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/WaterFluidVolume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import com.google.gson.JsonObject; 11 | 12 | import net.minecraft.nbt.NbtCompound; 13 | import net.minecraft.world.biome.Biome; 14 | 15 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 16 | 17 | /* package-private */ final class WaterFluidVolume extends BiomeSourcedFluidVolume { 18 | 19 | public WaterFluidVolume(FluidAmount amount) { 20 | super(WaterFluidKey.INSTANCE, amount); 21 | } 22 | 23 | @Deprecated(since = "0.6.4", forRemoval = true) 24 | public WaterFluidVolume(int amount) { 25 | super(WaterFluidKey.INSTANCE, amount); 26 | } 27 | 28 | public WaterFluidVolume(Biome source, FluidAmount amount) { 29 | super(WaterFluidKey.INSTANCE, source, amount); 30 | } 31 | 32 | @Deprecated(since = "0.6.4", forRemoval = true) 33 | public WaterFluidVolume(Biome source, int amount) { 34 | super(WaterFluidKey.INSTANCE, source, amount); 35 | } 36 | 37 | public WaterFluidVolume(NbtCompound tag) { 38 | super(WaterFluidKey.INSTANCE, tag); 39 | } 40 | 41 | public WaterFluidVolume(JsonObject json) { 42 | super(WaterFluidKey.INSTANCE, json); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/volume/WeightedFluidKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.volume; 9 | 10 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 11 | 12 | public abstract class WeightedFluidKey extends FluidKey { 13 | 14 | public final Class valueClass; 15 | public final T defaultValue; 16 | 17 | public WeightedFluidKey(FluidKeyBuilder builder, Class valueClass, T defaultValue) { 18 | super(builder); 19 | this.valueClass = valueClass; 20 | this.defaultValue = defaultValue; 21 | } 22 | 23 | @Override 24 | public WeightedFluidVolume withAmount(FluidAmount amount) { 25 | return withAmount(defaultValue, amount); 26 | } 27 | 28 | @Override 29 | @Deprecated(since = "0.6.0", forRemoval = true) 30 | public WeightedFluidVolume withAmount(int amount) { 31 | return withAmount(FluidAmount.of1620(amount)); 32 | } 33 | 34 | public abstract WeightedFluidVolume withAmount(T value, FluidAmount amount); 35 | 36 | @Deprecated(since = "0.6.4", forRemoval = true) 37 | public WeightedFluidVolume withAmount(T value, int amount) { 38 | return withAmount(value, FluidAmount.of1620(amount)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/world/IFluidBlockMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.world; 9 | 10 | import net.minecraft.fluid.FlowableFluid; 11 | 12 | public interface IFluidBlockMixin { 13 | FlowableFluid __fluid(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/fluid/world/IFluidVolumeDrainable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.world; 9 | 10 | import net.minecraft.block.BlockState; 11 | import net.minecraft.block.FluidDrainable; 12 | import net.minecraft.block.Waterloggable; 13 | import net.minecraft.util.math.BlockPos; 14 | import net.minecraft.world.WorldAccess; 15 | 16 | import alexiil.mc.lib.attributes.Simulation; 17 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 18 | 19 | /** Similar to {@link FluidDrainable}, but for {@link FluidVolume}'s. Note that you should never call this directly as 20 | * vanilla {@link Waterloggable} fluids don't implement this! */ 21 | public interface IFluidVolumeDrainable { 22 | FluidVolume tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state, Simulation simulation); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/GroupedItemInv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 11 | import alexiil.mc.lib.attributes.item.impl.SimpleLimitedGroupedItemInv; 12 | 13 | /** A modifiable version of {@link GroupedItemInvView}, except that all modification methods are provided by 14 | * {@link ItemExtractable} and {@link ItemInsertable}. */ 15 | public interface GroupedItemInv extends GroupedItemInvView, ItemTransferable { 16 | 17 | @Override 18 | default GroupedItemInv filtered(ItemFilter filter) { 19 | LimitedGroupedItemInv limited = createLimitedGroupedInv(); 20 | limited.getRule(filter.negate()).disallowTransfer(); 21 | return limited.markFinal(); 22 | } 23 | 24 | /** @return A new {@link LimitedGroupedItemInv} that provides a more controllable version of this 25 | * {@link GroupedItemInv}. */ 26 | default LimitedGroupedItemInv createLimitedGroupedInv() { 27 | return new SimpleLimitedGroupedItemInv(this); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/InvMarkDirtyListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | /** Listener {@link FunctionalInterface} for 11 | * {@link FixedItemInvView#addListener(InvMarkDirtyListener, alexiil.mc.lib.attributes.ListenerRemovalToken)}. */ 12 | @FunctionalInterface 13 | public interface InvMarkDirtyListener { 14 | 15 | /** @param inv The inventory that was modified - this is always the inventory object that you registered the 16 | * listener with, and never any delegate inventories! */ 17 | void onMarkDirty(AbstractItemInvView inv); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/ItemInvAmountChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | @FunctionalInterface 13 | public interface ItemInvAmountChangeListener { 14 | 15 | /** @param inv The inventory that changed 16 | * @param stack The {@link ItemStack} whose amount changed. 17 | * @param previous The previous amount of the given stack. 18 | * @param current The new amount of the given stack. */ 19 | void onChange(GroupedItemInvView inv, ItemStack stack, int previous, int current); 20 | 21 | /** A simple listener for an {@link ItemInvAmountChangeListener} that wraps an {@link InvMarkDirtyListener}. */ 22 | public static final class MarkDirtyWrapper implements ItemInvAmountChangeListener { 23 | 24 | public final InvMarkDirtyListener realListener; 25 | 26 | public MarkDirtyWrapper(InvMarkDirtyListener realListener) { 27 | this.realListener = realListener; 28 | } 29 | 30 | @Override 31 | public void onChange(GroupedItemInvView inv, ItemStack stack, int previous, int current) { 32 | realListener.onMarkDirty(inv); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/ItemInvSlotChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.item.impl.DirectFixedItemInv; 13 | 14 | /** Listener {@link FunctionalInterface} for {@link FixedItemInvView}. 15 | *

16 | * Note that the listener system is not fully fleshed out yet so this will change in the future! */ 17 | @FunctionalInterface 18 | public interface ItemInvSlotChangeListener { 19 | 20 | /** @param inv The inventory that changed 21 | * @param slot The slot that changed 22 | * @param previous The previous {@link ItemStack}. 23 | * @param current The new {@link ItemStack} */ 24 | void onChange(FixedItemInvView inv, int slot, ItemStack previous, ItemStack current); 25 | 26 | /** A specialised type of listener that won't receive the previous {@link ItemStack} that occupied the given slot. 27 | * Used for optimisation purposes in {@link DirectFixedItemInv}. */ 28 | @FunctionalInterface 29 | public interface ItemInvSlotListener extends ItemInvSlotChangeListener { 30 | 31 | /** NOTE: This might not be called if the inventory calls {@link #onChange(FixedItemInvView, int)} directly! */ 32 | @Override 33 | default void onChange(FixedItemInvView inv, int slot, ItemStack previous, ItemStack current) { 34 | onChange(inv, slot); 35 | } 36 | 37 | void onChange(FixedItemInvView inv, int slot); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/ItemStackUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | import java.util.Objects; 11 | 12 | import net.minecraft.item.ItemStack; 13 | 14 | public final class ItemStackUtil { 15 | private ItemStackUtil() {} 16 | 17 | /** Checks to see if the two {@link ItemStack}'s are equal, but ignoring the {@link ItemStack#getCount() counts}. */ 18 | public static boolean areEqualIgnoreAmounts(ItemStack a, ItemStack b) { 19 | if (a.isEmpty()) { 20 | return b.isEmpty(); 21 | } 22 | if (b.isEmpty()) { 23 | return false; 24 | } 25 | return a.getItem() == b.getItem() && Objects.equals(a.getNbt(), b.getNbt()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/SingleCopyingItemSlot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.ListenerRemovalToken; 13 | import alexiil.mc.lib.attributes.ListenerToken; 14 | import alexiil.mc.lib.attributes.item.FixedItemInv.CopyingFixedItemInv; 15 | 16 | public class SingleCopyingItemSlot extends SingleItemSlot { 17 | 18 | SingleCopyingItemSlot(CopyingFixedItemInv backingView, int slot) { 19 | super(backingView, slot); 20 | } 21 | 22 | @Override 23 | public CopyingFixedItemInv getBackingInv() { 24 | return (CopyingFixedItemInv) super.getBackingInv(); 25 | } 26 | 27 | /** Adds the given listener to the backing inventory, such that the 28 | * {@link ItemInvSlotChangeListener#onChange(FixedItemInvView, int, ItemStack, ItemStack)} will be called every time 29 | * that this inventory changes. However if this inventory doesn't support listeners then this will return a null 30 | * {@link ListenerToken token}. 31 | * 32 | * @param removalToken A token that will be called whenever the given listener is removed from this inventory (or if 33 | * this inventory itself is unloaded or otherwise invalidated). 34 | * @return A token that represents the listener, or null if the listener could not be added. */ 35 | public final ListenerToken addListener(ItemInvSlotChangeListener listener, ListenerRemovalToken removalToken) { 36 | return getBackingInv().addListener((realInv, s, previous, current) -> { 37 | assert realInv == backingView; 38 | if (slot == s) { 39 | listener.onChange(realInv, slot, previous, current); 40 | } 41 | }, removalToken); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/SingleItemSlotView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 13 | 14 | /** A delegating view of a single slot in a {@link FixedItemInvView}. */ 15 | public class SingleItemSlotView { 16 | 17 | final FixedItemInvView backingView; 18 | final int slot; 19 | 20 | SingleItemSlotView(FixedItemInvView backingView, int slot) { 21 | this.backingView = backingView; 22 | this.slot = slot; 23 | 24 | if (slot < 0) { 25 | throw new IllegalArgumentException(slot + " is negative! This will never work!"); 26 | } 27 | } 28 | 29 | public FixedItemInvView getBackingInv() { 30 | return backingView; 31 | } 32 | 33 | public final int getIndex() { 34 | return slot; 35 | } 36 | 37 | public final ItemStack get() { 38 | return backingView.getInvStack(slot); 39 | } 40 | 41 | public final int getMaxAmount(ItemStack stack) { 42 | return backingView.getMaxAmount(slot, stack); 43 | } 44 | 45 | public final boolean isValid(ItemStack stack) { 46 | return backingView.isItemValidForSlot(slot, stack); 47 | } 48 | 49 | public final ItemFilter getFilter() { 50 | return backingView.getFilterForSlot(slot); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/FixedInventoryViewVanillaWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.compat; 9 | 10 | import net.minecraft.inventory.Inventory; 11 | import net.minecraft.item.ItemStack; 12 | 13 | import alexiil.mc.lib.attributes.item.FixedItemInv; 14 | import alexiil.mc.lib.attributes.item.FixedItemInvView; 15 | import alexiil.mc.lib.attributes.misc.OpenWrapper; 16 | 17 | /** An {@link FixedItemInv} that wraps a vanilla {@link Inventory}. */ 18 | public class FixedInventoryViewVanillaWrapper implements FixedItemInvView, OpenWrapper { 19 | protected final Inventory inv; 20 | 21 | public FixedInventoryViewVanillaWrapper(Inventory inv) { 22 | this.inv = inv; 23 | } 24 | 25 | public static FixedInventoryViewVanillaWrapper wrapInventory(Inventory inv) { 26 | return new FixedInventoryViewVanillaWrapper(inv); 27 | } 28 | 29 | @Override 30 | public int getSlotCount() { 31 | return inv.size(); 32 | } 33 | 34 | @Override 35 | public ItemStack getInvStack(int slot) { 36 | return inv.getStack(slot); 37 | } 38 | 39 | @Override 40 | public boolean isItemValidForSlot(int slot, ItemStack item) { 41 | return inv.isValid(slot, item); 42 | } 43 | 44 | @Override 45 | public int getMaxAmount(int slot, ItemStack stack) { 46 | return Math.min(inv.getMaxCountPerStack(), stack.getMaxCount()); 47 | } 48 | 49 | @Override 50 | public Object getWrapped() { 51 | return inv; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/FixedSidedInventoryVanillaWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.compat; 9 | 10 | import net.minecraft.inventory.SidedInventory; 11 | import net.minecraft.item.ItemStack; 12 | import net.minecraft.util.math.Direction; 13 | 14 | import alexiil.mc.lib.attributes.item.FixedItemInv; 15 | 16 | /** An {@link FixedItemInv} that wraps a vanilla {@link SidedInventory} for a particular {@link Direction side}. */ 17 | public class FixedSidedInventoryVanillaWrapper extends FixedInventoryVanillaWrapper { 18 | 19 | final SidedInventory sidedInv; 20 | final Direction side; 21 | 22 | public FixedSidedInventoryVanillaWrapper(SidedInventory inv, Direction side) { 23 | super(inv); 24 | this.side = side; 25 | this.sidedInv = inv; 26 | } 27 | 28 | public static FixedItemInv create(SidedInventory inventory, Direction side) { 29 | FixedSidedInventoryVanillaWrapper wrapper = new FixedSidedInventoryVanillaWrapper(inventory, side); 30 | return wrapper.getMappedInv(inventory.getAvailableSlots(side)); 31 | } 32 | 33 | @Override 34 | protected boolean canExtract(int slot, ItemStack extractedStack) { 35 | return sidedInv.canExtract(slot, extractedStack, side); 36 | } 37 | 38 | @Override 39 | protected boolean canInsert(int slot, ItemStack newStack) { 40 | return isItemValidForSlot(slot, newStack) && sidedInv.canInsert(slot, newStack, side); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/mod/LbaItemModCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.compat.mod; 9 | 10 | import alexiil.mc.lib.attributes.item.compat.mod.dank.DankItemInvCompatLoader; 11 | import alexiil.mc.lib.attributes.item.compat.mod.transfer.TransferItemInvCompatLoader; 12 | 13 | public final class LbaItemModCompat { 14 | private LbaItemModCompat() {} 15 | 16 | public static void load() { 17 | // EmiItemInvCompatLoader.load(); 18 | DankItemInvCompatLoader.load(); 19 | TransferItemInvCompatLoader.load(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/mod/dank/DankItemInvCompatLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.compat.mod.dank; 9 | 10 | import net.minecraft.block.entity.BlockEntity; 11 | import net.minecraft.inventory.Inventory; 12 | 13 | import alexiil.mc.lib.attributes.misc.LibBlockAttributes; 14 | import alexiil.mc.lib.attributes.misc.compat.mod.LbaModCompatLoader; 15 | 16 | /** Compat for https://github.com/Tfarcenim/DankStorageFabric */ 17 | public class DankItemInvCompatLoader extends LbaModCompatLoader { 18 | 19 | private static final String MOD_NAME = "Dank Storage"; 20 | 21 | public static void load() { 22 | try { 23 | Class dock = c("tfar.dankstorage.blockentity.DockBlockEntity"); 24 | if (!(Inventory.class.isAssignableFrom(dock))) { 25 | throw new NoSuchMethodException("DockBlockEntity doesn't implement Inventory"); 26 | } 27 | if (!(BlockEntity.class.isAssignableFrom(dock))) { 28 | throw new NoSuchMethodException("DockBlockEntity doesn't extend BlockEntity???"); 29 | } 30 | 31 | LibBlockAttributes.LOGGER.info(MOD_NAME + " found, loading compatibility for items."); 32 | DankItemInvCompat.load((Class) dock); 33 | } catch (ClassNotFoundException cnfe) { 34 | LibBlockAttributes.LOGGER 35 | .info(MOD_NAME + " not found, not loading compatibility for items (" + cnfe.getMessage() + ")"); 36 | } catch (NoSuchMethodException e) { 37 | LibBlockAttributes.LOGGER.info( 38 | "A different version of " + MOD_NAME + " was found, not loading compatibility for items. (" 39 | + e.getMessage() + ")" 40 | ); 41 | } catch (ReflectiveOperationException roe) { 42 | LibBlockAttributes.LOGGER 43 | .warn("A different version of " + MOD_NAME + " was found, not loading compatibility for items.", roe); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/mod/emi/iteminv/EmiEmptyItemInventory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.compat.mod.emi.iteminv; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import dev.emi.iteminventory.api.ItemInventory; 13 | 14 | public enum EmiEmptyItemInventory implements ItemInventory { 15 | INSTANCE; 16 | 17 | @Override 18 | public int getInvSize(ItemStack invItem) { 19 | return 0; 20 | } 21 | 22 | @Override 23 | public ItemStack getStack(ItemStack invItem, int index) { 24 | throw new IndexOutOfBoundsException(); 25 | } 26 | 27 | @Override 28 | public void setStack(ItemStack invItem, int index, ItemStack stack) { 29 | throw new IndexOutOfBoundsException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/mod/emi/iteminv/EmiItemInvCompat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.compat.mod.emi.iteminv; 9 | 10 | import alexiil.mc.lib.attributes.Attribute; 11 | import alexiil.mc.lib.attributes.AttributeSourceType; 12 | import alexiil.mc.lib.attributes.item.ItemAttributes; 13 | 14 | import dev.emi.iteminventory.api.ItemInventory; 15 | 16 | public final class EmiItemInvCompat { 17 | private EmiItemInvCompat() {} 18 | 19 | static void load() { 20 | ItemAttributes.forEachInv(EmiItemInvCompat::put); 21 | } 22 | 23 | private static void put(Attribute attribute) { 24 | AttributeSourceType srcType = AttributeSourceType.COMPAT_WRAPPER; 25 | attribute.putItemClassAdder(srcType, ItemInventory.class, true, (stack, excess, to) -> { 26 | to.offer(new FixedInvEmiItemInv(stack, excess)); 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/compat/mod/emi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | /** The name "ItemInventory" isn't very unique, so instead of using it directly we prefix it with the authors name. */ 9 | package alexiil.mc.lib.attributes.item.compat.mod.emi; 10 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/entity/ItemExtractableProjectileEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.entity; 9 | 10 | import net.minecraft.entity.projectile.ProjectileEntity; 11 | import net.minecraft.item.ItemStack; 12 | 13 | import alexiil.mc.lib.attributes.Simulation; 14 | import alexiil.mc.lib.attributes.item.ItemExtractable; 15 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 16 | 17 | public class ItemExtractableProjectileEntity implements ItemExtractable { 18 | private final ProjectileEntity entity; 19 | 20 | public ItemExtractableProjectileEntity(ProjectileEntity entity) { 21 | this.entity = entity; 22 | } 23 | 24 | @Override 25 | public ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) { 26 | if (!entity.isAlive()) { 27 | return ItemStack.EMPTY; 28 | } 29 | 30 | // TODO: Getter for ProjectileEntity.asItemStack 31 | 32 | return ItemStack.EMPTY; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ConstantItemFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | public enum ConstantItemFilter implements ReadableItemFilter { 13 | ANYTHING(true, true), 14 | 15 | @Deprecated(since = "0.8.0", forRemoval = true) 16 | ANYTHING_EXCEPT_EMPTY(true, false), 17 | 18 | @Deprecated(since = "0.8.0", forRemoval = true) 19 | ONLY_EMPTY(false, true), 20 | 21 | NOTHING(false, false); 22 | 23 | private final boolean fullResult; 24 | 25 | private ConstantItemFilter(boolean fullResult, boolean emptyResult) { 26 | this.fullResult = fullResult; 27 | } 28 | 29 | public static ConstantItemFilter of(boolean result) { 30 | return result ? ANYTHING : NOTHING; 31 | } 32 | 33 | @Deprecated(since = "0.8.0", forRemoval = true) 34 | public static ConstantItemFilter of(boolean fullResult, boolean emptyResult) { 35 | if (fullResult) { 36 | return emptyResult ? ANYTHING : ANYTHING_EXCEPT_EMPTY; 37 | } else { 38 | return emptyResult ? ONLY_EMPTY : NOTHING; 39 | } 40 | } 41 | 42 | @Override 43 | public boolean matches(ItemStack stack) { 44 | return stack.isEmpty() ? false : fullResult; 45 | } 46 | 47 | @Override 48 | public ItemFilter negate() { 49 | return of(!fullResult); 50 | } 51 | 52 | @Override 53 | public ItemFilter and(ItemFilter other) { 54 | return fullResult ? other : NOTHING; 55 | } 56 | 57 | @Override 58 | public ItemFilter or(ItemFilter other) { 59 | return fullResult ? ANYTHING : other; 60 | } 61 | 62 | // Don't override asPredicate so that we still get the better version that calls our own negate(), and(), or() 63 | // methods. 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ExactItemSetFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import java.util.Collection; 11 | import java.util.Collections; 12 | import java.util.Set; 13 | 14 | import net.minecraft.item.Item; 15 | import net.minecraft.item.ItemConvertible; 16 | import net.minecraft.item.ItemStack; 17 | 18 | /** A {@link ReadableItemFilter}, similar to {@link ExactItemFilter} but which matches any of the {@link Item}s in a 19 | * {@link Set}. */ 20 | public final class ExactItemSetFilter implements ReadableItemFilter { 21 | 22 | private final Set items; 23 | 24 | public ExactItemSetFilter(Set items) { 25 | this.items = Collections.unmodifiableSet(items); 26 | } 27 | 28 | @Override 29 | public boolean matches(ItemStack stack) { 30 | return items.contains(stack.getItem()); 31 | } 32 | 33 | public Set getItems() { 34 | return items; 35 | } 36 | 37 | public static ReadableItemFilter anyOf(Collection items) { 38 | return ExactItemFilter.anyOf(items); 39 | } 40 | 41 | public static ReadableItemFilter anyOf(ItemConvertible[] items) { 42 | return ExactItemFilter.anyOf(items); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ExactItemStackFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.item.ItemStackUtil; 13 | 14 | /** An {@link ItemFilter} that only matches on a single {@link ItemStack}, using 15 | * {@link ItemStackUtil#areEqualIgnoreAmounts(ItemStack, ItemStack)}. */ 16 | public final class ExactItemStackFilter implements ReadableItemFilter { 17 | 18 | public final ItemStack stack; 19 | 20 | public ExactItemStackFilter(ItemStack stack) { 21 | this.stack = stack; 22 | } 23 | 24 | @Override 25 | public boolean matches(ItemStack other) { 26 | return ItemStackUtil.areEqualIgnoreAmounts(this.stack, other); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/InvertedItemFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | public final class InvertedItemFilter implements ReadableItemFilter { 13 | 14 | public final ItemFilter delegate; 15 | 16 | public InvertedItemFilter(ItemFilter delegate) { 17 | this.delegate = delegate; 18 | } 19 | 20 | @Override 21 | public boolean matches(ItemStack stack) { 22 | return !delegate.matches(stack); 23 | } 24 | 25 | @Override 26 | public ItemFilter negate() { 27 | return delegate; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ItemClassFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | /** A {@link ReadableItemFilter} that only matches items that are {@link Class#isInstance(Object)} of a certain 13 | * {@link Class}, and are NOT {@link ItemStack#isEmpty() empty} . */ 14 | public final class ItemClassFilter implements ReadableItemFilter { 15 | 16 | public final Class matchedClass; 17 | 18 | public ItemClassFilter(Class matchedClass) { 19 | this.matchedClass = matchedClass; 20 | } 21 | 22 | @Override 23 | public boolean matches(ItemStack stack) { 24 | return !stack.isEmpty() && matchedClass.isInstance(stack.getItem()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ItemInsertableFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.ItemInsertable; 14 | 15 | /** An {@link ItemFilter} that checks to see if the given {@link ItemInsertable} could have the stack inserted into it, 16 | * right now. */ 17 | public final class ItemInsertableFilter implements ItemFilter { 18 | 19 | public final ItemInsertable insertable; 20 | 21 | public ItemInsertableFilter(ItemInsertable insertable) { 22 | this.insertable = insertable; 23 | } 24 | 25 | @Override 26 | public boolean matches(ItemStack stack) { 27 | if (stack.isEmpty()) { 28 | // Bit strange, because inserting an empty stack will always return 29 | // the empty stack, which indicates a successful insertion. 30 | return true; 31 | } 32 | ItemStack leftover = insertable.attemptInsertion(stack, Simulation.SIMULATE); 33 | return leftover.isEmpty() || leftover.getCount() < stack.getCount(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ItemStackFilterUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import alexiil.mc.lib.attributes.misc.LibBlockAttributes; 11 | 12 | public enum ItemStackFilterUtil { 13 | ; 14 | 15 | /** Attempts to find the maximum stack amount from all of the stacks in the filter. */ 16 | public static int findMaximumStackAmount(ItemFilter filter) { 17 | if (filter == ConstantItemFilter.ANYTHING) { 18 | return 64; 19 | } 20 | if (filter == ConstantItemFilter.NOTHING) { 21 | return 0; 22 | } 23 | 24 | if (filter instanceof ExactItemStackFilter) { 25 | return ((ExactItemStackFilter) filter).stack.getMaxCount(); 26 | } 27 | 28 | if (filter instanceof AggregateItemFilter) { 29 | int max = 1; 30 | for (ItemFilter inner : (AggregateItemFilter) filter) { 31 | max = Math.max(max, findMaximumStackAmount(inner)); 32 | } 33 | return max; 34 | } 35 | 36 | if (filter instanceof ReadableItemFilter) { 37 | LibBlockAttributes.LOGGER.warn("Encountered an unknown readable filter " + filter.getClass() 38 | + " - ItemStackFilterUtil.findMaximumStackAmount should probably have support for it!"); 39 | } 40 | return 64; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ItemTagFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import net.minecraft.item.Item; 14 | import net.minecraft.registry.Registries; 15 | import net.minecraft.registry.entry.RegistryEntry; 16 | import net.minecraft.registry.tag.TagKey; 17 | 18 | /** A {@link ResolvableItemFilter} that matches any {@link Item}s in a {@link TagKey}. */ 19 | public final class ItemTagFilter implements ResolvableItemFilter { 20 | 21 | public final TagKey tag; 22 | 23 | public ItemTagFilter(TagKey tag) { 24 | this.tag = tag; 25 | } 26 | 27 | @Override 28 | public ReadableItemFilter resolve() { 29 | List items = new ArrayList<>(); 30 | for (RegistryEntry entry : Registries.ITEM.iterateEntries(tag)) { 31 | items.add(entry.value()); 32 | } 33 | return ExactItemFilter.anyOf(items); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/filter/ResolvableItemFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.filter; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | /** A type of {@link ReadableItemFilter} that may be resolved at a later time to a fixed {@link ReadableItemFilter}, but 13 | * which isn't constant over time. (For example item tags may be reloaded, but are stored in a static field and so don't 14 | * need to be re-created often. (And can be read)). */ 15 | @FunctionalInterface 16 | public interface ResolvableItemFilter extends ReadableItemFilter { 17 | 18 | /** Resolves this {@link ReadableItemFilter}. Note that this must return one of the valid types of 19 | * {@link ReadableItemFilter}, except this! 20 | *

21 | * This is intended for use-cases where you actually need to read the filter - for other cases there's usually 22 | * little reason to call this, as "matches" should be faster for most reasonable implementations. (However some 23 | * implementations - for example lambdas - might be faster to call multiple times if you resolve them before 24 | * checking them). */ 25 | ReadableItemFilter resolve(); 26 | 27 | /** {@inheritDoc} 28 | *

29 | * This is overridden primarily for lambdas - most implementing classes are expected to override this, because it 30 | * will most likely be faster. */ 31 | @Override 32 | default boolean matches(ItemStack stack) { 33 | ReadableItemFilter resolved = resolve(); 34 | if (resolved instanceof ResolvableItemFilter) { 35 | throw new IllegalStateException( 36 | getClass() + "'s 'resolve()' method returned " + resolved + ", which isn't a fixed filter!" 37 | ); 38 | } 39 | ReadableItemFilter.checkValidity(resolved); 40 | return resolved.matches(stack); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/CombinedItemInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import net.minecraft.item.ItemStack; 14 | 15 | import alexiil.mc.lib.attributes.Simulation; 16 | import alexiil.mc.lib.attributes.item.ItemInsertable; 17 | import alexiil.mc.lib.attributes.item.filter.AggregateItemFilter; 18 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 19 | import alexiil.mc.lib.attributes.misc.AbstractCombined; 20 | 21 | public final class CombinedItemInsertable extends AbstractCombined implements ItemInsertable { 22 | 23 | public CombinedItemInsertable(List list) { 24 | super(list); 25 | } 26 | 27 | @Override 28 | public ItemStack attemptInsertion(ItemStack stack, Simulation simulation) { 29 | for (ItemInsertable insertable : list) { 30 | stack = insertable.attemptInsertion(stack, simulation); 31 | if (stack.isEmpty()) { 32 | return ItemStack.EMPTY; 33 | } 34 | } 35 | return stack; 36 | } 37 | 38 | @Override 39 | public ItemFilter getInsertionFilter() { 40 | List filters = new ArrayList<>(list.size()); 41 | for (int i = 0; i < list.size(); i++) { 42 | filters.add(list.get(i).getInsertionFilter()); 43 | } 44 | return AggregateItemFilter.anyOf(filters); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/EmptyItemExtractable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.ItemExtractable; 14 | import alexiil.mc.lib.attributes.item.ItemInsertable; 15 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 16 | import alexiil.mc.lib.attributes.misc.NullVariant; 17 | 18 | /** An {@link ItemExtractable} that never returns any items from 19 | * {@link #attemptExtraction(ItemFilter, int, Simulation)}. */ 20 | public enum EmptyItemExtractable implements ItemExtractable, NullVariant { 21 | /** An {@link ItemExtractable} that should be treated as equal to null in all circumstances - that is any checks 22 | * that depend on an object being extractable should be considered FALSE for this instance. */ 23 | NULL, 24 | 25 | /** An {@link ItemExtractable} that informs callers that it will push items into a nearby {@link ItemInsertable}, 26 | * but doesn't expose any other item based attributes. 27 | *

28 | * The buildcraft quarry is a good example of this - it doesn't have any inventory slots itself and it pushes items 29 | * out of it as it mines them from the world, but item pipes should still connect to it so that it can insert into 30 | * them. */ 31 | SUPPLIER; 32 | 33 | private final String str = "EmptyItemExtractable." + name(); 34 | 35 | @Override 36 | public ItemStack attemptExtraction(ItemFilter filter, int maxCount, Simulation simulation) { 37 | return ItemStack.EMPTY; 38 | } 39 | 40 | @Override 41 | public ItemExtractable getPureExtractable() { 42 | return this; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return str; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/FilteredItemExtractable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.ItemExtractable; 14 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 15 | 16 | public final class FilteredItemExtractable implements ItemExtractable { 17 | private final ItemExtractable real; 18 | public final ItemFilter filter; 19 | 20 | public FilteredItemExtractable(ItemExtractable real, ItemFilter filter) { 21 | this.real = real; 22 | this.filter = filter; 23 | } 24 | 25 | @Override 26 | public ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) { 27 | return real.attemptExtraction(filter.and(this.filter), maxAmount, simulation); 28 | } 29 | 30 | @Override 31 | public ItemStack attemptAnyExtraction(int maxAmount, Simulation simulation) { 32 | return real.attemptExtraction(filter, maxAmount, simulation); 33 | } 34 | 35 | @Override 36 | public ItemExtractable filtered(ItemFilter filter) { 37 | return new FilteredItemExtractable(real, filter.and(this.filter)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/FilteredItemInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.ItemInsertable; 14 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 15 | 16 | /** An {@link ItemInsertable} that delegates to another {@link ItemInsertable}, but has an additional filter as to what 17 | * can be inserted. */ 18 | public final class FilteredItemInsertable implements ItemInsertable { 19 | 20 | private final ItemInsertable real; 21 | public final ItemFilter filter; 22 | 23 | public FilteredItemInsertable(ItemInsertable real, ItemFilter filter) { 24 | this.real = real; 25 | this.filter = filter; 26 | } 27 | 28 | @Override 29 | public ItemFilter getInsertionFilter() { 30 | return real.getInsertionFilter().and(filter); 31 | } 32 | 33 | @Override 34 | public ItemStack attemptInsertion(ItemStack stack, Simulation simulation) { 35 | if (stack.isEmpty() || !filter.matches(stack)) { 36 | return stack; 37 | } 38 | return real.attemptInsertion(stack, simulation); 39 | } 40 | 41 | @Override 42 | public ItemInsertable filtered(ItemFilter filter) { 43 | return new FilteredItemInsertable(real, filter.and(this.filter)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/FilteredItemTransferable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.ItemTransferable; 14 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 15 | 16 | public final class FilteredItemTransferable implements ItemTransferable { 17 | private final ItemTransferable real; 18 | public final ItemFilter filter; 19 | 20 | public FilteredItemTransferable(ItemTransferable real, ItemFilter filter) { 21 | this.real = real; 22 | this.filter = filter; 23 | } 24 | 25 | @Override 26 | public ItemStack attemptInsertion(ItemStack stack, Simulation simulation) { 27 | if (stack.isEmpty() || !filter.matches(stack)) { 28 | return stack; 29 | } 30 | return real.attemptInsertion(stack, simulation); 31 | } 32 | 33 | @Override 34 | public ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) { 35 | return real.attemptExtraction(filter.and(this.filter), maxAmount, simulation); 36 | } 37 | 38 | @Override 39 | public ItemStack attemptAnyExtraction(int maxAmount, Simulation simulation) { 40 | return real.attemptExtraction(filter, maxAmount, simulation); 41 | } 42 | 43 | @Override 44 | public ItemTransferable filtered(ItemFilter filter) { 45 | return new FilteredItemTransferable(real, filter.and(this.filter)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/RejectingItemInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.ItemInsertable; 14 | import alexiil.mc.lib.attributes.item.filter.ConstantItemFilter; 15 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 16 | import alexiil.mc.lib.attributes.misc.NullVariant; 17 | 18 | /** An {@link ItemInsertable} that always refuses to accept any inserted {@link ItemStack}. */ 19 | public enum RejectingItemInsertable implements ItemInsertable, NullVariant { 20 | NULL, 21 | EXTRACTOR; 22 | 23 | private final String str = "RejectingItemInsertable." + name(); 24 | 25 | @Override 26 | public ItemStack attemptInsertion(ItemStack stack, Simulation simulation) { 27 | return stack; 28 | } 29 | 30 | @Override 31 | public ItemFilter getInsertionFilter() { 32 | return ConstantItemFilter.NOTHING; 33 | } 34 | 35 | @Override 36 | public ItemInsertable getPureInsertable() { 37 | return this; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return str; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/SimpleFixedItemInvExtractable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.FixedItemInv; 14 | import alexiil.mc.lib.attributes.item.ItemExtractable; 15 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 16 | 17 | /** @deprecated Use {@link GroupedItemInvFixedWrapper} instead of this! */ 18 | @Deprecated(since = "0.4.0", forRemoval = true) 19 | public final class SimpleFixedItemInvExtractable implements ItemExtractable { 20 | 21 | private final GroupedItemInvFixedWrapper wrapper; 22 | 23 | public SimpleFixedItemInvExtractable(FixedItemInv inv) { 24 | this.wrapper = new GroupedItemInvFixedWrapper(inv); 25 | } 26 | 27 | @Override 28 | public ItemStack attemptExtraction(ItemFilter filter, int maxCount, Simulation simulation) { 29 | return wrapper.attemptExtraction(filter, maxCount, simulation); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/impl/SimpleFixedItemInvInsertable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | import alexiil.mc.lib.attributes.item.FixedItemInv; 14 | import alexiil.mc.lib.attributes.item.FixedItemInvView; 15 | import alexiil.mc.lib.attributes.item.ItemInsertable; 16 | import alexiil.mc.lib.attributes.item.filter.ItemFilter; 17 | 18 | /** An {@link ItemInsertable} wrapper over an {@link FixedItemInv}. This implementation is the naive implementation 19 | * where every insertion operation will look at every slot in the target inventory in order to insert into the most 20 | * appropriate slot first. As such the use of this class is discouraged whenever a more efficient version can be made 21 | * (unless the target inventory has a very small {@link FixedItemInvView#getSlotCount() size}. 22 | * 23 | * @deprecated Use {@link GroupedItemInvFixedWrapper} instead. */ 24 | @Deprecated(since = "0.4.0", forRemoval = true) 25 | public final class SimpleFixedItemInvInsertable implements ItemInsertable { 26 | 27 | private final GroupedItemInvFixedWrapper wrapper; 28 | 29 | public SimpleFixedItemInvInsertable(FixedItemInv inv) { 30 | this.wrapper = new GroupedItemInvFixedWrapper(inv); 31 | } 32 | 33 | @Override 34 | public ItemStack attemptInsertion(ItemStack stack, Simulation simulation) { 35 | return wrapper.attemptInsertion(stack, simulation); 36 | } 37 | 38 | @Override 39 | public ItemFilter getInsertionFilter() { 40 | return wrapper.getInsertionFilter(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/item/mixin/impl/DropperBlockMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.mixin.impl; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 15 | 16 | import net.minecraft.block.DropperBlock; 17 | import net.minecraft.block.entity.DispenserBlockEntity; 18 | import net.minecraft.server.world.ServerWorld; 19 | import net.minecraft.util.ActionResult; 20 | import net.minecraft.util.math.BlockPointerImpl; 21 | import net.minecraft.util.math.BlockPos; 22 | 23 | import alexiil.mc.lib.attributes.item.mixin.HopperHooks; 24 | 25 | @Mixin(DropperBlock.class) 26 | public class DropperBlockMixin { 27 | 28 | private static final String DISPENSER_BLOCK_ENTITY = "Lnet/minecraft/block/entity/DispenserBlockEntity;"; 29 | 30 | @Inject( 31 | method = "dispense", at = @At(value = "INVOKE_ASSIGN", target = DISPENSER_BLOCK_ENTITY + "chooseNonEmptySlot(Lnet/minecraft/util/math/random/Random;)I"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD 32 | ) 33 | void dispenseIntoLba( 34 | ServerWorld serverWorld, BlockPos pos, CallbackInfo ci, BlockPointerImpl pointer, DispenserBlockEntity be, 35 | int index 36 | ) { 37 | ActionResult result = HopperHooks.tryDispense(be, index); 38 | if (result != ActionResult.PASS) { 39 | ci.cancel(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/AbstractCombined.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import java.util.List; 11 | 12 | /** Implementation helper class for LBA {@link Combined}. */ 13 | public abstract class AbstractCombined implements Combined { 14 | 15 | protected final List list; 16 | 17 | protected AbstractCombined(List list) { 18 | this.list = list; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object obj) { 23 | if (obj == this) return true; 24 | if (obj == null) return false; 25 | if (getClass() != obj.getClass()) { 26 | return false; 27 | } 28 | return list.equals(((AbstractCombined) obj).list); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | return list.hashCode(); 34 | } 35 | 36 | @Override 37 | public int getSubObjectCount() { 38 | return list.size(); 39 | } 40 | 41 | @Override 42 | public Object getSubObject(int index) { 43 | return list.get(index); 44 | } 45 | 46 | @Override 47 | public String toString() { 48 | if (list.isEmpty()) { 49 | return getClass().getSimpleName() + "{}"; 50 | } 51 | StringBuilder sb = new StringBuilder(); 52 | sb.append(getClass().getSimpleName()); 53 | sb.append("{"); 54 | for (Object o : list) { 55 | sb.append(" "); 56 | sb.append(o); 57 | sb.append("\n"); 58 | } 59 | sb.append("}"); 60 | return sb.toString(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/AbstractItemBasedAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import net.minecraft.item.ItemStack; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | 14 | /** Skeleton class for use when exposing an attribute (like a fluid inventory) from an item that is contained in a 15 | * reference. */ 16 | public abstract class AbstractItemBasedAttribute { 17 | 18 | protected final Reference stackRef; 19 | protected final LimitedConsumer excessStacks; 20 | 21 | protected AbstractItemBasedAttribute(Reference stackRef, LimitedConsumer excessStacks) { 22 | this.stackRef = stackRef; 23 | this.excessStacks = excessStacks; 24 | } 25 | 26 | /** Attempts to place the stacks in the reference and excess. 27 | * 28 | * @param oldStack A copied stack from {@link #stackRef}, but decreased by 1. 29 | * @param newStack The modified stack that was split off from {@link #stackRef}. */ 30 | public boolean setStacks(Simulation simulation, ItemStack oldStack, ItemStack newStack) { 31 | if (oldStack.isEmpty() && stackRef.set(newStack, simulation)) { 32 | return true; 33 | } else if (stackRef.isValid(oldStack) && excessStacks.offer(newStack, simulation)) { 34 | boolean did = stackRef.set(oldStack, simulation); 35 | if (!did) { 36 | throw new IllegalStateException( 37 | "Failed to set the stack! (Even though we just checked this up above...)" // 38 | + "\n\tstackRef = " + stackRef + "\n\tstack = " + oldStack 39 | ); 40 | } 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return getClass().getName() + " in " + stackRef; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/CallableRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import java.util.function.Consumer; 11 | import java.util.function.Predicate; 12 | import java.util.function.Supplier; 13 | 14 | /** A {@link Reference} that delegates to a {@link Supplier} for {@link #get()}, {@link Consumer} for 15 | * {@link #set(Object)}, and a {@link Predicate} for {@link #isValid(Object)}. */ 16 | public final class CallableRef implements Reference { 17 | 18 | private final Supplier getter; 19 | private final Consumer setter; 20 | private final Predicate canSet; 21 | 22 | public CallableRef(Supplier getter, Consumer setter, Predicate canSet) { 23 | this.getter = getter; 24 | this.setter = setter; 25 | this.canSet = canSet; 26 | } 27 | 28 | @Override 29 | public T get() { 30 | return getter.get(); 31 | } 32 | 33 | @Override 34 | public boolean set(T value) { 35 | if (canSet.test(value)) { 36 | setter.accept(value); 37 | return true; 38 | } else { 39 | return false; 40 | } 41 | } 42 | 43 | @Override 44 | public boolean isValid(T value) { 45 | return canSet.test(value); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/Combined.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import alexiil.mc.lib.attributes.AttributeCombiner; 11 | 12 | /** An {@link Object} that combines several sub objects of one type into a single object of the same type. This is 13 | * generally the inverse of {@link AttributeCombiner#combine(java.util.List)}. */ 14 | public interface Combined { 15 | 16 | /** @return The number of sub-objects that this combines to make. May return -1 if this cannot easily expose the 17 | * sub-objects cleanly. */ 18 | int getSubObjectCount(); 19 | 20 | /** @param index The index, between 0 and {@link #getSubObjectCount()}. 21 | * @throws RuntimeException if the index is <0 or >={@link #getSubObjectCount()}. */ 22 | Object getSubObject(int index); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/DestroyableRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | /** A {@link Reference} that can be modified until {@link #destroy()} is called, after which all calls to 11 | * {@link #set(Object)} and {@link #isValid(Object)} will return false. */ 12 | public final class DestroyableRef implements Reference { 13 | 14 | private final Reference ref; 15 | private boolean isAlive = true; 16 | 17 | public DestroyableRef(Reference ref) { 18 | this.ref = ref; 19 | } 20 | 21 | /** Prevents {@link #set(Object)} from returning true in the future. */ 22 | public void destroy() { 23 | isAlive = false; 24 | } 25 | 26 | @Override 27 | public T get() { 28 | return ref.get(); 29 | } 30 | 31 | @Override 32 | public boolean set(T value) { 33 | return isAlive && ref.set(value); 34 | } 35 | 36 | @Override 37 | public boolean isValid(T value) { 38 | return isAlive && ref.isValid(value); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/LibBlockAttributes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Logger; 14 | 15 | import net.fabricmc.loader.api.FabricLoader; 16 | import net.fabricmc.loader.api.ModContainer; 17 | 18 | import net.minecraft.util.Identifier; 19 | 20 | public class LibBlockAttributes { 21 | private static final String MODID = "libblockattributes"; 22 | public static final Logger LOGGER = LogManager.getLogger(MODID); 23 | 24 | public static final String MODID_CORE = "libblockattributes_core"; 25 | public static final String MODID_ITEMS = "libblockattributes_items"; 26 | public static final String MODID_FLUIDS = "libblockattributes_fluids"; 27 | 28 | public enum LbaModule { 29 | ALL(MODID), 30 | CORE(MODID_CORE), 31 | ITEMS(MODID_ITEMS), 32 | FLUIDS(MODID_FLUIDS); 33 | 34 | public final String id; 35 | 36 | private LbaModule(String id) { 37 | this.id = id; 38 | } 39 | 40 | public Identifier id(String path) { 41 | return new Identifier(id, path); 42 | } 43 | 44 | @Nullable 45 | public ModContainer getModContainer() { 46 | return FabricLoader.getInstance().getModContainer(id).orElse(null); 47 | } 48 | } 49 | 50 | public static Identifier id(String path) { 51 | return new Identifier(MODID, path); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/NullVariant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | /** Marker interface for the various null-like implementations of item and fluid inventories. */ 11 | public interface NullVariant {} 12 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/OpenWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import javax.annotation.Nullable; 11 | 12 | import net.minecraft.inventory.Inventory; 13 | import net.minecraft.inventory.SidedInventory; 14 | 15 | import alexiil.mc.lib.attributes.Convertible; 16 | import alexiil.mc.lib.attributes.item.FixedItemInvView; 17 | import alexiil.mc.lib.attributes.item.compat.FixedInventoryViewVanillaWrapper; 18 | import alexiil.mc.lib.attributes.item.compat.FixedSidedInventoryVanillaWrapper; 19 | 20 | /** An {@link Object} that wraps an object of a different type into some other type. This is generally the inverse of 21 | * {@link Convertible#convertTo(Class)}. */ 22 | public interface OpenWrapper { 23 | 24 | /** @return The object that this wraps, or null if the wrapped object cannot be converted cleanly without exposing 25 | * additional details. 26 | *

27 | * For example LBA's {@link Inventory} to {@link FixedItemInvView} wrapper 28 | * ({@link FixedInventoryViewVanillaWrapper}) implements this to return the {@link Inventory}, but the 29 | * {@link SidedInventory} variant ({@link FixedSidedInventoryVanillaWrapper}) returns null, as it is not 30 | * possible to cleanly open the original inventory without exposing additional slots. */ 31 | @Nullable 32 | Object getWrapped(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/Ref.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | /** A simple {@link Reference} that holds the value directly in the field {@link #obj}, and accepts any new value. */ 11 | public final class Ref implements Reference { 12 | public T obj; 13 | 14 | public Ref(T obj) { 15 | this.obj = obj; 16 | } 17 | 18 | @Override 19 | public T get() { 20 | return obj; 21 | } 22 | 23 | @Override 24 | public boolean set(T value) { 25 | obj = value; 26 | return true; 27 | } 28 | 29 | @Override 30 | public boolean isValid(T value) { 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/Saveable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import net.minecraft.nbt.NbtCompound; 11 | 12 | /** An object that can be saved and loaded (in place, unlike fluid keys or volumes which must be loaded from a 13 | * specialised static method). */ 14 | public interface Saveable { 15 | default NbtCompound toTag() { 16 | return toTag(new NbtCompound()); 17 | } 18 | 19 | NbtCompound toTag(NbtCompound tag); 20 | 21 | void fromTag(NbtCompound tag); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/SimulatableRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import java.util.function.Supplier; 11 | 12 | import alexiil.mc.lib.attributes.Simulation; 13 | 14 | /** A variant of {@link CallableRef} that uses {@link Supplier} for {@link #get()}, and {@link LimitedConsumer} for 15 | * {@link #set(Object)} and {@link #isValid(Object)}. */ 16 | public final class SimulatableRef implements Reference { 17 | 18 | private final Supplier getter; 19 | private final LimitedConsumer setter; 20 | 21 | public SimulatableRef(Supplier getter, LimitedConsumer setter) { 22 | this.getter = getter; 23 | this.setter = setter; 24 | } 25 | 26 | @Override 27 | public T get() { 28 | return getter.get(); 29 | } 30 | 31 | @Override 32 | public boolean set(T value) { 33 | return setter.offer(value); 34 | } 35 | 36 | @Override 37 | public boolean isValid(T value) { 38 | return setter.wouldAccept(value); 39 | } 40 | 41 | @Override 42 | public boolean set(T value, Simulation simulation) { 43 | return setter.offer(value, simulation); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/StackReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | import net.minecraft.item.ItemStack; 11 | import net.minecraft.screen.slot.Slot; 12 | 13 | /** Specialist {@link Reference} interface for {@link ItemStack}s. NOTE: You cannot assume that all 14 | * {@link Reference}s for {@link ItemStack}s will implement this, as this is only provided in the rare case that someone 15 | * needs to perform an "instance of" check. 16 | *

17 | * (For example {@link PlayerInvUtil#referenceSlot(net.minecraft.screen.slot.Slot)} uses this to attempt to convert a 18 | * {@link Slot} into a {@link StackReference} directly, rather than generate a potentially-inaccurate reference from the 19 | * slot. */ 20 | public interface StackReference extends Reference {} 21 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/UnmodifiableRef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc; 9 | 10 | /** A {@link Reference} that may be obtained through {@link #get()}, but never allows the value to be changed in 11 | * {@link #set(Object)}. */ 12 | public final class UnmodifiableRef implements Reference { 13 | 14 | public final T obj; 15 | 16 | public UnmodifiableRef(T obj) { 17 | this.obj = obj; 18 | } 19 | 20 | @Override 21 | public T get() { 22 | return obj; 23 | } 24 | 25 | @Override 26 | public boolean set(T value) { 27 | return false; 28 | } 29 | 30 | @Override 31 | public boolean isValid(T value) { 32 | return false; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/misc/compat/mod/LbaModCompatLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.misc.compat.mod; 9 | 10 | import java.lang.reflect.Field; 11 | import java.lang.reflect.Method; 12 | 13 | public abstract class LbaModCompatLoader { 14 | protected static Class c(String name) throws ClassNotFoundException { 15 | return Class.forName(name, false, LbaModCompatLoader.class.getClassLoader()); 16 | } 17 | 18 | protected static void requireField(Class cls, String name, Class type) throws ReflectiveOperationException { 19 | Field f = cls.getField(name); 20 | if (!type.equals(f.getType())) { 21 | throw new NoSuchFieldException("Needed the field " + f + " to be of type " + type); 22 | } 23 | } 24 | 25 | protected static void requireMethod(Class cls, String name, Class[] args, Class ret) 26 | throws ReflectiveOperationException { 27 | 28 | Method m = cls.getMethod(name, args); 29 | if (!ret.equals(m.getReturnType())) { 30 | throw new NoSuchMethodException("Needed the method " + m + " to return " + ret); 31 | } 32 | } 33 | 34 | protected static void requireClassExtends(Class cls, Class expectedParent) 35 | throws ReflectiveOperationException { 36 | 37 | if (!expectedParent.isAssignableFrom(cls)) { 38 | throw new ReflectiveOperationException("Needed the " + cls + " to extend " + expectedParent); 39 | } 40 | } 41 | 42 | protected static boolean hasOldMethod(Class cls, String name, Class[] args, Class ret) { 43 | try { 44 | Method m = cls.getMethod(name, args); 45 | return ret.equals(m.getReturnType()); 46 | } catch (NoSuchMethodException ignored) { 47 | return false; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/mixin/api/UnloadableBlockEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.mixin.api; 9 | 10 | import net.minecraft.block.entity.BlockEntity; 11 | 12 | /** Optional interface for {@link BlockEntity}s to implement if they need to do something when the chunk they are in is 13 | * unloaded. 14 | *

15 | * In 1.17 minecraft also calls {@link BlockEntity#markRemoved()} after this is called, so you don't need to put 16 | * duplicate logic in both. */ 17 | public interface UnloadableBlockEntity { 18 | void onChunkUnload(); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/mixin/impl/mx/ClientWorldMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.mixin.impl.mx; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | import net.minecraft.block.entity.BlockEntity; 16 | import net.minecraft.client.world.ClientWorld; 17 | import net.minecraft.world.chunk.WorldChunk; 18 | 19 | import alexiil.mc.lib.attributes.mixin.api.UnloadableBlockEntity; 20 | 21 | @Mixin(ClientWorld.class) 22 | public class ClientWorldMixin { 23 | 24 | @Inject(at = @At("HEAD"), method = "unloadBlockEntities(Lnet/minecraft/world/chunk/WorldChunk;)V") 25 | private void lba_unloadBlockEntities(WorldChunk chunk, CallbackInfo ci) { 26 | for (BlockEntity be : chunk.getBlockEntities().values()) { 27 | if (be instanceof UnloadableBlockEntity) { 28 | ((UnloadableBlockEntity) be).onChunkUnload(); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/alexiil/mc/lib/attributes/mixin/impl/mx/ServerWorldMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.mixin.impl.mx; 9 | 10 | import org.spongepowered.asm.mixin.Mixin; 11 | import org.spongepowered.asm.mixin.injection.At; 12 | import org.spongepowered.asm.mixin.injection.Inject; 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 14 | 15 | import net.minecraft.block.entity.BlockEntity; 16 | import net.minecraft.server.world.ServerWorld; 17 | import net.minecraft.world.chunk.WorldChunk; 18 | 19 | import alexiil.mc.lib.attributes.mixin.api.UnloadableBlockEntity; 20 | 21 | @Mixin(ServerWorld.class) 22 | public class ServerWorldMixin { 23 | 24 | @Inject(at = @At("HEAD"), method = "unloadEntities(Lnet/minecraft/world/chunk/WorldChunk;)V") 25 | private void lba_unloadBlockEntities(WorldChunk chunk, CallbackInfo ci) { 26 | for (BlockEntity be : chunk.getBlockEntities().values()) { 27 | if (be instanceof UnloadableBlockEntity) { 28 | ((UnloadableBlockEntity) be).onChunkUnload(); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/icon.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/icon_512.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/icon_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/icon_all.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/icon_fat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/icon_fat.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/icon_fluids.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/icon_fluids.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/icon_items.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/icon_items.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "libblockattributes.fluid.empty": "Empty", 3 | 4 | "libblockattributes.fluid.amount": "%1$s %2$s", 5 | "libblockattributes.fluid.name": "%1$s of %2$s", 6 | "libblockattributes.fluid.tank_empty.short": "0/%1$s", 7 | "libblockattributes.fluid.tank_empty.long": "Empty %1$s Tank", 8 | "libblockattributes.fluid.tank_full.short": "%1$s/%1$s", 9 | "libblockattributes.fluid.tank_full.long": "Full %1$s Tank", 10 | "libblockattributes.fluid.tank_partial.short": "%1$s/%2$s", 11 | "libblockattributes.fluid.tank_partial.long": "%1$s in a %2$s Tank", 12 | "libblockattributes.fluid.tank_multi_unit.short": "%1$s/%2$s", 13 | "libblockattributes.fluid.tank_multi_unit.long": "%1$s in a %2$s Tank", 14 | "libblockattributes.fluid.multi_unit.2": "%1$s %2$s and %3$s %4$s", 15 | "libblockattributes.fluid.multi_unit.3": "%1$s %2$s, %3$s %4$s, and %5$s %6$s", 16 | "libblockattributes.fluid.multi_unit.4": "%1$s %2$s, %3$s %4$s, %5$s %6$s, and %7$s %8$s", 17 | "libblockattributes.fluid.multi_unit.combiner": "%1$s, %2$s %3$s", 18 | "libblockattributes.fluid.multi_unit.end": "%1$s, and %2$s %3$s", 19 | "libblockattributes.fluid.flow_rate.short": "%1$s/%2$s", 20 | "libblockattributes.fluid.flow_rate.long": "%1$s per %2$s", 21 | 22 | "libblockattributes.time_unit.tick.singular": "Tick", 23 | "libblockattributes.time_unit.tick.plural": "Ticks", 24 | "libblockattributes.time_unit.tick.symbol": "t", 25 | "libblockattributes.time_unit.second.singular": "Second", 26 | "libblockattributes.time_unit.second.plural": "Seconds", 27 | "libblockattributes.time_unit.second.symbol": "s", 28 | 29 | "libblockattributes.fluid_unit.bucket.singular": "Bucket", 30 | "libblockattributes.fluid_unit.bucket.plural": "Buckets", 31 | "libblockattributes.fluid_unit.bucket.symbol": "B", 32 | "libblockattributes.fluid_unit.bottle.singular": "Bottle", 33 | "libblockattributes.fluid_unit.bottle.plural": "Bottles", 34 | "libblockattributes.fluid_unit.bottle.symbol": "b", 35 | 36 | "libblockattributes.fluid_property.advanced_prefix_key": "Property: %1$s", 37 | "libblockattributes.fluid_property.advanced_prefix_value": "Value: %1$s" 38 | } 39 | -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/textures/fluid/potion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexIIL/LibBlockAttributes/06c99192bd9aea1c9223e4ccfdb02cf90be9c66c/src/main/resources/assets/libblockattributes/textures/fluid/potion.png -------------------------------------------------------------------------------- /src/main/resources/assets/libblockattributes/textures/fluid/potion.png.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "animation": { 3 | "frametime": 2 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/assets/minecraft/atlases/blocks.json: -------------------------------------------------------------------------------- 1 | { 2 | "sources": [ 3 | { 4 | "type": "directory", 5 | "source": "fluid", 6 | "prefix": "fluid/" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.0.txt: -------------------------------------------------------------------------------- 1 | First release. 2 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.1.txt: -------------------------------------------------------------------------------- 1 | Rename "IStackFilter" to "IItemFilter" 2 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.10.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added missing FluidVolume.toTag() methods. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.11.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Massive overhaul of how fluids are registered and handled. 4 | * Now fluids are based on any registry, rather than just the fluid registry 5 | * This allows potions to be used as fluids in tanks and gui's. 6 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.12.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed FluidVolume.fromTag throwing an exception when deserialising empty fluids. 4 | * Fixed water and potions returning ABGR colours rather than ARGB colours. 5 | * Fixed water and lava using the wrong texture. 6 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.13.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Fixed WaterFluidVolume's not being read properly by the deserialiser. 4 | * Added IFluidItem: an interface for items to implement so that they can be filled or drained. 5 | * Note that this is temporary: in the future items will need some way to expose normal attributes. 6 | * Added FluidVolumeUtil.move(IFluidExtractable from, IFluidInsertable to) for quickly and easily moving fluids from one object to another. 7 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.14.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed a crash when you merged water volumes together. 4 | * Added a lot of precondition checking to various methods. 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.15.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Removed IDelegatingAttributeBlock, as it's basically useless. 4 | 5 | Changes: 6 | 7 | * Added FluidWorldUtil.drain(World, BlockPos, Simulation), which attempts to drain a FluidVolume from that particular position in the world. 8 | * Fixed a bug where SimpleFixedFluidInvInsertable and SimpleFixedItemInvInsertable didn't respect their respective inventories "do not modify" rule. 9 | * Added FluidKey.fromWorld(ViewableWorld, BlockPos) -> FluidVolume for FluidWorldUtil.drain to use. 10 | * Added a mixin to vanilla's FluidBlock to get the Fluid object contained within. 11 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.16.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Made the fluid sprite and name mandatory components for the fluid key builder 4 | * Renamed "FluidVolume.getTextComponent()" to "FluidVolume.getName()" 5 | 6 | Changes: 7 | 8 | * Fixed a crash when splitting a single unit of fluid from a BiomeSourcedFluidVolume 9 | * Added methods to get the tooltip from a FluidKey itself as well as the FluidVolume 10 | * Changed the sprite identifier for potions to "libblockattributes:fluid/potion" rather than the water one 11 | * Fixed a bug where multiple biome sources for water didn't produce the corret render colour. 12 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.17.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Removed the generic type token from IAttributeBlock.addAllAttributes() 4 | * Added listener removal tokens: so that you can listen for when your listener is removed from the object you were listening to. 5 | 6 | Changes: 7 | 8 | * Changed custom attribute adders to be stored in a list, so that you can add multiple custom ones to an attribute. 9 | * Added FluidVolumeUtil.createItemInventoryInsertable and createItemInventoryExtractable for inserting to and extracting from a held itemstack. 10 | * Added FluidVolumeUtil.interactWithTank for filling or emptying buckets of fluids. 11 | * Added SimpleFixed{Fluid|Item}Inv.toTag() and fromTag(CompoundTag) 12 | * Fixed the potion texture being registered for all sprite atlases, rather than just the block atlas. 13 | * Fixed the potion texture not being defined as an animation. 14 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.18.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Fixed quite a few implementation bugs in FluidVolumeUtil.interactWithTank 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.19.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Fixed another bug with FLuidVolumeUtil.interactWithTank 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.2.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Made IItemFilter no longer extend java.util.Predicate. 4 | 5 | Changes: 6 | 7 | * Improved SimpleFixedItemInvInsertable.getInsertionFilter to combine all of the filters from the wrapped inventory. 8 | * Added IItemFilter.negate(), IItemFilter.and(), and IItemFilter.or() as replacements for said methods in java.util.Predicate. 9 | * Added IItemFilter.asPredicate() as a replacement for extending it. 10 | * Added various methods to AggregateStackFilter for combining filters. 11 | * Made IFixedItemInv.getInsertable(int[] slots) and getExtractable(int[] slots) return the null instances for RejectingItemInsertable and EmptyItemExtractable when the given slot array is empty. 12 | 13 | Bug Fixes: 14 | 15 | * Fixed ItemInvUtil providing invalid IItemInsertable and IItemExtractable for vanilla composter blocks. 16 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.20.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Actually fixed the bug that 0.1.19 promised to fix. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.21.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Really fixed the bug that 0.1.19 and 0.1.20 promised to fix. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.22.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Fixed IFluidInsertable.getInsertionFilter()'s default implementation not working with implementations of IFluidInsertable.attemptInsertion that require a minimum amount of fluid. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.23.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added FluidUnit: so that different fluids can pick the most appropriate unit (so water uses buckets, and potions use bottles) 4 | * Added various fluid rendering helpers 5 | * Add basic silk fluid compatibility 6 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.3.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added a marker interface IReadableItemFilter that extends IItemFilter. 4 | * This is intended for general methods that operate on IItemFilter's. 5 | 6 | Bug Fixes: 7 | 8 | * Actually implement ItemStackFilterUtil.findMaximumStackAmount. 9 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.4.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Moved all of the item attributes out of their own interfaces and into ItemAttributes. 4 | * This fixes a bug where every attribute's null instance was actually null, rather than a null object. 5 | * Renamed "EmptyItemExtractable.NULL_EXTRACTABLE" to "NULL". 6 | * Renamed "RejectingItemInsertable.NULL_INSERTABLE" to "NULL". 7 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.5.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Major refactor of how you create and access attribute instances. 4 | * There's now 3 classes for attributes: Attribute, AttributeDefaulted, and AttributeCombinable 5 | * All of the attribute instance getter methods have been moved into the base Attribute class 6 | * These must be created through the static factory methods in "Attributes" 7 | * Moved IItemFilter.ANY_STACK and IItemFilter.NOTHING to a new class ConstantItemFilter. 8 | 9 | Changes: 10 | 11 | * Added a new class: SearchParameter for specifying how to search for attributes at a given block location 12 | * SearchParamDirectional: used to search in a specific direction. 13 | * SearchParamInVoxel: used to search for attributes but only in a single VoxelShape 14 | * SearchParamDirectionalVoxel: A combined form of the above. 15 | * This can also order the resultant instance list by the order that the search would have encountered them. 16 | * Improved the implementation of AggregateItemFilter.combine. 17 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.6.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed a crash caused by CacheInfo always being null. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.7.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed a crash caused by a misuse of Preconditions 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.8.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Rename IInvChangeListener to IItemInvChangeListener 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.1.9.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Rename SimpleFixedInvExtractable to SimpleFixedItemInvExtractable 4 | * Rename SimpleFixedInvInsertable to SimpleFixedItemInvInsertable 5 | * Moved IListenerToken out into it's own file 6 | * Made CacheInfo's no-arg constuctor private (as there's no cache information available yet) 7 | 8 | Changes: 9 | 10 | * Added fluid attributes as a nearly identical copy of the item attributes 11 | * Instead of ItemStack everything is based on "FluidVolume" and "FluidKey" 12 | * FluidKey is an immutable class with 2 fields: minecraft's Fluid class, and a CompoundTag. 13 | * FluidVolume has Fluid, CompoundTag (modifiable), and amount (also modifiable). 14 | * Everything filter wise is based around FluidKey, while everything else is based around FluidVolume 15 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.10.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to Minecraft 1.18 release candidate 3 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.10.2.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to 1.18.2 4 | * This version should still work on 1.18.1 however, if you don't want to update your mod but do want the other changes here. 5 | * Added one-way compatibility with fabric's transfer API 6 | * Mods using LBA can insert into and extract from vanilla, LBA inventories, and transfer api inventries. 7 | * Mods using transfer API can only insert into and extract from vanilla and transfer api inventories. 8 | * If mods want to insert into and extract from LBA inventories they they will need to add compat with LBA. 9 | * Removed legacy compatibility with TechReborn's fluid code, since it's moved over to transfer api. 10 | * Fixed "FixedInventoryVanillaWrapper" not calling "Inventory.markDirty" whenever it changed the inventory. 11 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.11.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to 1.19.2 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.11.1.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Fixed LBA-Core mixins not applying, leading to `UnloadableBlockEntity.onChunkUnload` never being called (#50). 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.12.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to Minecraft 1.19.3 (PTOM76) 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.13.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to Minecraft 1.19.4 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.14.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to Minecraft 1.20 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.2.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to 19w12b 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.2.1.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Removed SimpleFluidKey and SimpleFluidVolume - you should use NormalFluidKey and NormalFluidVolume instead. 4 | 5 | Changes: 6 | 7 | * Made NormalFluidKey and NormalFluidVolume not-abstract 8 | * Changed FluidKeys.put(Fluid, FluidKey) to also register both the still and flowing variants of fluids if the fluid passed is a vanilla minecraft BaseFluid 9 | * Added NormalFluidKey.builder(), as an (optional) replacement for a new NormalFluidKeyBuilder() 10 | * Added NormalFluidKeyBuilder.build(), which is a shorter way of writing new NormalFluidKey(builder /* extra settings */); 11 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.2.2.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Add support for unregistered vanilla fluids (as well as potions). Currently there's no way to get their sprite or name from the base Fluid object unfortunatly :/ 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.3.0.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Renamed a LOT of classes to be more inline with fabric's naming convention. 4 | * Removed the "I" prefix from every interface that had it. 5 | * SearchParameter -> SearchOption 6 | * SearchParamDirectional -> SearchOptionDirectional 7 | * SearchParamInVoxel -> SearchOptionInVoxel 8 | * SearchParamDirectionalVoxel -> SearchOptionDirectionalVoxel 9 | * AttributeDefaulted -> DefaultedAttribute 10 | * AttributeCombinable -> CombinableAttribute 11 | * IFluidItem -> FluidProviderItem 12 | 13 | Changes: 14 | 15 | * Added much better support for ordinary fluid classes - now lava is defined through the implicit fluids system without any problems. 16 | * Added a static utility class "SearchOptions" which contains factories for creating all of the different types of SearchOption. 17 | * Fixed fluid renders not binding the texture map and setting up blending before rendering. 18 | * Added "FixedItemInvView.offerSelfAsAttribute" and "FixedFluidInvView.offerSelfAsAttribute" to make adding those classes (and subclasses) to an attribute list much quicker. 19 | * Added "FluidVolume.renderGuiRect" as a quicker way of calling "FluidVolume.getRenderer().renderGuiRectangle()" 20 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.3.1.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to 19w13b 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.3.3.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Updated to 19w14b 4 | * Updated fabric-loader requirement to 0.4.0 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.3.4.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * [#4] Added several methods to make working with FluidVolume's a bit easier: 4 | * FluidKey.getRawFluid(): Returns the backing fluid object, or null if the fluid key isn't based on a minecraft `Fluid`. 5 | * FluidVolume.getRawFluid(): Delegate to FluidKey.getRawFluid(). 6 | * FluidVolume.create(Fluid fluid, int amount): Helper for creating a new fluid volume from a minecraft fluid. 7 | * FluidVolume.create(FluidKey key, int amount): Delegates to `key.withAmount(amount)` 8 | * FluidVolume.create(Potion potion, int amount): Helper for creating a new FluidKey from a given potion. 9 | * Added "SlotFixedItemInv" for using FixedItemInv in gui container Slots. 10 | * Vastly improved the behaviour of PartialInventoryFixedWrapper to correctly track modifications made to an ItemStack returned by Inventory.getInvStack. 11 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.3.5.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Fixed several issues with the implementation of PartialInventoryFixedWrapper where exceptions were thrown randomly. 4 | * Added proper checking to FixedItemInv.getInvStack so that it will *always* throw an exception if the returned stack is modified. 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.1.txt: -------------------------------------------------------------------------------- 1 | Breaking changes: 2 | 3 | * Moved several classes from "alexiil.mc.lib.attributes.item.impl" to "alexiil.mc.lib.attributes.item.compat": 4 | * FixedInventoryVanillaWrapper 5 | * FixedInventoryViewVanillaWrapper 6 | * PartialInventoryFixedWrapper (and renamed it to InventoryFixedWrapper) 7 | 8 | Additions: 9 | * Added a new class: SidedInventoryFixedWrapper, which: 10 | * Extends InventoryFixedWrapper 11 | * Implements vanilla minecraft's SidedInventory interface. 12 | 13 | Bug Fixes: 14 | 15 | * Fixed a crash when exposing a InventoryFixedWrapper to a hopper. 16 | * Fixed SlotFixedItemInv not working properly if the current stack is not valid for 17 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.10.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed SidedInventoryFixedWrapper.canInsertInvStack only calling inv.isValidForSlot rather than simulating a full insertion. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.11.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added the missing "setOwnerListener" to SimpleFixedFluidInv. 4 | * Added missing "modmenu:api": true tag to fabric.mod.json 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.13.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Removed special-casing from hoppers in ItemAttributes. 4 | * Moved the lambda in "ItemFilter.asPredicate" out to it's own (public) class: "ItemFilterAsPredicate". 5 | * This lets the predicate and/or with itself into a (potentially) more optimised version. 6 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.14.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * [#14] Made InventoryFixedWrapper.inv and FixedInventoryViewVanillaWrapper.inv protected rather than package-private. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.15.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * [#13] Added a few methods to FixedItemInvView and FixedFluidInvView for iterating over their slots/tanks: 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.2.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Removed JumboFixedItemInv, as all of the optimisations that would have bee added to it will instead be added to SimpleFixedItemInv. 4 | 5 | Changes: 6 | 7 | * Updated to minecraft 1.14.1 Pre-Release 2 8 | * Added ItemInsertable.getPureInsertable(), which returns an object that *only* implements ItemInsertable 9 | * Added ItemExtractable.getPureExtractable(), which returns an object that *only* implements ItemInsertable 10 | * Added ItemEntityAttributeUtil.getSpecialExtractable(Entity) which can return an IntemExtractable from item entities. 11 | * Added ExactItemFilter, which is similar to an ExactItemStackFilter but only filters on Item's rather than the whole ItemStack. 12 | * Made SimpleFixed{Item/Fluid}Inv implement {Item/Fluid}Transferable. 13 | 14 | Bug Fixes: 15 | 16 | * Fixed voxel-bounded attribute searches not respecting the bounds of contained attributes. 17 | * Fixed the collections returned by ItemStackCollections sometimes not working properly. (And by sometimes I think it was "whenever you used them") 18 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.4.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed an issue with the buildscript which produced maven data for "items" and "fluids" that didn't depend on "core". 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.5.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Relicense from MIT to the Mozilla Public License Version 2.0 4 | * (Mostly to match BuildCraft's license, of which many parts of it were used in LBA). 5 | 6 | Bug Fixes: 7 | 8 | * Fixed SingleItemSlot.attemptExtraction using "maxAmount" for the slot rather than the stored slot index. 9 | * Fixed ItemInvUtil.insertSingle modifying the stack given to it, unlike *everything else* in LBA. 10 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.6.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed FluidVolumeUtil.extractSingle() not working correctly. 4 | * Fixed FluidVolumeUtil.interactWithTank modifying a creative player's inventory. 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.7.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed FluidVolumeUtil.move() crashing when no fluid could be inserted into the destination. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.8.txt: -------------------------------------------------------------------------------- 1 | Breaking changes: 2 | 3 | * Added a new requirement to FluidExtractable.attemptExtraction: 4 | * Now it should always be valid to simulate an extraction with any filter the first time, 5 | and then simulate or action the second time with an exact fluid filter with the fluid 6 | that was extracted the first time. (This is required for the bugfix below). 7 | 8 | * FluidKey now final-overrides equals and hashCode to perform identity equality. 9 | * This implies that every fluid must only have one fluid key, that must be cached 10 | somewhere at all times. 11 | 12 | Bug Fixes: 13 | 14 | * Fixed FluidVolumeUtil.move() crashing when the source or the destination had a minimum transfer amount. 15 | * Fixed ItemInvUtil.extractSingle() never merging an item with the item passed in. 16 | * Fixed fabric.mod.json using "requires" instead of "depends" for mod dependencies. 17 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.4.9.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added a new interface "Convertible", with a single method " T convertTo(Class clazz)" 4 | * AttributeList.offer() now uses this to attempt to convert the given object into the desired one. 5 | * This is primarily used to fix the bug below. 6 | * Deprecated FixedItemInvView.offerSelfAsAttribute and FixedFluidInvView.offerSelfAsAttribute because 7 | they now implement the convertible interface. 8 | 9 | Bug Fixes: 10 | 11 | * Fixed SimpleFixedItemInvView.offerSelfAsAttribute adding two instances of ItemTransferable 12 | rather than just one. 13 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.5.1.txt: -------------------------------------------------------------------------------- 1 | Additions: 2 | 3 | * Added misc.Saveable interface, which includes "toTag" and "fromTag" methods. 4 | * FullFixedItemInv, DirectFixedItemInv, and SimpleFixedFluidInv implement this. 5 | * Added saving methods to SimpleGroupedItemInv (how did I miss these ???) 6 | * Plus it now implements misc.Saveable 7 | * Added LimitedFixedItemInv.ItemSlotLimitRule.disallowInsertion() 8 | * And the fluid variant. 9 | * Added many variants of FluidVolumeUtil.interactWithTank that take FluidInsertable 10 | and FluidExtractable or FluidTransferable instead of just FixedFluidInv. 11 | 12 | Bug Fixes: 13 | 14 | * Fixed SimpleLimitedFixedItemInv exposing the delegate inventory, rather than itself. 15 | (so now the rules are correctly applied to insert/extract as well as setInvStack) 16 | * Fixed CombinedItemInsertable.getInsertionFilter incorrectly combining insertion filters 17 | using AND rather than OR. 18 | * Fixed CombinedItemInsertable pre-computing the insertion filter when there's no guarantee 19 | that the filters returned from the insertables will stay constant. 20 | * Fixed FluidInsertable.getInsertionFilter() inserting Integer.MAX_VALUE of 21 | the fluid, which caused a few crashes when it was added to and overflowed. 22 | * Fixed ImplicitFluidVolumeRenderer not using fabric api's FluidRenderHandlerRegistry 23 | to get the sprite. (Now it falls back to the block model rather than relying on it). 24 | * Fixed FluidVolumeRenderer.renderGuiRectangle rendering at z=30, rather than z=0. 25 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.6.3.txt: -------------------------------------------------------------------------------- 1 | Bug Fixes: 2 | 3 | * Fixed FluidVolume.equals still comparing the amount field with == rather than equals. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.6.6.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Allowed LBA to be loaded in 20w06a. 4 | 5 | Bug Fixes: 6 | 7 | * Fixed RebornCore fluid compat not working. 8 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.7.0.txt: -------------------------------------------------------------------------------- 1 | Breaking Changes: 2 | 3 | * Added a "boolean server" parameter to SlotFixedItemInv's constructor. 4 | * (This was needed to fix #11) 5 | 6 | Changes: 7 | 8 | * Updated LBA to 1.16-pre.4. 9 | * Allowed this version of LBA to be loaded in any version of 1.16 after 1.16-pre.4. 10 | * Added fluid properties. 11 | * See alexiil.mc.lib.attributes.fluid.volume.FluidProperty for details. 12 | * Added much better support for fluid tooltips - see FluidVolume and FluidKey 13 | for the new add/get*Tooltip methods. 14 | * This also adds configs, for tweaking how the resultant tooltips display. 15 | * For code-based control you can create a custom "FluidTooltipContext" object. 16 | * Added much more control when registering custom adders for blocks and items 17 | * See the new javadoc for Attribute for more details. 18 | * Added compatibility with emi's item inventory API. 19 | 20 | Bug Fixes: 21 | 22 | * Fixed X fluid faces using swapped UV co-ordinates. 23 | * [#11] SlotFixedItemInv doesn't work properly. 24 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.2.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added FluidContainerRegistry, which can be used to easily allow custom buckets to be filled with a custom fluid from an empty bucket, without needing complex stuff. 4 | * This is intended to replace IBucketItem, which is now deprecated. 5 | * Added "FluidKeyCustomiser", for custom Fluid instances to implement to customise the implicit FluidKey that gets created for them. 6 | * Added FluidKey.luminosity, to allow tanks to emit light based on the fluid's light. (Lava uses 15). 7 | * Gave the empty fluid a proper name. 8 | * Added a new field to FluidKey: exactFilter, which is an ExactFluidFilter of that fluid key. 9 | * Optimised AttributeList.addAll when searching the entire block in a specific direction. 10 | * Added fluid compat for cauldrons. (However you can only insert or extract 1/3 of a bucket at a time, so it's not always possible to insert into them with pipes). 11 | 12 | Bug Fixes: 13 | 14 | * Fixed FluidKeys static init loading worldgen early. 15 | * Fixed various tooltip issues with FluidUnits. 16 | * Fixed FluidAmount.toLong() rounding incorrectly. 17 | * Fixed ItemInvUtil.move reusing the insertion filter after modifying the inventory. 18 | * Fixed FluidVolume.equals not considering two empty fluids of different classes to be equal. 19 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.4.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added FluidTypeFilter, for checking if a fluid is a raw (minecraft) fluid, a floating fluid, or of a particular registry. 4 | * Added FluidWorldUtil.createFluidDrainer and FluidWorldUtil.createFluidPlacer, which return a FluidExtractable and FluidInsertable that operate on the world directly. 5 | * Added a few additional variants of FluidVolumeUtil.move that take a Simulation parameter. 6 | * Undeprecate IBucketItem and make FluidContainerRegistry use it. 7 | * Remove Grouped{Fluid/Item}InvFixedWrapper.getInsertionFilter() as it wasn't correct. 8 | (It returned all of the filters for every slot OR'd together, but ItemInsertable.getInsertionFilter() is meant to filter only item stacks where attemptInsertion would succeed). 9 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.5.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Made FluidVolume.getRenderColor default to using fabric's FluidRenderHandler if we're on the client and the caller hasn't explicitly set it. 4 | * Made SingleItemSlotView and SingleFluidTankView throw an exception if you pass an out-of-bounds slot. 5 | 6 | Bug Fixes: 7 | 8 | * Made FluidVolume.getRenderColor default to using fabric's FluidRenderHandler if we're on the client and the caller hasn't explicitly set it. 9 | * Fixed usage of Registry.containsId on the server (which is a client-only method) 10 | * [#34] Fixed the dropper mixin crashing when there's no non-empty slots to drop from. 11 | * [#39] Fixed Dank Storage inventories not being inserted to properly. 12 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.6.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Partially reverted the 0.8.5 change which made SingleItemSlotView and SingleFluidTankView throw an exception if you pass an out-of-bounds slot. 4 | * Instead they only throw an exception on negative slot indices. 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.7.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added "lba.misc.OpenWrapper", which is meant to be the opposite of Convertible. 4 | * This is used in cases where an object really is a "simple wrapper" from one type to another 5 | * This has a single method: "Object getWrapped()". 6 | * Note that this may return null if an implementation can't expose the inner object without also exposing more details than they wish. 7 | * All of LBA's base wrapper implementations implement this: 8 | * GroupedItemInvViewFixedWrapper (returned by FixedItemInvView.getGroupedInv()) 9 | * GroupedFluidInvViewFixedWrapper (returned by FixedFluidInvView.getGroupedInv()) 10 | * FixedInventoryViewVanillaWrapper (turns a vanilla Inventory into an LBA FixedItemInvView) 11 | * InventoryFixedWrapper (turns an LBA FixedItemInv into a vanilla Inventory) 12 | * None of LBA's mod-compat implementations implement this. 13 | * Added "lba.misc.Combined", which is meant to be the opposite of AttributeCombiner. 14 | * This is used in cases where an object is a "simpler combiner" of a list of objects (of the same type) 15 | * This has two methods: 16 | * "int getSubObjectCount()": Returns the number of objects that this combines. 17 | * "Object getSubObject(int index)": Returns the sub-object at that particular index. 18 | * Unlike "OpenWrapper" this must not return null, unless the index is invalid. 19 | * However getSubObjectCount() may return 0, or -1 if the sub-objects cannot be exposed normally. 20 | * There's also a new abstract class to make implementing these simpler: "lba.misc.AbstractCombined". 21 | * All of LBA's base combined implementations implement this. 22 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.8.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added debug logging to CompatLeveledMap to aid in debugging fluid attribute replacement. 4 | * This can be enabled by adding the following debug flag to your vm arguments: 5 | * "-Dlibblockattributes.debug.record_attribute_additions=true" 6 | 7 | Bug Fixes: 8 | 9 | * [#41] Warnings about fluid attributes for "glass_bottle" being replaced when it shouldn't be. 10 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.8.9.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Added FluidAmount json serialisation. 4 | * [#44] Removed Universal Components compatibility workaround. As such LBA is now incompatible with UC. 5 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.9.0.txt: -------------------------------------------------------------------------------- 1 | Changes: 2 | 3 | * Ported to 1.17. 4 | * Cauldron compat isn't finished yet, so it's been disabled (for now). 5 | * Added "since" and "forRemoval" attributes to Deprecated annotations. 6 | * Added FluidAmount.splitBalanced. 7 | * Moved the LBA helper interface "UnloadableBlockEntity" to LBA. 8 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.9.1.txt: -------------------------------------------------------------------------------- 1 | Bug fixes: 2 | 3 | * Fixed the fluid config file not being created automatically if it's missing. 4 | -------------------------------------------------------------------------------- /src/main/resources/changelog/0.9.2.txt: -------------------------------------------------------------------------------- 1 | Bug fixes: 2 | 3 | * Fixed the fluid config file being created directly in the game directory rather than in the config directory. 4 | -------------------------------------------------------------------------------- /src/main/resources/libblockattributes_core.client.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "alexiil.mc.lib.attributes.mixin.impl.mx", 4 | "compatibilityLevel": "JAVA_8", 5 | "client": [ 6 | "ClientWorldMixin" 7 | ], 8 | "injectors": { 9 | "defaultRequire": 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/libblockattributes_core.common.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "alexiil.mc.lib.attributes.mixin.impl.mx", 4 | "compatibilityLevel": "JAVA_8", 5 | "mixins": [ 6 | "ServerWorldMixin" 7 | ], 8 | "injectors": { 9 | "defaultRequire": 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/libblockattributes_fluid.client.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "alexiil.mc.lib.attributes.fluid.mixin.impl", 4 | "compatibilityLevel": "JAVA_8", 5 | "client": [ 6 | "RenderLayerAccessor" 7 | ], 8 | "injectors": { 9 | "defaultRequire": 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/libblockattributes_fluid.common.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "alexiil.mc.lib.attributes.fluid.mixin.impl", 4 | "compatibilityLevel": "JAVA_8", 5 | "mixins": [ 6 | "FlowableFluidAccessor", 7 | "BiomeEffectsAccessor", 8 | "BucketItemMixin", 9 | "GlassBottleItemMixin", 10 | "PotionItemMixin", 11 | "FluidBlockMixin" 12 | ], 13 | "injectors": { 14 | "defaultRequire": 1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/libblockattributes_item.common.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "alexiil.mc.lib.attributes.item.mixin.impl", 4 | "compatibilityLevel": "JAVA_8", 5 | "mixins": [ 6 | "HopperBlockEntityMixin", 7 | "DropperBlockMixin" 8 | ], 9 | "injectors": { 10 | "defaultRequire": 1 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/alexiil/mc/lib/attributes/Tester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes; 9 | 10 | import net.fabricmc.api.ModInitializer; 11 | 12 | import alexiil.mc.lib.attributes.item.impl.DirectFixedItemInvTester; 13 | 14 | public class Tester implements ModInitializer { 15 | @Override 16 | public void onInitialize() { 17 | DirectFixedItemInvTester.runTests(); 18 | 19 | // TODO: Write tests for SimpleLimitedFixedItemInv and SimpleGroupedItemInv! 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/alexiil/mc/lib/attributes/fluid/item/FluidContainerTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.item; 9 | 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | import net.minecraft.item.ItemStack; 14 | import net.minecraft.item.Items; 15 | import net.minecraft.potion.Potions; 16 | 17 | import alexiil.mc.lib.attributes.VanillaSetupBaseTester; 18 | import alexiil.mc.lib.attributes.fluid.FluidAttributes; 19 | import alexiil.mc.lib.attributes.fluid.FluidVolumeUtil; 20 | import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; 21 | import alexiil.mc.lib.attributes.fluid.volume.FluidKeys; 22 | import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; 23 | import alexiil.mc.lib.attributes.misc.Ref; 24 | 25 | public class FluidContainerTester extends VanillaSetupBaseTester { 26 | 27 | @Test 28 | public void testFilling() { 29 | Ref ref = new Ref<>(new ItemStack(Items.GLASS_BOTTLE)); 30 | FluidVolume toInsert = FluidKeys.get(Potions.HEALING).withAmount(FluidAmount.BOTTLE); 31 | FluidVolume excess = FluidAttributes.INSERTABLE.get(ref).insert(toInsert); 32 | Assert.assertEquals(FluidVolumeUtil.EMPTY, excess); 33 | Assert.assertEquals(Items.POTION, ref.get().getItem()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/alexiil/mc/lib/attributes/fluid/render/FluidFaceSplitterTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.fluid.render; 9 | 10 | import java.util.Collections; 11 | 12 | import org.junit.Test; 13 | 14 | public class FluidFaceSplitterTester { 15 | 16 | @Test 17 | public void printFace() { 18 | double l = 0.25; 19 | double h = 0.75; 20 | FluidRenderFace face = FluidRenderFace.createFlatFaceZ(l, l, 0, h, h, 0, 1, true); 21 | System.out.println(face); 22 | 23 | System.out.println("SPLIT:"); 24 | 25 | for (FluidRenderFace f : FluidFaceSplitter.splitFaces(Collections.singletonList(face))) { 26 | System.out.println(f); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/alexiil/mc/lib/attributes/item/impl/DirectFixedItemInvTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | public class DirectFixedItemInvTester { 11 | 12 | public static void runTests() { 13 | testBasics(); 14 | } 15 | 16 | private static void testBasics() { 17 | DirectFixedItemInv inv = new DirectFixedItemInv(10); 18 | // TODO: Think of and write tests! 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/alexiil/mc/lib/attributes/item/impl/SimpleLimitedGroupedItemInvTester.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 AlexIIL 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. 7 | */ 8 | package alexiil.mc.lib.attributes.item.impl; 9 | 10 | import org.junit.Test; 11 | 12 | import net.minecraft.item.ItemStack; 13 | 14 | import alexiil.mc.lib.attributes.item.GroupedItemInv; 15 | import alexiil.mc.lib.attributes.item.LimitedGroupedItemInv; 16 | 17 | public class SimpleLimitedGroupedItemInvTester extends ItemInvTester { 18 | 19 | @Test 20 | public void testBasicLimits() { 21 | FullFixedItemInv inv = new FullFixedItemInv(10); 22 | fillInventory(inv, ITEMS, 0); 23 | GroupedItemInv grouped = inv.getGroupedInv(); 24 | LimitedGroupedItemInv limited = grouped.createLimitedGroupedInv(); 25 | 26 | limited.getRule(new ItemStack(ITEMS[0])).disallowTransfer(); 27 | 28 | assertEquals(ItemStack.EMPTY, limited.extract(new ItemStack(ITEMS[0]), 1)); 29 | assertEquals(new ItemStack(ITEMS[0]), grouped.extract(new ItemStack(ITEMS[0]), 1)); 30 | 31 | limited.getRule(stack -> stack.getItem() != ITEMS[2]).disallowTransfer(); 32 | 33 | assertEquals(ItemStack.EMPTY, limited.extract(new ItemStack(ITEMS[1]), 1)); 34 | assertEquals(new ItemStack(ITEMS[1]), grouped.extract(new ItemStack(ITEMS[1]), 1)); 35 | 36 | assertEquals(new ItemStack(ITEMS[2]), limited.extract(new ItemStack(ITEMS[2]), 1)); 37 | assertEquals(ItemStack.EMPTY, grouped.extract(new ItemStack(ITEMS[2]), 1)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "libblockattributes_tests", 4 | "name": "LibBlockAttributes Tests", 5 | "description": "Various unit(ish) tests for LibBlockAttributes", 6 | "version": "$version", 7 | "environment": "*", 8 | "entrypoints": { 9 | "main": [ 10 | "alexiil.mc.lib.attributes.Tester" 11 | ] 12 | }, 13 | "requires": { 14 | "fabricloader": ">=0.4.0", 15 | "fabric": "*", 16 | "libblockattributes": "*" 17 | }, 18 | "mixins": [], 19 | "icon": "assets/libblockattributes/icon.png", 20 | "authors": [ "AlexIIL" ] 21 | } 22 | --------------------------------------------------------------------------------