Skip to content

Commit

Permalink
feat: rework Cradle sacrifice system to prefer to spawn hostile mobs …
Browse files Browse the repository at this point in the history
…and occasionally anomalies

This reworks how the tributes affect the spawning of flesh blobs and removes the spawning of malignant blobs when using living flesh.
  • Loading branch information
Elenterius committed Aug 14, 2023
1 parent 9399a51 commit 7a8bd97
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.elenterius.biomancy.block.cradle;

interface ITribute {
public interface ITribute {
ITribute EMPTY = new ITribute() {
@Override
public int biomass() {
Expand All @@ -27,6 +27,11 @@ public int hostileModifier() {
return 0;
}

@Override
public int anomalyModifier() {
return 0;
}

@Override
public boolean isEmpty() {
return true;
Expand All @@ -43,7 +48,13 @@ public boolean isEmpty() {

int hostileModifier();

int anomalyModifier();

default boolean isEmpty() {
return biomass() == 0 && lifeEnergy() == 0 && successModifier() == 0 && diseaseModifier() == 0 && hostileModifier() == 0;
return biomass() == 0 && lifeEnergy() == 0
&& successModifier() == 0
&& diseaseModifier() == 0
&& hostileModifier() == 0
&& anomalyModifier() == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public int diseaseModifier() {
public int hostileModifier() {
return hostileModifier;
}

@Override
public int anomalyModifier() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.github.elenterius.biomancy.block.cradle;

import com.github.elenterius.biomancy.block.FleshVeinsBlock;
import com.github.elenterius.biomancy.block.entity.SimpleSyncedBlockEntity;
import com.github.elenterius.biomancy.entity.fleshblob.AbstractFleshBlob;
import com.github.elenterius.biomancy.init.*;
import com.github.elenterius.biomancy.entity.fleshblob.FleshBlob;
import com.github.elenterius.biomancy.init.ModBlockEntities;
import com.github.elenterius.biomancy.init.ModDamageSources;
import com.github.elenterius.biomancy.init.ModEntityTypes;
import com.github.elenterius.biomancy.init.ModSoundEvents;
import com.github.elenterius.biomancy.network.ISyncableAnimation;
import com.github.elenterius.biomancy.network.ModNetworkHandler;
import com.github.elenterius.biomancy.util.SoundUtil;
import com.github.elenterius.biomancy.world.PrimordialEcosystem;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
Expand Down Expand Up @@ -133,47 +134,63 @@ private void resetState() {

public void onSacrifice(ServerLevel level) {
BlockPos pos = getBlockPos();
if (sacrificeHandler.getTumorFactor() < 2f && level.random.nextFloat() < sacrificeHandler.getSuccessChance()) {
spawnFleshBlob(level, pos, sacrificeHandler);
SoundUtil.broadcastBlockSound(level, pos, ModSoundEvents.CREATOR_SPAWN_MOB);
if (level.random.nextFloat() < sacrificeHandler.getSuccessChance()) {

if (level.random.nextFloat() < sacrificeHandler.getAnomalyChance()) {
spawnPrimordialFleshBlob(level, pos, sacrificeHandler);
SoundUtil.broadcastBlockSound(level, pos, SoundEvents.FOX_SCREECH, 2f, 0.5f);
}
else {
if (sacrificeHandler.getHostileChance() < -4.2f) {
spawnLegacyFleshBlob(level, pos, sacrificeHandler);
}
else {
spawnFleshBlob(level, pos, sacrificeHandler);
}
SoundUtil.broadcastBlockSound(level, pos, ModSoundEvents.CREATOR_SPAWN_MOB);
}

level.sendParticles(ParticleTypes.EXPLOSION, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 1, 0, 0, 0, 0);
}
else {
if (sacrificeHandler.getSuccessChance() > -9000) {
attackAOE(level, pos);
SoundUtil.broadcastBlockSound(level, pos, ModSoundEvents.CREATOR_SPIKE_ATTACK);
spawnFleshBlocks(level, pos, sacrificeHandler);
}
else {
spawnMalignantFleshBlob(level, pos);
SoundUtil.broadcastBlockSound(level, pos, SoundEvents.TRIDENT_THUNDER, 5f, 0.9f);
level.sendParticles(ParticleTypes.EXPLOSION, pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d, 1, 0, 0, 0, 0);
attackAOE(level, pos);
SoundUtil.broadcastBlockSound(level, pos, ModSoundEvents.CREATOR_SPIKE_ATTACK);
if (level.random.nextFloat() < sacrificeHandler.getTumorFactor()) {
PrimordialEcosystem.spreadMalignantVeinsFromSource(level, pos);
}
}

resetState();
}

public void spawnMalignantFleshBlob(ServerLevel level, BlockPos pos) {
AbstractFleshBlob fleshBlob = ModEntityTypes.MALIGNANT_FLESH_BLOB.get().create(level);
public void spawnPrimordialFleshBlob(ServerLevel level, BlockPos pos, SacrificeHandler sacrificeHandler) {
EntityType<? extends FleshBlob> entityType = level.random.nextFloat() < sacrificeHandler.getHostileChance() ? ModEntityTypes.PRIMORDIAL_HUNGRY_FLESH_BLOB.get() : ModEntityTypes.PRIMORDIAL_FLESH_BLOB.get();
spawnPrimordialFleshBlob(level, pos, entityType);
}

public void spawnPrimordialFleshBlob(ServerLevel level, BlockPos pos, EntityType<? extends FleshBlob> fleshBlobType) {
FleshBlob fleshBlob = fleshBlobType.create(level);
if (fleshBlob != null) {
float yaw = PrimordialCradleBlock.getYRotation(getBlockState());
fleshBlob.moveTo(pos.getX() + 0.5f, pos.getY() + 4f / 16f, pos.getZ() + 0.5f, yaw, 0);
fleshBlob.yHeadRot = fleshBlob.getYRot();
fleshBlob.yBodyRot = fleshBlob.getYRot();
fleshBlob.randomizeTumors();
fleshBlob.restrictTo(pos, 32);
level.addFreshEntity(fleshBlob);
}
}

public void spawnLegacyFleshBlob(ServerLevel level, BlockPos pos, SacrificeHandler sacrificeHandler) {
spawnFleshBlob(level, pos, sacrificeHandler, ModEntityTypes.LEGACY_FLESH_BLOB.get());
}

public void spawnFleshBlob(ServerLevel level, BlockPos pos, SacrificeHandler sacrificeHandler) {
EntityType<? extends AbstractFleshBlob> entityType = level.random.nextFloat() < sacrificeHandler.getHostileChance() ? ModEntityTypes.HUNGRY_FLESH_BLOB.get() : ModEntityTypes.FLESH_BLOB.get();
EntityType<? extends FleshBlob> entityType = level.random.nextFloat() < sacrificeHandler.getHostileChance() ? ModEntityTypes.HUNGRY_FLESH_BLOB.get() : ModEntityTypes.FLESH_BLOB.get();
spawnFleshBlob(level, pos, sacrificeHandler, entityType);
}

public void spawnFleshBlob(ServerLevel level, BlockPos pos, SacrificeHandler sacrificeHandler, EntityType<? extends AbstractFleshBlob> fleshBlobType) {
AbstractFleshBlob fleshBlob = fleshBlobType.create(level);
public void spawnFleshBlob(ServerLevel level, BlockPos pos, SacrificeHandler sacrificeHandler, EntityType<? extends FleshBlob> fleshBlobType) {
FleshBlob fleshBlob = fleshBlobType.create(level);
if (fleshBlob != null) {
float yaw = PrimordialCradleBlock.getYRotation(getBlockState());
fleshBlob.moveTo(pos.getX() + 0.5f, pos.getY() + 4f / 16f, pos.getZ() + 0.5f, yaw, 0);
Expand All @@ -185,25 +202,6 @@ public void spawnFleshBlob(ServerLevel level, BlockPos pos, SacrificeHandler sac
}
}

public void spawnFleshBlocks(ServerLevel level, BlockPos pos, SacrificeHandler sacrificeHandler) {
if (level.random.nextFloat() >= sacrificeHandler.getTumorFactor()) return;

FleshVeinsBlock veinsBlock = ModBlocks.MALIGNANT_FLESH_VEINS.get();
BlockState state = level.getBlockState(pos);

if (level.random.nextFloat() < 0.6f) veinsBlock.getSpreader().spreadFromRandomFaceTowardRandomDirection(state, level, pos, level.random);
if (level.random.nextFloat() < 0.6f) veinsBlock.getSpreader().spreadFromRandomFaceTowardRandomDirection(state, level, pos, level.random);
if (level.random.nextFloat() < 0.6f) veinsBlock.getSpreader().spreadFromRandomFaceTowardRandomDirection(state, level, pos, level.random);
if (level.random.nextFloat() < 0.6f) veinsBlock.getSpreader().spreadFromRandomFaceTowardRandomDirection(state, level, pos, level.random);
level.playSound(null, pos, ModSoundEvents.FLESH_BLOCK_STEP.get(), SoundSource.BLOCKS, 1f, 0.15f + level.random.nextFloat() * 0.5f);

for (Direction subDirection : Direction.allShuffled(level.random)) {
BlockPos neighborPos = pos.relative(subDirection);
BlockState neighborState = level.getBlockState(neighborPos);
veinsBlock.increaseCharge(level, neighborPos, neighborState, level.random.nextIntBetweenInclusive(1, 3));
}
}

public void attackAOE() {
if (level != null && !level.isClientSide() && level instanceof ServerLevel serverLevel) {
attackAOE(serverLevel, worldPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class SacrificeHandler implements INBTSerializable<CompoundTag> {
private byte lifeEnergy;
private int successValue;
private int diseaseValue;
private int hostileValue;
private int hostileValue = 100;
private int anomalyValue = 5;

public boolean isFull() {
return lifeEnergy >= MAX_VALUE && biomass >= MAX_VALUE;
Expand Down Expand Up @@ -84,6 +85,10 @@ public float getHostileChance() {
return hostileValue / 100f;
}

public float getAnomalyChance() {
return anomalyValue / 100f;
}

public float getTumorFactor() {
return diseaseValue / 100f;
}
Expand Down Expand Up @@ -140,6 +145,7 @@ public boolean addTribute(ITribute tribute) {
diseaseValue += tribute.diseaseModifier();
hostileValue += tribute.hostileModifier();
successValue += tribute.successModifier();
anomalyValue += tribute.anomalyModifier();
return true;
}

Expand All @@ -151,8 +157,9 @@ public void reset() {
lifeEnergy = 0;

diseaseValue = 0;
hostileValue = 0;
hostileValue = 100;
successValue = 0;
anomalyValue = 5;
}

@Override
Expand All @@ -164,6 +171,7 @@ public CompoundTag serializeNBT() {
tag.putInt("Disease", diseaseValue);
tag.putInt("Hostile", hostileValue);
tag.putInt("Success", successValue);
tag.putInt("Anomaly", anomalyValue);
return tag;
}

Expand All @@ -175,6 +183,7 @@ public void deserializeNBT(CompoundTag tag) {
diseaseValue = tag.getInt("Disease");
hostileValue = tag.getInt("Hostile");
successValue = tag.getInt("Success");
anomalyValue = tag.getInt("Anomaly");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.github.elenterius.biomancy.block.cradle;

public record Tribute(int biomass, int lifeEnergy, int successModifier, int diseaseModifier, int hostileModifier, int anomalyModifier) implements ITribute {
public Tribute(ITribute a, ITribute b) {
this(
a.biomass() + b.biomass(),
a.lifeEnergy() + b.lifeEnergy(),
a.successModifier() + b.successModifier(),
a.diseaseModifier() + b.diseaseModifier(),
a.hostileModifier() + b.hostileModifier(),
a.anomalyModifier() + b.anomalyModifier()
);
}

public static Tribute.Builder builder() {
return new Tribute.Builder();
}

public static class Builder {
private int successModifier = 0;
private int diseaseModifier = 0;
private int hostileModifier = 0;
private int biomass = 0;
private int lifeEnergy = 0;
private int anomalyModifier = 0;

public Builder successModifier(int successModifier) {
this.successModifier = successModifier;
return this;
}

public Builder diseaseModifier(int diseaseModifier) {
this.diseaseModifier = diseaseModifier;
return this;
}

public Builder hostileModifier(int hostileModifier) {
this.hostileModifier = hostileModifier;
return this;
}

public Builder biomass(int biomass) {
this.biomass = biomass;
return this;
}

public Builder lifeEnergy(int lifeEnergy) {
this.lifeEnergy = lifeEnergy;
return this;
}

public Builder anomalyModifier(int anomalyModifier) {
this.anomalyModifier = anomalyModifier;
return this;
}

public ITribute create() {
return new Tribute(biomass, lifeEnergy, successModifier, diseaseModifier, hostileModifier, anomalyModifier);
}
}
}
Loading

0 comments on commit 7a8bd97

Please sign in to comment.