2019-04-14 11:22:11 +02:00
|
|
|
package de.ellpeck.naturesaura.chunk;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
|
|
|
import net.minecraft.util.Direction;
|
2019-04-14 11:22:11 +02:00
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
|
|
import net.minecraftforge.common.util.INBTSerializable;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraftforge.common.util.LazyOptional;
|
2019-04-14 11:22:11 +02:00
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
public class AuraChunkProvider implements ICapabilityProvider, INBTSerializable<CompoundNBT> {
|
2019-04-14 11:22:11 +02:00
|
|
|
|
|
|
|
private final Chunk chunk;
|
|
|
|
private IAuraChunk auraChunk;
|
|
|
|
|
|
|
|
public AuraChunkProvider(Chunk chunk) {
|
|
|
|
this.chunk = chunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IAuraChunk getAuraChunk() {
|
|
|
|
if (this.auraChunk == null)
|
|
|
|
this.auraChunk = new AuraChunk(this.chunk, IAuraType.forWorld(this.chunk.getWorld()));
|
|
|
|
return this.auraChunk;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2020-01-21 23:02:39 +01:00
|
|
|
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
|
|
|
|
return capability == NaturesAuraAPI.capAuraChunk ? LazyOptional.of(() -> (T) this.getAuraChunk()) : LazyOptional.empty();
|
2019-04-14 11:22:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public CompoundNBT serializeNBT() {
|
2019-04-14 11:22:11 +02:00
|
|
|
return this.getAuraChunk().serializeNBT();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void deserializeNBT(CompoundNBT nbt) {
|
2019-04-14 11:22:11 +02:00
|
|
|
this.getAuraChunk().deserializeNBT(nbt);
|
|
|
|
}
|
|
|
|
}
|