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

75 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;
2018-10-28 16:21:43 +01:00
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.EntityAreaEffectCloud;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionType;
2018-10-28 16:21:43 +01:00
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import java.util.List;
public class TileEntityPotionGenerator extends TileEntityImpl implements ITickable {
@Override
public void update() {
if (!this.world.isRemote && this.world.getTotalWorldTime() % 10 == 0) {
2018-11-07 13:33:49 +01:00
if (Multiblocks.POTION_GENERATOR.isComplete(this.world, this.pos)) {
boolean addedOne = false;
2018-10-28 16:21:43 +01:00
List<EntityAreaEffectCloud> clouds = this.world.getEntitiesWithinAABB(EntityAreaEffectCloud.class, new AxisAlignedBB(this.pos).grow(2));
for (EntityAreaEffectCloud cloud : clouds) {
if (cloud.isDead)
continue;
2018-10-28 16:21:43 +01:00
if (!addedOne) {
PotionType type = ReflectionHelper.getPrivateValue(EntityAreaEffectCloud.class, cloud, "field_184502_e", "potion");
if (type == null)
continue;
2018-10-28 16:21:43 +01:00
for (PotionEffect effect : type.getEffects()) {
Potion potion = effect.getPotion();
if (potion.isBadEffect() || potion.isInstant()) {
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
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
this.pos.getX(), this.pos.getY(), this.pos.getZ(), 5,
2019-02-16 01:43:40 +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)
cloud.setDead();
else
cloud.setRadius(newRadius);
}
}
}
}
@Override
public boolean wantsLimitRemover() {
return true;
}
}