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()); Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType());
if (amount == null || amount <= 0) if (amount == null || amount <= 0)
return; return;
if (!generator.canGenerateRightNow(35, amount)) if (!generator.canGenerateRightNow(amount))
return; return;
generator.generateAura(amount);
while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(entity.world, pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(entity.world, spot).storeAura(spot, amount);
}
PacketHandler.sendToAllAround(entity.world, pos, 32, 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())); 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; return;
int remain = this.amountToRelease; int remain = this.amountToRelease;
if (this.canGenerateRightNow(35, remain)) { if (this.canGenerateRightNow(remain)) {
while (remain > 0) { this.generateAura(remain);
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
remain -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, remain);
}
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.ANIMAL_GEN_CREATE)); 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() { public void tick() {
if (this.world.isRemote || !this.justGenerated) if (this.world.isRemote || !this.justGenerated)
return; return;
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.world, this.pos); this.generateAura(150000);
chunk.storeAura(this.pos, 150000);
this.justGenerated = false; this.justGenerated = false;
} }

View file

@ -46,12 +46,7 @@ public class TileEntityChorusGenerator extends TileEntityImpl implements ITickab
this.world.removeBlock(pos, false); this.world.removeBlock(pos, false);
this.world.playSound(null, this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5, 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); SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 0.5F, 1F);
this.generateAura(this.auraPerBlock);
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);
}
} }
@Override @Override

View file

@ -78,11 +78,7 @@ public class TileEntityEndFlower extends TileEntityImpl implements ITickableTile
} else { } else {
int toDrain = Math.min(5000, this.container.getStoredAura()); int toDrain = Math.min(5000, this.container.getStoredAura());
this.container.drainAura(toDrain, false); this.container.drainAura(toDrain, false);
this.generateAura(toDrain);
while (toDrain > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos);
toDrain -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toDrain);
}
if (this.container.getStoredAura() <= 0) { if (this.container.getStoredAura() <= 0) {
this.world.setBlockState(this.pos, Blocks.DEAD_BUSH.getDefaultState()); 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) { if (generateFactor > 0) {
int toAdd = MathHelper.ceil(generateFactor * 10000F); int toAdd = MathHelper.ceil(generateFactor * 10000F);
if (this.canGenerateRightNow(35, toAdd)) { if (this.canGenerateRightNow(toAdd)) {
this.toRelease = toAdd; this.toRelease = toAdd;
this.releaseTimer = 15 * flightTime + 40; this.releaseTimer = 15 * flightTime + 40;
} }
@ -121,10 +121,8 @@ public class TileEntityFireworkGenerator extends TileEntityImpl implements ITick
if (this.releaseTimer > 0) { if (this.releaseTimer > 0) {
this.releaseTimer--; this.releaseTimer--;
if (this.releaseTimer <= 0) { if (this.releaseTimer <= 0) {
while (this.toRelease > 0) { this.generateAura(this.toRelease);
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos); this.toRelease = 0;
this.toRelease -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, this.toRelease);
}
PacketHandler.sendToAllLoaded(this.world, this.pos, PacketHandler.sendToAllLoaded(this.world, this.pos,
new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION)); new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));

View file

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

View file

@ -14,6 +14,7 @@ import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.capabilities.Capability; 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()) { if (this.wantsLimitRemover()) {
BlockState below = this.world.getBlockState(this.pos.down()); BlockState below = this.world.getBlockState(this.pos.down());
if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER) if (below.getBlock() == ModBlocks.GENERATOR_LIMIT_REMOVER)
return true; 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; return aura + toAdd <= IAuraChunk.DEFAULT_AURA * 2;
} }
@ -182,6 +183,13 @@ public class TileEntityImpl extends TileEntity {
return false; 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 { public enum SaveType {
TILE, TILE,
SYNC, SYNC,

View file

@ -51,12 +51,8 @@ public class TileEntityMossGenerator extends TileEntityImpl implements ITickable
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state); BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
int toAdd = 7000; int toAdd = 7000;
if (this.canGenerateRightNow(35, toAdd)) { if (this.canGenerateRightNow(toAdd)) {
while (toAdd > 0) { this.generateAura(toAdd);
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
toAdd -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toAdd);
}
PacketHandler.sendToAllAround(this.world, this.pos, 32, PacketHandler.sendToAllAround(this.world, this.pos, 32,
new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.MOSS_GENERATOR)); 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(); BlockPos pos = this.scheduledBigTrees.remove();
if (this.world.getBlockState(pos).getBlock().getTags().contains(BlockTags.LOGS.getName())) { if (this.world.getBlockState(pos).getBlock().getTags().contains(BlockTags.LOGS.getName())) {
int toAdd = 100000; int toAdd = 100000;
boolean canGen = this.canGenerateRightNow(25, toAdd); boolean canGen = this.canGenerateRightNow(toAdd);
if (canGen) if (canGen)
while (toAdd > 0) { this.generateAura(toAdd);
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 25, this.pos);
toAdd -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toAdd);
}
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles( PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.OAK_GENERATOR, 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; int toAdd = (effect.getAmplifier() * 7 + 1) * (effect.getDuration() / 25) * 100;
boolean canGen = this.canGenerateRightNow(30, toAdd); boolean canGen = this.canGenerateRightNow(toAdd);
if (canGen) if (canGen)
while (toAdd > 0) { this.generateAura(toAdd);
BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 30, this.pos);
toAdd -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, toAdd);
}
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles( PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(
this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.POTION_GEN, 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; return;
if (this.generationTimer > 0) { if (this.generationTimer > 0) {
int amount = this.amountToRelease * 10; int amount = this.amountToRelease * 10;
if (this.canGenerateRightNow(35, amount)) { if (this.canGenerateRightNow(amount)) {
while (amount > 0) { this.generateAura(amount);
BlockPos pos = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos);
amount -= IAuraChunk.getAuraChunk(this.world, pos).storeAura(pos, 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)); 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; this.generationTimer -= 10;