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;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
2018-11-12 01:29:33 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2018-11-13 11:39:28 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-10-25 18:49:42 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
|
|
|
|
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
|
2018-12-02 01:36:41 +01:00
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
|
|
|
if (spot < 0) {
|
2018-10-25 18:49:42 +02:00
|
|
|
List<ISpotDrainable> tiles = new ArrayList<>();
|
|
|
|
Helper.getTileEntitiesInArea(world, pos, 25, tile -> {
|
2020-01-21 23:02:39 +01:00
|
|
|
IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
|
|
|
|
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()) {
|
2018-11-12 01:29:33 +01:00
|
|
|
IAuraType type = IAuraType.forWorld(world);
|
2018-10-25 18:49:42 +02:00
|
|
|
for (int i = world.rand.nextInt(6); i >= 0; i--) {
|
|
|
|
ISpotDrainable tile = tiles.get(world.rand.nextInt(tiles.size()));
|
2018-11-07 23:42:13 +01:00
|
|
|
if (!tile.isAcceptableType(type))
|
|
|
|
continue;
|
2018-12-02 01:36:41 +01:00
|
|
|
int 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
|
2018-11-13 18:21:41 +01:00
|
|
|
public boolean appliesHere(Chunk 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() {
|
|
|
|
return NAME;
|
|
|
|
}
|
2018-10-25 18:49:42 +02:00
|
|
|
}
|