Skip to content

Commit

Permalink
feat: make life energy affect the energy charge of the Primordial Cra…
Browse files Browse the repository at this point in the history
…dle and allow life energy of sacrifices to exceed 100
  • Loading branch information
Elenterius committed Oct 28, 2023
1 parent 6f4732b commit ca75b23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,14 @@ protected void setChangedSilent() {

public void onSacrifice(ServerLevel level) {
BlockPos pos = getBlockPos();

float spreadChargeMultiplier = sacrificeHandler.getLifeEnergyPct();

if (level.random.nextFloat() < sacrificeHandler.getSuccessChance()) {

if (level.random.nextFloat() < sacrificeHandler.getAnomalyChance()) {
spawnPrimordialFleshBlob(level, pos, sacrificeHandler);
primalSpreadCharge += 2048;
primalSpreadCharge += Math.round(2048 * spreadChargeMultiplier);
SoundUtil.broadcastBlockSound(level, pos, SoundEvents.FOX_SCREECH, 2f, 0.5f);
}
else {
Expand All @@ -157,7 +160,7 @@ public void onSacrifice(ServerLevel level) {
spawnFleshBlob(level, pos, sacrificeHandler);
}

primalSpreadCharge += 512;
primalSpreadCharge += Math.round(512 * spreadChargeMultiplier);
SoundUtil.broadcastBlockSound(level, pos, ModSoundEvents.CREATOR_SPAWN_MOB);
}

Expand All @@ -174,7 +177,7 @@ public void onSacrifice(ServerLevel level) {
PrimordialEcosystem.tryToReplaceBlock(level, pos.below(), ModBlocks.PRIMAL_FLESH.get().defaultBlockState());
}

primalSpreadCharge += 1024;
primalSpreadCharge += Math.round(1024 * spreadChargeMultiplier);
SoundUtil.broadcastBlockSound(level, pos, ModSoundEvents.FLESH_BLOCK_STEP.get(), 1f, 0.15f + level.random.nextFloat() * 0.5f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

public class SacrificeHandler implements INBTSerializable<CompoundTag> {

private static final int MAX_VALUE = 100;
private static final int MAX_BIOMASS_VALUE = 100;

private byte biomass;
private byte lifeEnergy;
private int lifeEnergy;
private int successValue;
private int diseaseValue;
private int hostileValue;
Expand All @@ -39,11 +39,11 @@ public void reset() {
}

public boolean isFull() {
return lifeEnergy >= MAX_VALUE && biomass >= MAX_VALUE;
return lifeEnergy >= MAX_BIOMASS_VALUE && biomass >= MAX_BIOMASS_VALUE;
}

public void setBiomass(int amount) {
biomass = (byte) Mth.clamp(amount, 0, MAX_VALUE);
biomass = (byte) Mth.clamp(amount, 0, MAX_BIOMASS_VALUE);
}

public boolean addBiomass(int amount) {
Expand All @@ -54,7 +54,7 @@ public boolean addBiomass(int amount) {
return true;
}

if (amount > 0 && biomass < MAX_VALUE) {
if (amount > 0 && biomass < MAX_BIOMASS_VALUE) {
setBiomass(biomass + amount);
return true;
}
Expand All @@ -67,11 +67,11 @@ public int getBiomassAmount() {
}

public float getBiomassPct() {
return biomass / (float) MAX_VALUE;
return biomass / 100f;
}

public void setLifeEnergy(int amount) {
lifeEnergy = (byte) Mth.clamp(amount, 0, MAX_VALUE);
lifeEnergy = (byte) Mth.clamp(amount, 0, Integer.MAX_VALUE);
}

public boolean addLifeEnergy(int amount) {
Expand All @@ -82,7 +82,7 @@ public boolean addLifeEnergy(int amount) {
return true;
}

if (amount > 0 && lifeEnergy < MAX_VALUE) {
if (amount > 0) {
setLifeEnergy(lifeEnergy + amount);
return true;
}
Expand All @@ -95,7 +95,7 @@ public int getLifeEnergyAmount() {
}

public float getLifeEnergyPct() {
return lifeEnergy / (float) MAX_VALUE;
return lifeEnergy / 100f;
}

public float getSuccessChance() {
Expand Down Expand Up @@ -184,7 +184,7 @@ public boolean addTribute(Tribute tribute) {
public CompoundTag serializeNBT() {
CompoundTag tag = new CompoundTag();
tag.putByte("Biomass", biomass);
tag.putByte("LifeEnergy", lifeEnergy);
tag.putInt("LifeEnergy", lifeEnergy);

tag.putInt("Success", successValue);

Expand All @@ -199,7 +199,7 @@ public CompoundTag serializeNBT() {
@Override
public void deserializeNBT(CompoundTag tag) {
biomass = tag.getByte("Biomass");
lifeEnergy = tag.getByte("LifeEnergy");
lifeEnergy = tag.getInt("LifeEnergy");

successValue = tag.getInt("Success");

Expand Down

0 comments on commit ca75b23

Please sign in to comment.