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

76 lines
3.1 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.blocks.tiles;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
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;
2019-10-20 22:30:49 +02:00
import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Potion;
2020-01-22 23:21:52 +01:00
import net.minecraft.potion.PotionUtils;
2021-12-04 15:40:09 +01:00
import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
2020-01-21 21:04:44 +01:00
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
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-04 15:40:09 +01:00
public BlockEntityPotionGenerator() {
2020-01-22 01:32:26 +01:00
super(ModTileEntities.POTION_GENERATOR);
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)) {
boolean addedOne = false;
2021-12-04 15:40:09 +01:00
List<AreaEffectCloudEntity> clouds = this.level.getEntitiesWithinAABB(AreaEffectCloudEntity.class, new AxisAlignedBB(this.worldPosition).grow(2));
2019-10-20 22:30:49 +02:00
for (AreaEffectCloudEntity cloud : clouds) {
2020-01-21 21:04:44 +01:00
if (!cloud.isAlive())
continue;
2018-10-28 16:21:43 +01:00
if (!addedOne) {
2020-01-21 21:04:44 +01:00
Potion type = ObfuscationReflectionHelper.getPrivateValue(AreaEffectCloudEntity.class, cloud, "field_184502_e");
2018-10-28 16:21:43 +01:00
if (type == null)
continue;
2019-10-20 22:30:49 +02:00
for (EffectInstance effect : type.getEffects()) {
Effect potion = effect.getPotion();
2020-01-21 21:04:44 +01:00
if (!potion.isBeneficial() || potion.isInstant()) {
2018-10-28 16:21:43 +01:00
continue;
}
2020-01-26 00:16:06 +01:00
int toAdd = (effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25) * 100;
2021-03-30 15:44:31 +02:00
boolean 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,
2020-01-22 23:21:52 +01:00
PotionUtils.getPotionColor(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
float newRadius = cloud.getRadius() - 0.25F;
if (newRadius < 0.5F)
2020-01-21 21:04:44 +01:00
cloud.remove();
2018-10-28 16:21:43 +01:00
else
cloud.setRadius(newRadius);
}
}
}
}
@Override
public boolean wantsLimitRemover() {
return true;
}
}