simplified aura generation code

This commit is contained in:
Ell 2021-03-30 15:44:31 +02:00
parent df69f29568
commit f4bb53ec5e
12 changed files with 32 additions and 60 deletions

View file

@ -88,13 +88,9 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType());
if (amount == null || amount <= 0)
return;
if (!generator.canGenerateRightNow(35, amount))
if (!generator.canGenerateRightNow(amount))
return;
while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(entity.world, pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(entity.world, spot).storeAura(spot, amount);
}
generator.generateAura(amount);
PacketHandler.sendToAllAround(entity.world, pos, 32,
new PacketParticles((float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ()));

View file

@ -24,12 +24,8 @@ public class TileEntityAnimalGenerator extends TileEntityImpl implements ITickab
return;
int remain = this.amountToRelease;
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);
}
if (this.canGenerateRightNow(remain)) {
this.generateAura(remain);
PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ANIMAL_GEN_CREATE));
}

View file

@ -22,8 +22,7 @@ public class TileEntityAuraBloom extends TileEntityImpl implements ITickableTile
public void tick() {
if (this.world.isRemote || !this.justGenerated)
return;
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, this.pos);
chunk.storeAura(this.pos, 150000);
this.generateAura(150000);
this.justGenerated = false;
}

View file

@ -46,12 +46,7 @@ public class TileEntityChorusGenerator extends TileEntityImpl implements ITickab
this.world.removeBlock(pos, false);
this.world.playSound(null, this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5,
SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 0.5F, 1F);
int aura = this.auraPerBlock;
while (aura > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
aura -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, aura);
}
this.generateAura(this.auraPerBlock);
}
@Override

View file

@ -78,11 +78,7 @@ public class TileEntityEndFlower extends TileEntityImpl implements ITickableTile
} else {
int toDrain = Math.min(5000, this.container.getStoredAura());
this.container.drainAura(toDrain, false);
while (toDrain > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos);
toDrain -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toDrain);
}
this.generateAura(toDrain);
if (this.container.getStoredAura() <= 0) {
this.world.setBlockState(this.pos, Blocks.DEAD_BUSH.getDefaultState());

View file

@ -98,7 +98,7 @@ public class TileEntityFireworkGenerator extends TileEntityImpl implements ITick
if (generateFactor > 0) {
int toAdd = MathHelper.ceil(generateFactor * 10000F);
if (this.canGenerateRightNow(35, toAdd)) {
if (this.canGenerateRightNow(toAdd)) {
this.toRelease = toAdd;
this.releaseTimer = 15 * flightTime + 40;
}
@ -121,10 +121,8 @@ public class TileEntityFireworkGenerator extends TileEntityImpl implements ITick
if (this.releaseTimer > 0) {
this.releaseTimer--;
if (this.releaseTimer <= 0) {
while (this.toRelease > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
this.toRelease -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, this.toRelease);
}
this.generateAura(this.toRelease);
this.toRelease = 0;
PacketHandler.sendToAllLoaded(this.world, this.pos,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));

View file

@ -58,15 +58,12 @@ public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
int addAmount = 25000;
int toAdd = Math.max(0, addAmount - curr.getValue() * 100);
if (toAdd > 0) {
if (IAuraType.forWorld(this.world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(30, toAdd)) {
int remain = toAdd;
while (remain > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos);
remain -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, remain);
}
} else
if (IAuraType.forWorld(this.world).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) && this.canGenerateRightNow(toAdd)) {
this.generateAura(toAdd);
} else {
toAdd = 0;
}
}
for (Map.Entry<BlockState, MutableInt> entry : this.consumedRecently.entrySet()) {
if (entry.getKey() != state) {

View file

@ -14,6 +14,7 @@ import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.capabilities.Capability;
@ -168,13 +169,13 @@ public class TileEntityImpl extends TileEntity {
}
}
public boolean canGenerateRightNow(int range, int toAdd) {
public boolean canGenerateRightNow(int toAdd) {
if (this.wantsLimitRemover()) {
BlockState below = this.world.getBlockState(this.pos.down());
if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER)
return true;
}
int aura = IAuraChunk.getAuraInArea(this.world, this.pos, range);
int aura = IAuraChunk.getAuraInArea(this.world, this.pos, 35);
return aura + toAdd <= IAuraChunk.DEFAULT_AURA * 2;
}
@ -182,6 +183,13 @@ public class TileEntityImpl extends TileEntity {
return false;
}
public void generateAura(int amount) {
while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
amount -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, amount);
}
}
public enum SaveType {
TILE,
SYNC,

View file

@ -51,12 +51,8 @@ public class TileEntityMossGenerator extends TileEntityImpl implements ITickable
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
int toAdd = 7000;
if (this.canGenerateRightNow(35, toAdd)) {
while (toAdd > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
toAdd -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toAdd);
}
if (this.canGenerateRightNow(toAdd)) {
this.generateAura(toAdd);
PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.MOSS_GENERATOR));
}

View file

@ -25,12 +25,9 @@ public class TileEntityOakGenerator extends TileEntityImpl implements ITickableT
BlockPos pos = this.scheduledBigTrees.remove();
if (this.world.getBlockState(pos).getBlock().getTags().contains(BlockTags.LOGS.getName())) {
int toAdd = 100000;
boolean canGen = this.canGenerateRightNow(25, toAdd);
boolean canGen = this.canGenerateRightNow(toAdd);
if (canGen)
while (toAdd > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 25, this.pos);
toAdd -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toAdd);
}
this.generateAura(toAdd);
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.OAK_GENERATOR,

View file

@ -45,12 +45,9 @@ public class TileEntityPotionGenerator extends TileEntityImpl implements ITickab
}
int toAdd = (effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25) * 100;
boolean canGen = this.canGenerateRightNow(30, toAdd);
boolean canGen = this.canGenerateRightNow(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);
}
this.generateAura(toAdd);
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.POTION_GEN,

View file

@ -25,11 +25,8 @@ public class TileEntitySlimeSplitGenerator extends TileEntityImpl implements ITi
return;
if (this.generationTimer > 0) {
int amount = this.amountToRelease * 10;
if (this.canGenerateRightNow(35, amount)) {
while (amount > 0) {
BlockPos pos = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
amount -= IAuraChunk.getAuraChunk(this.world, pos).storeAura(pos, amount);
}
if (this.canGenerateRightNow(amount)) {
this.generateAura(amount);
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.SLIME_SPLIT_GEN_CREATE, this.color));
}
this.generationTimer -= 10;