NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityPotionGenerator.java

75 lines
2.9 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.blocks.tiles;
2018-11-07 13:33:49 +01:00
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
2020-01-22 23:21:52 +01:00
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
2021-12-08 00:31:29 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import java.util.List;
2021-12-04 15:40:09 +01:00
public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITickableBlockEntity {
2020-01-21 21:04:44 +01:00
2021-12-08 00:31:29 +01:00
public BlockEntityPotionGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.POTION_GENERATOR, pos, state);
2020-01-21 21:04:44 +01:00
}
@Override
2020-01-21 21:04:44 +01:00
public void tick() {
2021-12-04 15:40:09 +01:00
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) {
if (Multiblocks.POTION_GENERATOR.isComplete(this.level, this.worldPosition)) {
2021-12-15 16:30:22 +01:00
var addedOne = false;
2021-12-15 16:30:22 +01:00
var clouds = this.level.getEntitiesOfClass(AreaEffectCloud.class, new AABB(this.worldPosition).inflate(2));
for (var cloud : clouds) {
2020-01-21 21:04:44 +01:00
if (!cloud.isAlive())
continue;
2018-10-28 16:21:43 +01:00
if (!addedOne) {
2021-12-15 16:30:22 +01:00
var type = cloud.getPotion();
2018-10-28 16:21:43 +01:00
if (type == null)
continue;
2021-12-15 16:30:22 +01:00
for (var effect : type.getEffects()) {
var potion = effect.getEffect();
2021-12-08 00:31:29 +01:00
if (!potion.isBeneficial() || potion.isInstantenous()) {
2018-10-28 16:21:43 +01:00
continue;
}
2021-12-15 16:30:22 +01:00
var toAdd = (effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25) * 100;
var canGen = this.canGenerateRightNow(toAdd);
2019-02-16 01:43:40 +01:00
if (canGen)
2021-03-30 15:44:31 +02:00
this.generateAura(toAdd);
2018-10-28 16:21:43 +01:00
2021-12-04 15:40:09 +01:00
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.POTION_GEN,
2021-12-08 00:31:29 +01:00
PotionUtils.getColor(type), canGen ? 1 : 0));
2018-10-28 16:21:43 +01:00
addedOne = true;
2018-10-28 16:21:43 +01:00
break;
}
}
2018-10-28 16:21:43 +01:00
2021-12-15 16:30:22 +01:00
var newRadius = cloud.getRadius() - 0.25F;
2021-12-08 00:31:29 +01:00
if (newRadius < 0.5F) {
cloud.kill();
} else {
2018-10-28 16:21:43 +01:00
cloud.setRadius(newRadius);
2021-12-08 00:31:29 +01:00
}
}
}
}
}
@Override
public boolean wantsLimitRemover() {
return true;
}
}