Skip to content

Commit

Permalink
Make Coffins less annoying + killing Apparitions with Transfiguring P…
Browse files Browse the repository at this point in the history
…otions
  • Loading branch information
AViewFromTheTop committed Sep 28, 2024
1 parent dd5e520 commit 9648688
Show file tree
Hide file tree
Showing 29 changed files with 141 additions and 79 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Do not use this mod in attempt to harass Mojang. They are hard workers and know
- Each nearby Coffin will activate and spawn up to two mobs per-player simultaneously
- Spawned mobs will constantly track the closest player
- Coffins will have a spawning cooldown of only 150 ticks
- Coffins will also be able to spawn two Apparitions

## COFFIN
- A new block that spawns mobs
Expand All @@ -149,9 +150,9 @@ Do not use this mod in attempt to harass Mojang. They are hard workers and know
- The amount of simultaneous spawned mobs per extra player increases to one
- Irritated
- The highest strength triggered at a power of 12
- Can spawn two Apparitions instead of one
- 200 ticks between spawns
- A Coffin's power will reset after 12000 ticks, or 10 minutes
- If all spawned mobs from each stage are defeated in a timely manner, the Coffin will remain inactive for the next 30 minutes

## APPARITION
- A new mysterious mob that spawns from Coffins
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

package net.frozenblock.trailiertales;

import net.frozenblock.lib.config.api.instance.ConfigModification;
import net.frozenblock.lib.config.api.registry.ConfigRegistry;
import net.frozenblock.wilderwild.config.WWBlockConfig;
import net.frozenblock.trailiertales.mod_compat.TTModIntegrations;

