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 org.apache.commons.lang3.mutable.MutableInt;
|
|
|
|
|
|
|
|
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-11-11 13:26:19 +01:00
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, MutableInt spot) {
|
2018-10-25 18:49:42 +02:00
|
|
|
int amount = spot.intValue();
|
|
|
|
if (amount < 0) {
|
|
|
|
List<ISpotDrainable> tiles = new ArrayList<>();
|
|
|
|
Helper.getTileEntitiesInArea(world, pos, 25, tile -> {
|
2018-11-12 22:04:40 +01:00
|
|
|
if (tile.hasCapability(NaturesAuraAPI.capAuraContainer, null)) {
|
|
|
|
IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null);
|
2018-10-25 18:49:42 +02:00
|
|
|
if (container instanceof ISpotDrainable) {
|
|
|
|
tiles.add((ISpotDrainable) container);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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-10-25 18:49:42 +02:00
|
|
|
int drained = tile.drainAuraPassively(-amount, 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);
|
|
|
|
amount += drained;
|
|
|
|
if (amount >= drained) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 23:42:13 +01:00
|
|
|
|
|
|
|
@Override
|
2018-11-12 01:29:33 +01:00
|
|
|
public boolean appliesToType(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
|
|
|
}
|