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

79 lines
3.2 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;
2020-01-21 21:04:44 +01:00
import net.minecraft.tileentity.ITickableTileEntity;
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;
2020-01-21 21:04:44 +01:00
public class TileEntityPotionGenerator extends TileEntityImpl implements ITickableTileEntity {
2020-01-22 01:32:26 +01:00
public TileEntityPotionGenerator() {
super(ModTileEntities.POTION_GENERATOR);
2020-01-21 21:04:44 +01:00
}
@Override
2020-01-21 21:04:44 +01:00
public void tick() {
if (!this.world.isRemote && this.world.getGameTime() % 10 == 0) {
2018-11-07 13:33:49 +01:00
if (Multiblocks.POTION_GENERATOR.isComplete(this.world, this.pos)) {
boolean addedOne = false;
2019-10-20 22:30:49 +02:00
List<AreaEffectCloudEntity> clouds = this.world.getEntitiesWithinAABB(AreaEffectCloudEntity.class, new AxisAlignedBB(this.pos).grow(2));
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;
}
int toAdd = ((effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25)) * 100;
2019-02-16 01:43:40 +01:00
boolean canGen = this.canGenerateRightNow(30, toAdd);
if (canGen)
while (toAdd > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos);
toAdd -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toAdd);
}
2018-10-28 16:21:43 +01:00
2020-01-22 23:21:52 +01:00
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
2018-10-28 16:21:43 +01:00
this.pos.getX(), this.pos.getY(), this.pos.getZ(), 5,
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;
}
}