public class TTPreLoadConstants {
public static final boolean IS_DATAGEN;
Expand All @@ -21,7 +19,7 @@ private static boolean isDatagen() {
static {
IS_DATAGEN = isDatagen();
if (IS_DATAGEN) {
ConfigRegistry.register(WWBlockConfig.INSTANCE, new ConfigModification<>(config -> config.snowlogging.snowlogging = false));
TTModIntegrations.WILDER_WILD_INTEGRATION.getIntegration().disableSnowloggingInDatagen();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import net.frozenblock.trailiertales.datafix.trailiertales.TTDataFixer;
import net.frozenblock.trailiertales.mod_compat.TTModIntegrations;
import net.frozenblock.trailiertales.networking.TrailierNetworking;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.frozenblock.trailiertales.registry.TTBlocks;
import net.frozenblock.trailiertales.registry.TTEnchantments;
import net.frozenblock.trailiertales.registry.TTEntities;
import net.frozenblock.trailiertales.registry.TTEntityTypes;
import net.frozenblock.trailiertales.registry.TTItems;
import net.frozenblock.trailiertales.registry.TTJukeboxSongs;
import net.frozenblock.trailiertales.registry.TTLootTables;
Expand Down Expand Up @@ -58,10 +58,10 @@ public void onInitialize(String modId, ModContainer container) {
TTStructurePieceTypes.init();
TTMapDecorationTypes.init();
TTBlocks.init();
TTBlockEntities.register();
TTBlockEntityTypes.register();
TTItems.init();
TTTrimPatterns.init();
TTEntities.init();
TTEntityTypes.init();
TTMemoryModuleTypes.register();
TTSensorTypes.register();
TTRecipeTypes.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import net.frozenblock.trailiertales.particle.GlowingColorTransitionParticle;
import net.frozenblock.trailiertales.particle.GlowingSpellParticle;
import net.frozenblock.trailiertales.particle.provider.TrailierParticleProviders;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.frozenblock.trailiertales.registry.TTBlocks;
import net.frozenblock.trailiertales.registry.TTEntities;
import net.frozenblock.trailiertales.registry.TTEntityTypes;
import net.frozenblock.trailiertales.registry.TTParticleTypes;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.particle.SoulParticle;
Expand All @@ -48,7 +48,7 @@ public void onInitializeClient() {
SplashTextAPI.addSplashLocation(TTConstants.id("texts/splashes.txt"));
addPanorama("catacombs");

BlockEntityWithoutLevelRendererRegistry.register(TTBlocks.COFFIN, TTBlockEntities.COFFIN);
BlockEntityWithoutLevelRendererRegistry.register(TTBlocks.COFFIN, TTBlockEntityTypes.COFFIN);

BlockRenderLayerMap renderLayerRegistry = BlockRenderLayerMap.INSTANCE;
renderLayerRegistry.putBlock(TTBlocks.POTTED_CYAN_ROSE, RenderType.cutout());
Expand All @@ -61,15 +61,15 @@ public void onInitializeClient() {
renderLayerRegistry.putBlock(TTBlocks.DAWNTRAIL, RenderType.cutout());
renderLayerRegistry.putBlock(TTBlocks.DAWNTRAIL_CROP, RenderType.cutout());

BlockEntityRenderers.register(TTBlockEntities.COFFIN, CoffinRenderer::new);
BlockEntityRenderers.register(TTBlockEntityTypes.COFFIN, CoffinRenderer::new);
EntityModelLayerRegistry.registerModelLayer(COFFIN_HEAD, CoffinRenderer::createHeadLayer);
EntityModelLayerRegistry.registerModelLayer(COFFIN_FOOT, CoffinRenderer::createFootLayer);

EntityRendererRegistry.register(TTEntities.APPARITION, ApparitionRenderer::new);
EntityRendererRegistry.register(TTEntityTypes.APPARITION, ApparitionRenderer::new);
EntityModelLayerRegistry.registerModelLayer(APPARITION, ApparitionModel::createBodyLayer);
EntityModelLayerRegistry.registerModelLayer(APPARITION_OVERLAY, ApparitionModel::createBodyLayer);

EntityRendererRegistry.register(TTEntities.THROWN_ITEM_PROJECTILE, ThrownItemRenderer::new);
EntityRendererRegistry.register(TTEntityTypes.THROWN_ITEM_PROJECTILE, ThrownItemRenderer::new);

EntityModelLayerRegistry.registerModelLayer(BOAT_BANNER, BoatBannerModel::createBodyLayer);

Expand Down
22 changes: 14 additions & 8 deletions src/main/java/net/frozenblock/trailiertales/block/CoffinBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import net.frozenblock.lib.networking.FrozenNetworking;
import net.frozenblock.trailiertales.TTConstants;
import net.frozenblock.trailiertales.block.entity.coffin.CoffinBlockEntity;
import net.frozenblock.trailiertales.block.entity.coffin.CoffinSpawner;
import net.frozenblock.trailiertales.block.entity.coffin.CoffinSpawnerState;
import net.frozenblock.trailiertales.block.entity.coffin.impl.EntityCoffinInterface;
import net.frozenblock.trailiertales.block.impl.CoffinPart;
import net.frozenblock.trailiertales.block.impl.TTBlockStateProperties;
import net.frozenblock.trailiertales.entity.Apparition;
import net.frozenblock.trailiertales.networking.packet.CoffinRemoveDebugPacket;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.frozenblock.trailiertales.registry.TTSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -196,12 +197,12 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
return level instanceof ServerLevel serverLevel
? createTickerHelper(
blockEntityType,
TTBlockEntities.COFFIN,
TTBlockEntityTypes.COFFIN,
(unusedWorld, pos, statex, coffin) -> coffin.getCoffinSpawner()
.tickServer(serverLevel, pos, statex, statex.getValue(PART), statex.getOptionalValue(BlockStateProperties.OMINOUS).orElse(false)))
: createTickerHelper(
blockEntityType,
TTBlockEntities.COFFIN,
TTBlockEntityTypes.COFFIN,
(world, pos, statex, coffin) -> coffin
.tickClient(world, pos, statex.getValue(PART), statex.getOptionalValue(BlockStateProperties.OMINOUS).orElse(false)));
}
Expand Down Expand Up @@ -235,7 +236,7 @@ public void appendHoverText(ItemStack stack, Item.TooltipContext tooltipContext,
Spawner.appendHoverText(stack, tooltip, "SpawnData");
}

public static void onCoffinUntrack(@Nullable Entity entity, boolean remove) {
public static void onCoffinUntrack(@Nullable Entity entity, @Nullable CoffinSpawner coffinSpawner, boolean remove) {
if (FrozenLibConfig.IS_DEBUG && entity != null && !entity.isRemoved() && entity.level() instanceof ServerLevel serverLevel) {
FrozenNetworking.sendPacketToAllPlayers(
serverLevel,
Expand All @@ -244,22 +245,27 @@ public static void onCoffinUntrack(@Nullable Entity entity, boolean remove) {
}

if (entity != null) {
entity.playSound(TTSounds.COFFIN_VANISH_MOB, 0.5F, 0.9F + (entity.getRandom().nextFloat() * 0.2F));
entity.playSound(TTSounds.COFFIN_VANISH_MOB, 0.8F, 0.9F + (entity.getRandom().nextFloat() * 0.2F));
}

if (entity instanceof LivingEntity livingEntity) {
AttributeInstance followRange = livingEntity.getAttribute(Attributes.FOLLOW_RANGE);
if (followRange != null) {
followRange.removeModifier(ATTRIBUTE_COFFIN_FOLLOW_RANGE);
}
if (followRange != null) followRange.removeModifier(ATTRIBUTE_COFFIN_FOLLOW_RANGE);
}

if (entity instanceof EntityCoffinInterface entityInterface) {
entityInterface.trailierTales$setCoffinData(null);
}

if (remove && coffinSpawner != null) {
coffinSpawner.onEntityRemoved(entity);
}

if (entity instanceof Apparition apparition && remove) {
apparition.dropItem();
apparition.level().broadcastEntityEvent(apparition, (byte)60);
apparition.discard();
apparition.dropPreservedEquipment();
} else if (remove && entity instanceof Mob mob && !mob.isPersistenceRequired() && !mob.requiresCustomPersistence()) {
mob.level().broadcastEntityEvent(mob, (byte)60);
mob.discard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.frozenblock.trailiertales.block.entity.SurveyorBlockEntity;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -133,7 +133,7 @@ public static void updatePower(@NotNull Level level, BlockPos pos, @NotNull Bloc
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
return level instanceof ServerLevel serverLevel
? createTickerHelper(blockEntityType, TTBlockEntities.SURVEYOR, (unusedWorld, pos, statex, surveyor) -> surveyor.tickServer(serverLevel, pos, statex))
? createTickerHelper(blockEntityType, TTBlockEntityTypes.SURVEYOR, (unusedWorld, pos, statex, surveyor) -> surveyor.tickServer(serverLevel, pos, statex))
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.List;
import java.util.Optional;
import net.frozenblock.trailiertales.block.SurveyorBlock;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.frozenblock.trailiertales.tag.TTEntityTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -29,7 +29,7 @@ public class SurveyorBlockEntity extends BlockEntity {
private int lastDetectionPower;

public SurveyorBlockEntity(BlockPos pos, BlockState state) {
super(TTBlockEntities.SURVEYOR, pos, state);
super(TTBlockEntityTypes.SURVEYOR, pos, state);
}

private static Vec3 chooseClosestPos(@NotNull Vec3 origin, Vec3 posA, Vec3 posB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.frozenblock.trailiertales.block.CoffinBlock;
import net.frozenblock.trailiertales.block.impl.CoffinPart;
import net.frozenblock.trailiertales.block.impl.TTBlockStateProperties;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.frozenblock.trailiertales.registry.TTSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class CoffinBlockEntity extends BlockEntity implements Spawner, CoffinSpa
private float openProgress;

public CoffinBlockEntity(BlockPos pos, BlockState state) {
super(TTBlockEntities.COFFIN, pos, state);
super(TTBlockEntityTypes.COFFIN, pos, state);
PlayerDetector.EntitySelector entitySelector = PlayerDetector.EntitySelector.SELECT_FROM_LEVEL;
this.coffinSpawner = new CoffinSpawner(this, entitySelector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.frozenblock.trailiertales.block.impl.CoffinPart;
import net.frozenblock.trailiertales.entity.Apparition;
import net.frozenblock.trailiertales.entity.ai.apparition.ApparitionAi;
import net.frozenblock.trailiertales.registry.TTEntities;
import net.frozenblock.trailiertales.registry.TTEntityTypes;
import net.frozenblock.trailiertales.registry.TTParticleTypes;
import net.frozenblock.trailiertales.registry.TTSounds;
import net.frozenblock.trailiertales.tag.TTBlockTags;
Expand Down Expand Up @@ -348,10 +348,10 @@ public boolean canSpawnApparition(Level level, BlockPos pos) {
}

public void spawnApparition(@NotNull ServerLevel level, @NotNull BlockPos pos) {
Apparition apparition = TTEntities.APPARITION.create(level, null, pos, MobSpawnType.TRIAL_SPAWNER, true, false);
Apparition apparition = TTEntityTypes.APPARITION.create(level, null, pos, MobSpawnType.TRIAL_SPAWNER, true, false);
if (apparition != null) {
if (level.addFreshEntity(apparition)) {
apparition.hiddenTicks = 500;
apparition.hiddenTicks = 100;
this.appendCoffinSpawnAttributes(apparition, level, pos, true);
this.data.nextApparitionSpawnsAt = level.getGameTime() + 1000L;
this.data.currentApparitions.add(apparition.getUUID());
Expand Down Expand Up @@ -418,7 +418,7 @@ public void tickServer(ServerLevel world, BlockPos pos, BlockState state, Coffin
Entity entity = world.getEntity(uiid);
boolean shouldUntrack = shouldMobBeUntracked(world, pos, entity);
if (shouldUntrack) {
CoffinBlock.onCoffinUntrack(entity, false);
CoffinBlock.onCoffinUntrack(entity, this, false);
}
return shouldUntrack;
});
Expand All @@ -427,7 +427,7 @@ public void tickServer(ServerLevel world, BlockPos pos, BlockState state, Coffin
Entity entity = world.getEntity(uiid);
boolean shouldUntrack = shouldMobBeUntracked(world, pos, entity);
if (shouldUntrack) {
CoffinBlock.onCoffinUntrack(entity, true);
CoffinBlock.onCoffinUntrack(entity, this, true);
}
return shouldUntrack;
});
Expand Down Expand Up @@ -467,6 +467,12 @@ public static boolean isInCatacombsBounds(BlockPos pos, @NotNull StructureManage
return structure != null && structureManager.structureHasPieceAt(pos, structureManager.getStructureAt(pos, structure));
}

public void onEntityRemoved(@NotNull Entity entity) {
if (entity.level() instanceof ServerLevel serverLevel && entity instanceof Apparition) {
this.data.nextApparitionSpawnsAt = serverLevel.getGameTime() + this.getConfig().ticksBetweenApparitionSpawn();
}
}

public interface StateAccessor {
void setState(Level level, CoffinSpawnerState state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public record CoffinSpawnerConfig(
float simultaneousMobsAddedPerPlayer,
int ticksBetweenSpawn,
int powerForNextLevel,
int maxApparitions
int maxApparitions,
int ticksBetweenApparitionSpawn
) {
public static final CoffinSpawnerConfig DEFAULT = new CoffinSpawnerConfig(
4,
Expand All @@ -21,7 +22,8 @@ public record CoffinSpawnerConfig(
0F,
400,
4,
1
1,
1800
);
public static final CoffinSpawnerConfig IRRITATED = new CoffinSpawnerConfig(
5,
Expand All @@ -31,7 +33,8 @@ public record CoffinSpawnerConfig(
1F,
300,
6,
1
1,
9000
);
public static final CoffinSpawnerConfig AGGRESSIVE = new CoffinSpawnerConfig(
6,
Expand All @@ -41,7 +44,8 @@ public record CoffinSpawnerConfig(
1F,
200,
10,
2
1,
700
);
public static final CoffinSpawnerConfig OMINOUS = new CoffinSpawnerConfig(
6,
Expand All @@ -51,13 +55,18 @@ public record CoffinSpawnerConfig(
1F,
150,
15,
2
2,
500
);

public static final Codec<CoffinSpawnerConfig> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
Codec.intRange(1, 128).lenientOptionalFieldOf("spawn_range", DEFAULT.spawnRange).forGetter(CoffinSpawnerConfig::spawnRange),
Codec.floatRange(0F, Float.MAX_VALUE).lenientOptionalFieldOf("total_mobs", DEFAULT.totalMobs).forGetter(CoffinSpawnerConfig::totalMobs),
Codec.intRange(1, 128)
.lenientOptionalFieldOf("spawn_range", DEFAULT.spawnRange)
.forGetter(CoffinSpawnerConfig::spawnRange),
Codec.floatRange(0F, Float.MAX_VALUE)
.lenientOptionalFieldOf("total_mobs", DEFAULT.totalMobs)
.forGetter(CoffinSpawnerConfig::totalMobs),
Codec.floatRange(0F, Float.MAX_VALUE)
.lenientOptionalFieldOf("simultaneous_mobs", DEFAULT.simultaneousMobs)
.forGetter(CoffinSpawnerConfig::simultaneousMobs),
Expand All @@ -75,7 +84,10 @@ public record CoffinSpawnerConfig(
.forGetter(CoffinSpawnerConfig::powerForNextLevel),
Codec.intRange(0, Integer.MAX_VALUE)
.lenientOptionalFieldOf("max_apparitions", DEFAULT.maxApparitions)
.forGetter(CoffinSpawnerConfig::maxApparitions)
.forGetter(CoffinSpawnerConfig::maxApparitions),
Codec.intRange(800, Integer.MAX_VALUE)
.lenientOptionalFieldOf("ticks_between_apparition_spawn", DEFAULT.ticksBetweenApparitionSpawn)
.forGetter(CoffinSpawnerConfig::ticksBetweenApparitionSpawn)
)
.apply(instance, CoffinSpawnerConfig::new)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void reset() {
this.power = 0;
this.nextMobSpawnsAt = 0L;
this.powerCooldownEndsAt = 0L;
this.nextApparitionSpawnsAt = 0L;
this.currentMobs.clear();
this.currentApparitions.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public UUID getCoffinUUID() {
public void tick(LivingEntity entity, @NotNull Level level) {
if (level instanceof ServerLevel serverLevel) {
long gameTime = level.getGameTime();
boolean canUntrackFromTime = (gameTime - this.lastInteractionAt) > 2400 && !(entity instanceof Apparition);
boolean canUntrackFromTime = (gameTime - this.lastInteractionAt) > 1800 && !(entity instanceof Apparition);
Optional<CoffinSpawner> optionalCoffinSpawner = this.getSpawner(level);
if (optionalCoffinSpawner.isEmpty() || canUntrackFromTime) {
CoffinBlock.onCoffinUntrack(entity, true);
CoffinBlock.onCoffinUntrack(entity, null, true);
} else {
if (FrozenLibConfig.IS_DEBUG) {
FrozenNetworking.sendPacketToAllPlayers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.frozenblock.trailiertales.block.entity.coffin.CoffinBlockEntity;
import net.frozenblock.trailiertales.block.entity.coffin.CoffinSpawnerState;
import net.frozenblock.trailiertales.block.impl.CoffinPart;
import net.frozenblock.trailiertales.registry.TTBlockEntities;
import net.frozenblock.trailiertales.registry.TTBlockEntityTypes;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void render(@NotNull CoffinBlockEntity blockEntity, float partialTick, @N

BlockState blockState = blockEntity.getBlockState();
DoubleBlockCombiner.NeighborCombineResult<? extends CoffinBlockEntity> neighborCombineResult = DoubleBlockCombiner.combineWithNeigbour(
TTBlockEntities.COFFIN,
TTBlockEntityTypes.COFFIN,
CoffinBlock::getBlockType,
CoffinBlock::getConnectedDirection,
CoffinBlock.FACING,
Expand Down
Loading

0 comments on commit 9648688

Please sign in to comment.