Posted February 10, 20223 yr Hello, it's me again! I'm currently in the process of making a port to 1.18.1 when I stumbled across a roadblock. package com.Polarice3.FireNBlood.items.capability; import com.Polarice3.FireNBlood.items.handler.SoulUsingItemHandler; import net.minecraft.core.Direction; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class SoulUsingItemCapability implements ICapabilitySerializable<Tag> { private final ItemStack stack; private final LazyOptional<IItemHandler> holder = LazyOptional.of(this::getHandler); private SoulUsingItemHandler handler; public SoulUsingItemCapability(ItemStack stack) { this.stack = stack; } @Nonnull private SoulUsingItemHandler getHandler() { if (handler == null) { handler = new SoulUsingItemHandler(stack); } return handler; } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? holder.cast() : LazyOptional.empty(); } public Tag serializeNBT() { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(getHandler(), null); } public void deserializeNBT(Tag nbt) { CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(getHandler(), null, nbt); } } In 1.18.1, the write and readNBTs are now obsolete so now I've no clue on how to properly set up my Capability again. Any suggestions?
February 10, 20223 yr add a serialize and deserialize method to your CapabilityHandler call there the logic from write and read method, then call these two methods from serializeNBT and deserializeNBT of your CapabilityProvider. Note you can call the logic from the read and write method directly from your CapabilityProvider if you hava setters to set the values of your Capability
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.