2018-11-13 11:39:28 +01:00
|
|
|
package de.ellpeck.naturesaura.chunk.effect;
|
2018-10-25 18:49:42 +02:00
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2018-11-13 11:39:28 +01:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-11-12 22:04:40 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.ISpotDrainable;
|
2018-11-12 01:29:33 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2023-06-27 10:40:31 +02:00
|
|
|
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.chunk.LevelChunk;
|
2018-10-25 18:49:42 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class ReplenishingEffect implements IDrainSpotEffect {
|
2018-11-13 11:39:28 +01:00
|
|
|
|
|
|
|
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "replenishing");
|
|
|
|
|
2018-10-25 18:49:42 +02:00
|
|
|
@Override
|
2023-06-27 10:40:31 +02:00
|
|
|
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot, AuraChunk.DrainSpot actualSpot) {
|
2018-12-02 01:36:41 +01:00
|
|
|
if (spot < 0) {
|
2018-10-25 18:49:42 +02:00
|
|
|
List<ISpotDrainable> tiles = new ArrayList<>();
|
2021-12-04 19:17:21 +01:00
|
|
|
Helper.getBlockEntitiesInArea(level, pos, 25, tile -> {
|
2024-03-10 15:54:58 +01:00
|
|
|
var container = level.getCapability(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, tile.getBlockPos(), tile.getBlockState(), tile, null);
|
2020-01-21 23:02:39 +01:00
|
|
|
if (container instanceof ISpotDrainable)
|
|
|
|
tiles.add((ISpotDrainable) container);
|
2018-11-14 19:14:03 +01:00
|
|
|
return false;
|
2018-10-25 18:49:42 +02:00
|
|
|
});
|
|
|
|
if (!tiles.isEmpty()) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var type = IAuraType.forLevel(level);
|
|
|
|
for (var i = level.random.nextInt(6); i >= 0; i--) {
|
|
|
|
var tile = tiles.get(level.random.nextInt(tiles.size()));
|
2018-11-07 23:42:13 +01:00
|
|
|
if (!tile.isAcceptableType(type))
|
|
|
|
continue;
|
2021-12-15 16:30:22 +01:00
|
|
|
var drained = tile.drainAuraPassively(-spot, false);
|
2018-11-07 23:42:13 +01:00
|
|
|
if (drained <= 0)
|
|
|
|
continue;
|
2018-10-25 18:49:42 +02:00
|
|
|
auraChunk.storeAura(pos, drained);
|
2018-12-02 01:36:41 +01:00
|
|
|
spot += drained;
|
|
|
|
if (spot >= drained) {
|
2018-10-25 18:49:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 23:42:13 +01:00
|
|
|
|
|
|
|
@Override
|
2021-12-15 16:24:53 +01:00
|
|
|
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
2018-11-07 23:42:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-13 11:39:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getName() {
|
2022-06-27 15:24:04 +02:00
|
|
|
return ReplenishingEffect.NAME;
|
2018-11-13 11:39:28 +01:00
|
|
|
}
|
2024-03-10 15:54:58 +01:00
|
|
|
|
2018-10-25 18:49:42 +02:00
|
|
|
}
|