Skip to content

Commit

Permalink
warding & vigil candles
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 30, 2024
1 parent 1241ad5 commit 48f7987
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ public static void clientTick(TickEvent.ClientTickEvent event) {
var below = level.getBlockState(blockAt.below());

if (below.getFluidState().is(FluidTags.WATER)) {
addFogGroup(level, OParticleTypes.FOG_WATER.get(), at, 3, 0);
addFogGroup(level, OParticleTypes.FOG_WATER.get(), blockAt, 3, 0);
} else if (!below.canBeReplaced()) {
addFogGroup(level, OParticleTypes.FOG.get(), at, 5, 1);
addFogGroup(level, OParticleTypes.FOG.get(), blockAt, 5, 1);
}
}

private static void addFogGroup(Level level, ParticleOptions type, Vec3 at, int amount, double yRange) {
private static void addFogGroup(Level level, ParticleOptions type, BlockPos at, int amount, double yRange) {
if(level.random.nextInt(amount * 2) != 0) return;

var realAmount = amount - level.random.nextInt(2);

for (int i = 0; i < realAmount; i++) {
level.addParticle(type,
at.x + level.random.nextDouble() * 2 - 1, at.y + 0.5 + level.random.nextDouble() * yRange, at.z + level.random.nextDouble() * 2 - 1,
at.getX() + level.random.nextDouble() * 2 - 1, at.getY() + 0.5 + level.random.nextDouble() * yRange, at.getZ() + level.random.nextDouble() * 2 - 1,
level.random.nextFloat() + 0.5F, 0.0, 0.0
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static VoxelShape[] createShapes(boolean hanging) {
private static final VoxelShape[] SHAPES = createShapes(false);
private static final VoxelShape[] HANGING_SHAPES = createShapes(true);

public static final ToIntFunction<BlockState> LIGHT_EMISSION = state -> state.getValue(LIT) ? 6 * state.getValue(CANDLES) : 0;
public static final ToIntFunction<BlockState> LIGHT_EMISSION = state -> state.getValue(LIT) ? 4 * state.getValue(CANDLES) : 0;

public VigilCandleBlock(Properties properties) {
super(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;

import java.util.function.Supplier;

public class FogEffect extends MobEffect {

public FogEffect() {
super(MobEffectCategory.NEUTRAL, 2696993);
super(MobEffectCategory.HARMFUL, 2696993);
this.setFactorDataFactory(() -> new MobEffectInstance.FactorData(22));
}

@Override
public void applyEffectTick(LivingEntity entity, int amplifier) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package galena.doom_and_gloom.content.effect;

import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;

public class WardingEffect extends MobEffect {

public WardingEffect() {
super(MobEffectCategory.BENEFICIAL, 0xc9bd93);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void tick() {
if(tickCount % 10 != 0) return;

if (!level.getBlockState(pos).isAir() || !level.getBlockState(pos.below()).is(OTags.Blocks.CAN_TURN_INTO_BURIAL_DIRT)) {
spawnMonster(level, pos);
discard();
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package galena.doom_and_gloom.content.entity;

import galena.doom_and_gloom.index.OBlockEntities;
import galena.doom_and_gloom.index.OEffects;
import galena.doom_and_gloom.index.OTags;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.CandleBlock;
Expand Down Expand Up @@ -32,6 +34,11 @@ public void tick(BlockState state, Level level, BlockPos pos) {
shouldClear.forEach(effect -> {
entity.removeEffect(effect.get());
});

var duration = 20 * 5;
if (!entity.hasEffect(OEffects.WARDING.get()) || entity.getEffect(OEffects.WARDING.get()).endsWithin(duration - 1)) {
entity.addEffect(new MobEffectInstance(OEffects.WARDING.get(), duration, 0, false, false, false));
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffectUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
Expand Down Expand Up @@ -46,7 +45,6 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import javax.annotation.Nullable;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.util.List;
Expand Down Expand Up @@ -87,7 +85,7 @@ protected void registerGoals() {
goalSelector.addGoal(4, new LookAtPlayerGoal(this, Player.class, 16.0F));
goalSelector.addGoal(9, new HollerStrollGoal(this, 1F));

targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, false));
targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, false, it -> !it.hasEffect(OEffects.WARDING.get())));
}

@Override
Expand All @@ -103,10 +101,18 @@ protected void customServerAiStep() {
}
}

public static void applyFogAround(ServerLevel level, Vec3 pos, @Nullable Entity source, int radius) {
MobEffectInstance mobeffectinstance = new MobEffectInstance(OEffects.FOG.get(), 260, 0, false, false);
var applied = MobEffectUtil.addEffectToPlayersAround(level, source, pos, radius, mobeffectinstance, 20 * 60 * 4);
public static void applyFogAround(ServerLevel level, Vec3 pos, Entity source, int radius) {
var duration = 20 * 60 * 4;

var applied = level.getPlayers(player ->
player.gameMode.isSurvival()
&& pos.closerThan(player.position(), radius)
&& (!player.hasEffect(OEffects.FOG.get()) || player.getEffect(OEffects.FOG.get()).endsWithin(duration - 1))
&& !player.hasEffect(OEffects.WARDING.get())
);

applied.forEach(it -> {
it.addEffect(new MobEffectInstance(OEffects.FOG.get(), 260, 0, false, false), source);
level.playSound(it, source, OSoundEvents.HOLLER_SHRIEKS.get(), source.getSoundSource(), 1F, 1F);
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/galena/doom_and_gloom/data/OLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ protected void addTranslations() {
addBlock(OBlocks.BONE_PILE, "Pile of Bones");

addEffect(OEffects.FOG, "Fog");
addEffect(OEffects.WARDING, "Warding");

// JEED compat
add("effect.doom_and_gloom.fog.description", "An eerie fog that accompanies the holler");
add("effect.doom_and_gloom.warding.description", "Wards against evil spirits");

addSubtitle("block", "sepulcher.unsealing", "Sepulcher opened");
addSubtitle("block", "sepulcher.sealing", "Sepulcher sealed");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/galena/doom_and_gloom/index/OBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class OBlocks {
public static final RegistryObject<Block> ROTTING_FLESH = HELPER.createBlock("rotting_flesh", () -> new Block(BlockBehaviour.Properties.copy(Blocks.DIRT)));
public static final RegistryObject<Block> STONE_TABLET = register("stone_tablet", () -> new StoneTabletBlock(BlockBehaviour.Properties.copy(Blocks.STONE)));

private static final Supplier<BlockBehaviour.Properties> VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().lightLevel(VigilCandleBlock.LIGHT_EMISSION).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY);
private static final Supplier<BlockBehaviour.Properties> VIGIL_CANDLE_PROPERTIES = () -> BlockBehaviour.Properties.of().noOcclusion().lightLevel(VigilCandleBlock.LIGHT_EMISSION).sound(SoundType.METAL).pushReaction(PushReaction.DESTROY);
public static final RegistryObject<Block> VIGIL_CANDLE = register("vigil_candle", () -> new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get()));
public static final Map<DyeColor, RegistryObject<Block>> COLORED_VIGIL_CANDLES = registerColored("vigil_candle", color -> new VigilCandleBlock(VIGIL_CANDLE_PROPERTIES.get().mapColor(color)));

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/galena/doom_and_gloom/index/OEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import galena.doom_and_gloom.DoomAndGloom;
import galena.doom_and_gloom.content.effect.FogEffect;
import galena.doom_and_gloom.content.effect.WardingEffect;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
Expand All @@ -12,5 +14,6 @@ public class OEffects {
public static final DeferredRegister<MobEffect> EFFECTS = DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, DoomAndGloom.MOD_ID);

public static final RegistryObject<MobEffect> FOG = EFFECTS.register("fog", FogEffect::new);
public static final RegistryObject<MobEffect> WARDING = EFFECTS.register("warding", WardingEffect::new);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"values": [
"doom_and_gloom:sepulcher"
"doom_and_gloom:gravetender"
]
}

0 comments on commit 48f7987

Please sign in to comment.