diff --git a/build.gradle b/build.gradle index 63f2b50..70c6f72 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,8 @@ repositories { maven { url "https://server.bbkr.space/artifactory/libs-release" } // Cotton maven - home of Cotton projects maven { url "https://dl.bintray.com/ladysnake/libs" } // Onyx Studios maven - home of Cardinal Components maven { url "https://alexiil.uk/maven/" } // Alexiil's maven - home of Lib Block Attributes - maven { url "https://maven.dblsaiko.net/" } //Grondag's maven - home of Fluidity - maven { url "https://jitpack.io" } + maven { url "https://maven.dblsaiko.net/" } // Grondag's maven - home of Fluidity + maven { url "https://jitpack.io" } // Emily Rose Ploszaj's maven - home of Item Inventory } dependencies { diff --git a/gradle.properties b/gradle.properties index 45d3f0d..a320b19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx3G +org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.16.4 -yarn_build=7 -loader_version=0.10.8 +minecraft_version = 1.16.5 +yarn_build = 10 +loader_version = 0.11.7 # Mod Properties mod_version = 0.8.0 @@ -14,9 +14,9 @@ archives_base_name = universalcomponents # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api -fabric_version=0.29.0+1.16 -cardinal_version=2.7.10 -lba_version=0.8.5 -fluidity_version=0.16 -item_inventory_version=1.1.0 -tr_energy_version=0.1.1 +fabric_version = 0.40.1+1.16 +cardinal_version = 2.8.3 +lba_version = 0.8.8 +fluidity_version = 0.16 +item_inventory_version = 1.1.0 +tr_energy_version = 0.1.1 diff --git a/src/main/java/io/github/cottonmc/component/compat/iteminv/WrappedItemInventory.java b/src/main/java/io/github/cottonmc/component/compat/iteminv/WrappedItemInventory.java index 7b8fd0d..fc35340 100644 --- a/src/main/java/io/github/cottonmc/component/compat/iteminv/WrappedItemInventory.java +++ b/src/main/java/io/github/cottonmc/component/compat/iteminv/WrappedItemInventory.java @@ -21,7 +21,7 @@ public WrappedItemInventory(ItemStack stack, ItemInventory inventory) { } @Override - public int getSize() { + public int size() { return inv.getInvSize(holderStack); } @@ -55,7 +55,7 @@ public boolean canExtract(int slot) { } @Override - public ItemStack takeStack(int slot, int amount, ActionType action) { + public ItemStack removeStack(int slot, int amount, ActionType action) { ItemStack original = inv.getStack(holderStack, slot).copy(); ItemStack ret = inv.getStack(holderStack, slot).split(amount); if (!action.shouldPerform()) { diff --git a/src/main/java/io/github/cottonmc/component/compat/lba/AttributeWrapper.java b/src/main/java/io/github/cottonmc/component/compat/lba/AttributeWrapper.java index 744e538..83bed4a 100644 --- a/src/main/java/io/github/cottonmc/component/compat/lba/AttributeWrapper.java +++ b/src/main/java/io/github/cottonmc/component/compat/lba/AttributeWrapper.java @@ -30,7 +30,7 @@ public ItemExtractable getExtractable() { @Override public int getSlotCount() { - return component.getSize(); + return component.size(); } @Override @@ -62,7 +62,7 @@ public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalT @Override public ItemStack attemptExtraction(ItemFilter filter, int maxAmount, Simulation simulation) { - return component.takeStack(0, maxAmount, actionForSim(simulation)); //TODO: fix + return component.removeStack(0, maxAmount, actionForSim(simulation)); //TODO: fix } @Override diff --git a/src/main/java/io/github/cottonmc/component/compat/lba/WrappedInvAttributeComponent.java b/src/main/java/io/github/cottonmc/component/compat/lba/WrappedInvAttributeComponent.java index a739e77..3bc43ee 100644 --- a/src/main/java/io/github/cottonmc/component/compat/lba/WrappedInvAttributeComponent.java +++ b/src/main/java/io/github/cottonmc/component/compat/lba/WrappedInvAttributeComponent.java @@ -31,7 +31,7 @@ public WrappedInvAttributeComponent(FixedItemInv inv) { } @Override - public int getSize() { + public int size() { return view.getSlotCount(); } @@ -72,7 +72,7 @@ public boolean canExtract(int slot) { } @Override - public ItemStack takeStack(int slot, int amount, ActionType action) { + public ItemStack removeStack(int slot, int amount, ActionType action) { return extractable.attemptExtraction(createFilterForSlot(slot), amount, simForAction(action)); } diff --git a/src/main/java/io/github/cottonmc/component/compat/tr/WrappedEnergyHandler.java b/src/main/java/io/github/cottonmc/component/compat/tr/WrappedEnergyHandler.java index 1bdad08..7d32f7c 100644 --- a/src/main/java/io/github/cottonmc/component/compat/tr/WrappedEnergyHandler.java +++ b/src/main/java/io/github/cottonmc/component/compat/tr/WrappedEnergyHandler.java @@ -3,7 +3,7 @@ import io.github.cottonmc.component.api.ActionType; import io.github.cottonmc.component.energy.CapacitorComponent; import io.github.cottonmc.component.energy.type.EnergyType; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.util.math.Direction; import team.reborn.energy.EnergyHandler; @@ -79,11 +79,11 @@ public List getListeners() { } @Override - public void readFromNbt(CompoundTag tag) { + public void readFromNbt(NbtCompound tag) { } @Override - public void writeToNbt(CompoundTag tag) { + public void writeToNbt(NbtCompound tag) { } } diff --git a/src/main/java/io/github/cottonmc/component/compat/vanilla/SidedInventoryWrapper.java b/src/main/java/io/github/cottonmc/component/compat/vanilla/SidedInventoryWrapper.java index 0704f14..dfcbb2b 100644 --- a/src/main/java/io/github/cottonmc/component/compat/vanilla/SidedInventoryWrapper.java +++ b/src/main/java/io/github/cottonmc/component/compat/vanilla/SidedInventoryWrapper.java @@ -35,7 +35,7 @@ static SidedInventoryWrapper of(Function func) { default int[] getAvailableSlots(Direction side) { InventoryComponent component = getComponent(side); if (component == null) return new int[0]; - return IntStream.range(0, component.getSize()).filter(slot -> component.canInsert(slot) || component.canExtract(slot)).toArray(); + return IntStream.range(0, component.size()).filter(slot -> component.canInsert(slot) || component.canExtract(slot)).toArray(); } @Override diff --git a/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedInvComponent.java b/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedInvComponent.java index 7f54ac9..7d3b8fc 100644 --- a/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedInvComponent.java +++ b/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedInvComponent.java @@ -18,7 +18,7 @@ public WrappedInvComponent(Inventory inv) { } @Override - public int getSize() { + public int size() { return inv.size(); } @@ -52,7 +52,7 @@ public boolean canExtract(int slot) { } @Override - public ItemStack takeStack(int slot, int amount, ActionType action) { + public ItemStack removeStack(int slot, int amount, ActionType action) { ItemStack original = inv.getStack(slot).copy(); ItemStack ret = inv.removeStack(slot, amount); if (!action.shouldPerform()) { diff --git a/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedSidedInvComponent.java b/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedSidedInvComponent.java index 5fe3d9f..605d733 100644 --- a/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedSidedInvComponent.java +++ b/src/main/java/io/github/cottonmc/component/compat/vanilla/WrappedSidedInvComponent.java @@ -23,7 +23,7 @@ public WrappedSidedInvComponent(SidedInventory inv, Direction side) { } @Override - public int getSize() { + public int size() { return inv.size(); } @@ -64,7 +64,7 @@ public boolean canExtract(int slot) { } @Override - public ItemStack takeStack(int slot, int amount, ActionType action) { + public ItemStack removeStack(int slot, int amount, ActionType action) { ItemStack original = inv.getStack(slot).copy(); ItemStack ret = inv.removeStack(slot, amount); if (!action.shouldPerform()) { diff --git a/src/main/java/io/github/cottonmc/component/data/DataProviderComponent.java b/src/main/java/io/github/cottonmc/component/data/DataProviderComponent.java index 6764495..42de66a 100644 --- a/src/main/java/io/github/cottonmc/component/data/DataProviderComponent.java +++ b/src/main/java/io/github/cottonmc/component/data/DataProviderComponent.java @@ -3,7 +3,7 @@ import io.github.cottonmc.component.data.api.DataElement; import io.github.cottonmc.component.data.api.Unit; import dev.onyxstudios.cca.api.v3.component.Component; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import javax.annotation.Nullable; import java.util.List; @@ -35,8 +35,8 @@ public interface DataProviderComponent extends Component { DataElement getElementFor(Unit unit); @Override - default void readFromNbt(CompoundTag tag) { } + default void readFromNbt(NbtCompound tag) { } @Override - default void writeToNbt(CompoundTag tag) { } + default void writeToNbt(NbtCompound tag) { } } diff --git a/src/main/java/io/github/cottonmc/component/energy/impl/ItemCapacitorComponent.java b/src/main/java/io/github/cottonmc/component/energy/impl/ItemCapacitorComponent.java index 4022240..895affd 100644 --- a/src/main/java/io/github/cottonmc/component/energy/impl/ItemCapacitorComponent.java +++ b/src/main/java/io/github/cottonmc/component/energy/impl/ItemCapacitorComponent.java @@ -1,13 +1,12 @@ package io.github.cottonmc.component.energy.impl; -import dev.onyxstudios.cca.api.v3.component.Component; import dev.onyxstudios.cca.api.v3.component.ComponentKey; import io.github.cottonmc.component.UniversalComponents; import io.github.cottonmc.component.energy.CapacitorComponent; import io.github.cottonmc.component.energy.type.EnergyType; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; -public class ItemCapacitorComponent extends SimpleCapacitorComponent implements Component { +public class ItemCapacitorComponent extends SimpleCapacitorComponent { private ComponentKey key; public ItemCapacitorComponent(int maxEnergy, EnergyType type) { @@ -24,8 +23,8 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ItemCapacitorComponent that = (ItemCapacitorComponent) o; - CompoundTag tag = new CompoundTag(); - CompoundTag tag1 = new CompoundTag(); + NbtCompound tag = new NbtCompound(); + NbtCompound tag1 = new NbtCompound(); that.writeToNbt(tag); this.writeToNbt(tag1); return tag1.equals(tag1); diff --git a/src/main/java/io/github/cottonmc/component/energy/impl/SimpleCapacitorComponent.java b/src/main/java/io/github/cottonmc/component/energy/impl/SimpleCapacitorComponent.java index 3a36b2f..912e6f1 100644 --- a/src/main/java/io/github/cottonmc/component/energy/impl/SimpleCapacitorComponent.java +++ b/src/main/java/io/github/cottonmc/component/energy/impl/SimpleCapacitorComponent.java @@ -4,7 +4,7 @@ import io.github.cottonmc.component.energy.CapacitorComponent; import io.github.cottonmc.component.energy.type.EnergyType; import net.fabricmc.fabric.api.util.NbtType; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -124,7 +124,7 @@ public List getListeners() { } @Override - public void readFromNbt(CompoundTag tag) { + public void readFromNbt(NbtCompound tag) { currentEnergy = tag.getInt("Energy"); maxEnergy = tag.getInt("MaxEnergy"); if (tag.contains("Harm", NbtType.NUMBER)) { @@ -133,7 +133,7 @@ public void readFromNbt(CompoundTag tag) { } @Override - public void writeToNbt(CompoundTag tag) { + public void writeToNbt(NbtCompound tag) { tag.putInt("Energy", currentEnergy); tag.putInt("MaxEnergy", maxEnergy); tag.putInt("Harm", harm); diff --git a/src/main/java/io/github/cottonmc/component/fluid/TankComponent.java b/src/main/java/io/github/cottonmc/component/fluid/TankComponent.java index 0a6f935..c4f4e1a 100644 --- a/src/main/java/io/github/cottonmc/component/fluid/TankComponent.java +++ b/src/main/java/io/github/cottonmc/component/fluid/TankComponent.java @@ -7,8 +7,8 @@ import dev.onyxstudios.cca.api.v3.component.Component; import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.fluid.Fluid; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtList; import java.util.Collections; import java.util.List; @@ -39,7 +39,7 @@ default boolean isEmpty() { boolean canExtract(int tank); - FluidVolume takeFluid(int tank, Fraction amount, ActionType action); + FluidVolume removeFluid(int tank, Fraction amount, ActionType action); FluidVolume removeFluid(int tank, ActionType action); @@ -87,20 +87,20 @@ default boolean contains(Set fluids) { } @Override - default void readFromNbt(CompoundTag tag) { + default void readFromNbt(NbtCompound tag) { clear(); - ListTag contents = tag.getList("Contents", NbtType.COMPOUND); + NbtList contents = tag.getList("Contents", NbtType.COMPOUND); for (int i = 0; i < contents.size(); i++) { - CompoundTag volTag = (CompoundTag)contents.get(i); - setFluid(i, FluidVolume.fromTag(volTag)); + NbtCompound volTag = (NbtCompound)contents.get(i); + setFluid(i, FluidVolume.fromNbt(volTag)); } } @Override - default void writeToNbt(CompoundTag tag) { - ListTag contents = new ListTag(); + default void writeToNbt(NbtCompound tag) { + NbtList contents = new NbtList(); for (FluidVolume vol : getAllContents()) { - contents.add(vol.toTag(new CompoundTag())); + contents.add(vol.toNbt(new NbtCompound())); } tag.put("Contents", contents); } diff --git a/src/main/java/io/github/cottonmc/component/fluid/impl/ItemTankComponent.java b/src/main/java/io/github/cottonmc/component/fluid/impl/ItemTankComponent.java index 723614d..b72e476 100644 --- a/src/main/java/io/github/cottonmc/component/fluid/impl/ItemTankComponent.java +++ b/src/main/java/io/github/cottonmc/component/fluid/impl/ItemTankComponent.java @@ -4,7 +4,7 @@ import io.github.cottonmc.component.UniversalComponents; import io.github.cottonmc.component.fluid.TankComponent; import io.github.fablabsmc.fablabs.api.fluidvolume.v1.Fraction; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; public class ItemTankComponent extends SimpleTankComponent { private ComponentKey type; @@ -23,8 +23,8 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ItemTankComponent that = (ItemTankComponent) o; - CompoundTag tag = new CompoundTag(); - CompoundTag tag1 = new CompoundTag(); + NbtCompound tag = new NbtCompound(); + NbtCompound tag1 = new NbtCompound(); that.writeToNbt(tag); this.writeToNbt(tag1); return tag1.equals(tag1); diff --git a/src/main/java/io/github/cottonmc/component/fluid/impl/SimpleTankComponent.java b/src/main/java/io/github/cottonmc/component/fluid/impl/SimpleTankComponent.java index c697a9d..8684677 100644 --- a/src/main/java/io/github/cottonmc/component/fluid/impl/SimpleTankComponent.java +++ b/src/main/java/io/github/cottonmc/component/fluid/impl/SimpleTankComponent.java @@ -53,7 +53,7 @@ public boolean canExtract(int slot) { } @Override - public FluidVolume takeFluid(int slot, Fraction amount, ActionType action) { + public FluidVolume removeFluid(int slot, Fraction amount, ActionType action) { FluidVolume vol = contents.get(slot); if (!action.shouldPerform()) { vol = vol.copy(); diff --git a/src/main/java/io/github/cottonmc/component/item/InventoryComponent.java b/src/main/java/io/github/cottonmc/component/item/InventoryComponent.java index f659583..69cfa92 100644 --- a/src/main/java/io/github/cottonmc/component/item/InventoryComponent.java +++ b/src/main/java/io/github/cottonmc/component/item/InventoryComponent.java @@ -11,8 +11,8 @@ import net.minecraft.inventory.SidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtList; import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldAccess; @@ -26,7 +26,7 @@ public interface InventoryComponent extends Component, Observable { /** * @return How many slots are in this inventory. */ - int getSize(); + int size(); /** * @return Whether this inventory is empty or not. @@ -75,7 +75,7 @@ default boolean isEmpty() { * @param action The type of action to perform. * @return The stack that was successfully removed. */ - ItemStack takeStack(int slot, int amount, ActionType action); + ItemStack removeStack(int slot, int amount, ActionType action); /** * Remove an entire item stack. @@ -113,7 +113,7 @@ default boolean isEmpty() { * Empty this inventory, removing all stacks. */ default void clear() { - for (int i = 0; i < getSize(); i++) { + for (int i = 0; i < size(); i++) { removeStack(i, ActionType.PERFORM); } } @@ -200,20 +200,20 @@ default SidedInventory asLocalInventory(WorldAccess world, BlockPos pos) { } @Override - default void readFromNbt(CompoundTag tag) { + default void readFromNbt(NbtCompound tag) { clear(); - ListTag items = tag.getList("Items", NbtType.COMPOUND); + NbtList items = tag.getList("Items", NbtType.COMPOUND); for (int i = 0; i < items.size(); i++) { - CompoundTag stackTag = (CompoundTag) items.get(i); + NbtCompound stackTag = (NbtCompound) items.get(i); setStack(i, StackSerializer.fromTag(stackTag)); } } @Override - default void writeToNbt(CompoundTag tag) { - ListTag items = new ListTag(); + default void writeToNbt(NbtCompound tag) { + NbtList items = new NbtList(); for (ItemStack stack : getStacks()) { - items.add(StackSerializer.toTag(stack, new CompoundTag())); + items.add(StackSerializer.toTag(stack, new NbtCompound())); } tag.put("Items", items); } diff --git a/src/main/java/io/github/cottonmc/component/item/impl/ItemInventoryComponent.java b/src/main/java/io/github/cottonmc/component/item/impl/ItemInventoryComponent.java index c1f5ab6..1b23434 100644 --- a/src/main/java/io/github/cottonmc/component/item/impl/ItemInventoryComponent.java +++ b/src/main/java/io/github/cottonmc/component/item/impl/ItemInventoryComponent.java @@ -3,7 +3,7 @@ import dev.onyxstudios.cca.api.v3.component.ComponentKey; import io.github.cottonmc.component.UniversalComponents; import io.github.cottonmc.component.item.InventoryComponent; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import java.util.Objects; @@ -27,8 +27,8 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ItemInventoryComponent that = (ItemInventoryComponent) o; - CompoundTag tag = new CompoundTag(); - CompoundTag tag1 = new CompoundTag(); //TODO: better way to do this? + NbtCompound tag = new NbtCompound(); + NbtCompound tag1 = new NbtCompound(); //TODO: better way to do this? that.writeToNbt(tag); this.writeToNbt(tag1); return tag1.equals(tag1); diff --git a/src/main/java/io/github/cottonmc/component/item/impl/SimpleInventoryComponent.java b/src/main/java/io/github/cottonmc/component/item/impl/SimpleInventoryComponent.java index 338f6fc..79a0cf2 100644 --- a/src/main/java/io/github/cottonmc/component/item/impl/SimpleInventoryComponent.java +++ b/src/main/java/io/github/cottonmc/component/item/impl/SimpleInventoryComponent.java @@ -19,7 +19,7 @@ public SimpleInventoryComponent(int size) { } @Override - public int getSize() { + public int size() { return stacks.size(); } @@ -53,7 +53,7 @@ public boolean canExtract(int slot) { } @Override - public ItemStack takeStack(int slot, int amount, ActionType action) { + public ItemStack removeStack(int slot, int amount, ActionType action) { ItemStack stack = stacks.get(slot); if (!action.shouldPerform()) { stack = stack.copy(); diff --git a/src/main/java/io/github/cottonmc/component/serializer/StackSerializer.java b/src/main/java/io/github/cottonmc/component/serializer/StackSerializer.java index f8932aa..04f3720 100644 --- a/src/main/java/io/github/cottonmc/component/serializer/StackSerializer.java +++ b/src/main/java/io/github/cottonmc/component/serializer/StackSerializer.java @@ -2,13 +2,13 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; public class StackSerializer { //allows int amounts - public static CompoundTag toTag(ItemStack stack, CompoundTag tag) { + public static NbtCompound toTag(ItemStack stack, NbtCompound tag) { Identifier identifier = Registry.ITEM.getId(stack.getItem()); tag.putString("id", identifier == null ? "minecraft:air" : identifier.toString()); tag.putInt("Count", stack.getCount()); @@ -20,7 +20,7 @@ public static CompoundTag toTag(ItemStack stack, CompoundTag tag) { } //allows int amounts - public static ItemStack fromTag(CompoundTag tag) { + public static ItemStack fromTag(NbtCompound tag) { Item item = Registry.ITEM.get(new Identifier(tag.getString("id"))); int count = tag.getInt("Count"); ItemStack ret = new ItemStack(item, count); diff --git a/src/main/java/io/github/fablabsmc/fablabs/api/fluidvolume/v1/FluidVolume.java b/src/main/java/io/github/fablabsmc/fablabs/api/fluidvolume/v1/FluidVolume.java index 29b5916..4ec43a4 100644 --- a/src/main/java/io/github/fablabsmc/fablabs/api/fluidvolume/v1/FluidVolume.java +++ b/src/main/java/io/github/fablabsmc/fablabs/api/fluidvolume/v1/FluidVolume.java @@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.util.NbtType; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtOps; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; @@ -17,7 +17,7 @@ public final class FluidVolume { private Fluid fluid; private Fraction amount; - private CompoundTag tag; + private NbtCompound nbt; private boolean empty; @@ -31,12 +31,12 @@ public FluidVolume(Fluid fluid, Fraction amount) { this.updateEmptyState(); } - private FluidVolume(CompoundTag tag) { - fluid = Registry.FLUID.get(new Identifier(tag.getString("Id"))); - amount = Fraction.CODEC.parse(NbtOps.INSTANCE, tag.getCompound("Amount")).resultOrPartial(UniversalComponents.logger::error).orElse(Fraction.ZERO); + private FluidVolume(NbtCompound nbt) { + fluid = Registry.FLUID.get(new Identifier(nbt.getString("Id"))); + amount = Fraction.CODEC.parse(NbtOps.INSTANCE, nbt.getCompound("Amount")).resultOrPartial(UniversalComponents.logger::error).orElse(Fraction.ZERO); - if (tag.contains("Tag", NbtType.COMPOUND)) { - this.tag = tag.getCompound("Tag"); + if (nbt.contains("Nbt", NbtType.COMPOUND)) { + this.nbt = nbt.getCompound("Nbt"); } this.updateEmptyState(); @@ -95,46 +95,46 @@ private void updateEmptyState() { empty = isEmpty(); } - public boolean hasTag() { - return !empty && tag != null && !tag.isEmpty(); + public boolean hasNbt() { + return !empty && nbt != null && !nbt.isEmpty(); } - public CompoundTag getTag() { - return tag; + public NbtCompound getNbt() { + return nbt; } - public CompoundTag getOrCreateTag() { - if (tag == null) { - tag = new CompoundTag(); + public NbtCompound getOrCreateNbt() { + if (nbt == null) { + nbt = new NbtCompound(); } - return tag; + return nbt; } - public void setTag(CompoundTag tag) { - this.tag = tag; + public void setNbt(NbtCompound nbt) { + this.nbt = nbt; } public FluidVolume copy() { if (this.isEmpty()) return FluidVolume.EMPTY; FluidVolume stack = new FluidVolume(this.fluid, this.amount); - if (this.hasTag()) stack.setTag(this.getTag()); + if (this.hasNbt()) stack.setNbt(this.getNbt()); return stack; } - public static FluidVolume fromTag(CompoundTag tag) { - return new FluidVolume(tag); + public static FluidVolume fromNbt(NbtCompound nbt) { + return new FluidVolume(nbt); } - public CompoundTag toTag(CompoundTag tag) { - tag.putString("Id", Registry.FLUID.getId(getFluid()).toString()); + public NbtCompound toNbt(NbtCompound nbt) { + nbt.putString("Id", Registry.FLUID.getId(getFluid()).toString()); - tag.put("Amount", Fraction.CODEC.encodeStart(NbtOps.INSTANCE, amount).resultOrPartial(UniversalComponents.logger::error).orElseGet(CompoundTag::new)); + nbt.put("Amount", Fraction.CODEC.encodeStart(NbtOps.INSTANCE, amount).resultOrPartial(UniversalComponents.logger::error).orElseGet(NbtCompound::new)); - if (this.tag != null) { - tag.put("Tag", this.tag.copy()); + if (this.nbt != null) { + nbt.put("Nbt", this.nbt.copy()); } - return tag; + return nbt; } }