I've been digging for some capabilities knowledge and I can see a lot of people using capabilities and nbt tags to add custom properties to block entities. Should I stick with the custom storage or would the capability system be a better way to implement my mechanic?
So far I have these prototype codes:
public class HeatCapability implements IHeat{
@Override
public void setHeat(double heat) {
}
@Override
public double getHeat() {
return 0;
}
@Override
public double ExchangeRate() {
return 0;
}
@Override
public double HeatCapacity() {
return 0;
}
@Override
public double ExchangeFactor() {
return 0;
}
@Override
public void write(DataOutput pOutput) throws IOException {
}
@Override
public byte getId() {
return 0;
}
@Override
public TagType<?> getType() {
return null;
}
@Override
public Tag copy() {
return null;
}
@Override
public void accept(TagVisitor pVisitor) {
}
}
public class HeatStorage implements ICapabilitySerializable<CompoundTag> {
@CapabilityInject(IHeat.class)
public static final Capability<IHeat> HEAT_CAPABILITY = null;
public static final LazyOptional<IHeat> instance = LazyOptional.of(HEAT_CAPABILITY::getDefaultInstance);
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
return cap == HEAT_CAPABILITY? (LazyOptional<T>) instance : LazyOptional.empty();
}
@Override
public CompoundTag serializeNBT() {
CompoundTag nbt = new CompoundTag();
nbt.putDouble("Heat", instance.resolve().get().getHeat());
return nbt;
}
@Override
public void deserializeNBT(CompoundTag nbt) {
instance.resolve().get().setHeat(nbt.getDouble("Heat"));
}
}