2018-12-14 13:51:08 +01:00
|
|
|
package de.ellpeck.naturesaura.chunk.effect;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2023-06-27 10:40:31 +02:00
|
|
|
import de.ellpeck.naturesaura.chunk.AuraChunk;
|
2019-02-09 21:55:40 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.util.Mth;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.chunk.LevelChunk;
|
|
|
|
import net.minecraft.world.phys.AABB;
|
2018-12-14 13:51:08 +01:00
|
|
|
|
|
|
|
public class CacheRechargeEffect implements IDrainSpotEffect {
|
|
|
|
|
|
|
|
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "cache_recharge");
|
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
private int amount;
|
2021-12-15 14:26:42 +01:00
|
|
|
private AABB bb;
|
2019-02-09 21:55:40 +01:00
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
|
2019-01-29 11:46:38 +01:00
|
|
|
if (spot < 100000)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2021-12-15 16:30:22 +01:00
|
|
|
var auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 20);
|
2021-06-28 14:31:37 +02:00
|
|
|
int aura = auraAndSpots.getLeft();
|
2019-01-29 11:46:38 +01:00
|
|
|
if (aura < 1500000)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2021-12-15 16:30:22 +01:00
|
|
|
var dist = Mth.clamp(aura / 3500, 3, 15);
|
2021-12-15 16:24:53 +01:00
|
|
|
this.bb = new AABB(pos).inflate(dist);
|
2021-12-04 19:17:21 +01:00
|
|
|
this.amount = Mth.ceil(aura / 250F / auraAndSpots.getRight());
|
2019-02-09 21:55:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 16:24:53 +01:00
|
|
|
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!this.calcValues(player.level, pos, spot))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INACTIVE;
|
2021-12-15 16:24:53 +01:00
|
|
|
if (!this.bb.contains(player.getEyePosition()))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INACTIVE;
|
2022-06-27 15:24:04 +02:00
|
|
|
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.blockPosition(), CacheRechargeEffect.NAME))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INHIBITED;
|
|
|
|
return ActiveType.ACTIVE;
|
2019-02-09 21:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getDisplayIcon() {
|
|
|
|
return new ItemStack(ModItems.AURA_CACHE);
|
|
|
|
}
|
2018-12-14 13:51:08 +01:00
|
|
|
|
2019-02-09 21:55:40 +01: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) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!this.calcValues(level, pos, spot))
|
2019-02-09 21:55:40 +01:00
|
|
|
return;
|
2021-12-15 16:30:22 +01:00
|
|
|
var players = level.getEntitiesOfClass(Player.class, this.bb);
|
|
|
|
for (var player : players) {
|
2022-06-27 15:24:04 +02:00
|
|
|
if (NaturesAuraAPI.instance().isEffectPowderActive(level, player.blockPosition(), CacheRechargeEffect.NAME))
|
2019-02-09 21:55:40 +01:00
|
|
|
continue;
|
|
|
|
if (NaturesAuraAPI.instance().insertAuraIntoPlayer(player, this.amount, true)) {
|
|
|
|
NaturesAuraAPI.instance().insertAuraIntoPlayer(player, this.amount, false);
|
|
|
|
auraChunk.drainAura(pos, this.amount);
|
2018-12-14 13:51:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 16:24:53 +01:00
|
|
|
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
2020-01-24 17:05:41 +01:00
|
|
|
return ModConfig.instance.cacheRechargeEffect.get();
|
2018-12-14 13:51:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getName() {
|
2022-06-27 15:24:04 +02:00
|
|
|
return CacheRechargeEffect.NAME;
|
2018-12-14 13:51:08 +01:00
|
|
|
}
|
|
|
|
}
|