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;
|
2019-02-09 21:55:40 +01:00
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-02-09 21:55:40 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2018-12-14 13:51:08 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
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;
|
|
|
|
private AxisAlignedBB bb;
|
|
|
|
|
|
|
|
private boolean calcValues(World world, 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;
|
2018-12-14 13:51:08 +01:00
|
|
|
int aura = IAuraChunk.getAuraInArea(world, pos, 20);
|
2019-01-29 11:46:38 +01:00
|
|
|
if (aura < 1500000)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2018-12-14 13:51:08 +01:00
|
|
|
int dist = MathHelper.clamp(aura / 3500, 3, 15);
|
2019-02-09 21:55:40 +01:00
|
|
|
this.bb = new AxisAlignedBB(pos).grow(dist);
|
2019-02-22 12:06:14 +01:00
|
|
|
this.amount = MathHelper.ceil(aura / 250F / IAuraChunk.getSpotAmountInArea(world, pos, 20));
|
2019-02-09 21:55:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-23 16:05:52 +01:00
|
|
|
public ActiveType isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2019-02-09 21:55:40 +01:00
|
|
|
if (!this.calcValues(player.world, pos, spot))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INACTIVE;
|
2019-02-09 21:55:40 +01:00
|
|
|
if (!this.bb.contains(player.getPositionVector()))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INACTIVE;
|
2019-02-09 21:55:40 +01:00
|
|
|
if (NaturesAuraAPI.instance().isEffectPowderActive(player.world, player.getPosition(), 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
|
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
|
|
|
if (!this.calcValues(world, pos, spot))
|
|
|
|
return;
|
2019-10-20 22:30:49 +02:00
|
|
|
List<PlayerEntity> players = world.getEntitiesWithinAABB(PlayerEntity.class, this.bb);
|
|
|
|
for (PlayerEntity player : players) {
|
2019-02-09 21:55:40 +01:00
|
|
|
if (NaturesAuraAPI.instance().isEffectPowderActive(world, player.getPosition(), NAME))
|
|
|
|
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
|
|
|
|
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
|
|
|
return ModConfig.enabledFeatures.cacheRechargeEffect;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getName() {
|
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
}
|