2018-11-29 00:47:21 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2020-01-22 23:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.tileentity.ITickableTileEntity;
|
2018-11-29 00:47:21 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
public class TileEntityAnimalGenerator extends TileEntityImpl implements ITickableTileEntity {
|
2018-11-29 00:47:21 +01:00
|
|
|
|
|
|
|
private int timeRemaining;
|
|
|
|
private int amountToRelease;
|
|
|
|
|
2020-01-22 01:32:26 +01:00
|
|
|
public TileEntityAnimalGenerator() {
|
|
|
|
super(ModTileEntities.ANIMAL_GENERATOR);
|
2020-01-21 21:04:44 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 00:47:21 +01:00
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public void tick() {
|
2018-11-29 00:47:21 +01:00
|
|
|
if (!this.world.isRemote) {
|
2020-01-21 21:04:44 +01:00
|
|
|
if (this.world.getGameTime() % 10 != 0)
|
2018-11-29 00:47:21 +01:00
|
|
|
return;
|
|
|
|
if (this.timeRemaining <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int remain = this.amountToRelease;
|
2019-02-16 01:43:40 +01:00
|
|
|
if (this.canGenerateRightNow(35, remain)) {
|
|
|
|
while (remain > 0) {
|
|
|
|
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
|
|
|
|
remain -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, remain);
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:21:52 +01:00
|
|
|
PacketHandler.sendToAllAround(this.world, this.pos, 32,
|
2020-01-26 00:16:06 +01:00
|
|
|
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ANIMAL_GEN_CREATE));
|
2018-11-29 00:47:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.timeRemaining -= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 13:36:05 +01:00
|
|
|
@Override
|
|
|
|
public boolean wantsLimitRemover() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-29 00:47:21 +01:00
|
|
|
public boolean isBusy() {
|
|
|
|
return this.timeRemaining > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGenerationValues(int time, int amount) {
|
|
|
|
this.timeRemaining = time;
|
|
|
|
this.amountToRelease = amount;
|
|
|
|
}
|
|
|
|
}
|