2018-10-28 13:46:09 +01:00
|
|
|
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;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.AreaEffectCloudEntity;
|
|
|
|
import net.minecraft.potion.Effect;
|
|
|
|
import net.minecraft.potion.EffectInstance;
|
2018-10-28 13:46:09 +01:00
|
|
|
import net.minecraft.potion.Potion;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.tileentity.ITickableTileEntity;
|
2018-10-28 13:46:09 +01:00
|
|
|
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;
|
2018-10-28 13:46:09 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2018-10-28 13:46:09 +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)) {
|
2018-10-28 13:46:09 +01:00
|
|
|
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())
|
2018-10-28 13:46:09 +01:00
|
|
|
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)
|
2018-10-28 13:46:09 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-29 11:46:38 +01:00
|
|
|
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-21 21:04:44 +01:00
|
|
|
// TODO particles
|
|
|
|
/* 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-21 21:04:44 +01:00
|
|
|
PotionUtils.getPotionColor(type), canGen ? 1 : 0));*/
|
2018-10-28 16:21:43 +01:00
|
|
|
|
2018-10-28 13:46:09 +01:00
|
|
|
addedOne = true;
|
2018-10-28 16:21:43 +01:00
|
|
|
break;
|
2018-10-28 13:46:09 +01:00
|
|
|
}
|
|
|
|
}
|
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);
|
2018-10-28 13:46:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 13:36:05 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wantsLimitRemover() {
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-28 13:46:09 +01:00
|
|
|
}
|