Skip to content

Commit

Permalink
added a basic tutorial when entering darkness
Browse files Browse the repository at this point in the history
changed callback methods to be more straightforward
added a respawn callback for a whisp feature to protect you from grues after respawning
  • Loading branch information
lever1209 committed Jan 27, 2024
1 parent abc2151 commit 2ecaecb
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 81 deletions.
9 changes: 1 addition & 8 deletions NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

add button on worlds menu to recalculate all blocks lighting, potentially dangerous with non vanilla, so throw up a warning, this "solves" the lighting artifacts when changing lighting values without needing too much cpu power in game, should only be used when editing these values or when converting world to pandora since all lighting values are cached
create a utility to load all chunks within a world, update all block luminance values with the ones stored in configs

persistent states to store grue interactions with a player

awaiting testing: the world is dark enough that lava can probably be dimmed without issue

low torch light makes indoor farms harder to do early game, i feel this side effect should be left as is, or made into a config
Expand All @@ -25,18 +24,12 @@ render a grue face just out of lantern light range staring at the camera, with t

option to use entity vs nothing per dimension in config

"tutorial" message first time player gets "Its pitch black, you are likely to be eaten by a grue." then cooldown, and 50% every time you enter darkness, until you get it, then cooldown then chance reduces to 15%, until message has appeared 10 times, then disable message

setup gamerules for select config options

fade light level

particle eyeball monster that lurks in the darkness, multiple floating eye segments? eye stalks?

fix readme, that last line is kinda cringe

add button on worlds menu to recalculate all blocks lighting, potentially dangerous with non vanilla, so throw up a warning, this "solves" the lighting artifacts when changing lighting values without needing too much cpu power in game, should only be used when editing these values or when converting world to pandora since all lighting values are cached

spawn a light generating whisp when respawning, it lasts 2 minutes and follows the player, or until the player enters the light

so, i just make a block entity, make it extend the block its replacing, and
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![build](https://github.com/lever1209/pandora-core/actions/workflows/build.yml/badge.svg?branch=development-1.19.x)](https://github.com/lever1209/pandora-core/actions/workflows/build.yml)

Imagine a world where you are at the bottom of the food chain.
The only thing you know about them is they dont like being seen.
12 changes: 7 additions & 5 deletions src/main/java/pkg/deepCurse/pandora/core/Pandora.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import com.llamalad7.mixinextras.MixinExtrasBootstrap;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;
import net.minecraft.block.Block;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import pkg.deepCurse.pandora.core.util.callbacks.EndServerTickCallback;
import pkg.deepCurse.pandora.core.util.callbacks.AfterServerPlayerRespawnCallback;
import pkg.deepCurse.pandora.core.util.callbacks.EndServerWorldTickCallback;
import pkg.deepCurse.pandora.core.util.tools.PandoraTools;

public class Pandora implements ModInitializer, PreLaunchEntrypoint {
Expand Down Expand Up @@ -46,10 +48,10 @@ public void onInitialize() {
}

public static void registerHooks() {
ServerTickEvents.END_WORLD_TICK.register((world) -> {
// try catch throwable this?
EndServerTickCallback.run(world);
});
ServerTickEvents.END_WORLD_TICK.register(new EndServerWorldTickCallback());

ServerPlayerEvents.AFTER_RESPAWN.register(new AfterServerPlayerRespawnCallback());

for (Entry<RegistryKey<Block>, Block> entry : Registry.BLOCK.getEntrySet()) {
PandoraTools.overrideLuminance(entry.getKey().getValue(), entry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@
import net.minecraft.nbt.NbtElement;
import pkg.deepCurse.pandora.core.util.interfaces.PlayerGrueDataInterface;

//import net.minecraft.nbt.NbtCompound;
//import net.minecraft.world.PersistentState;

@Mixin(PlayerEntity.class)
public class PlayerEntityMixin implements PlayerGrueDataInterface {

private long lastEncounterTime; // PandoraGrueLastEncounterTime
private short trainingWheelEncountersLeft; // PandoraGrueTrainingWheelEncountersLeft
private long lastTutorialEncounterTime; // PandoraGrueLastTutorialEncounterTime
private short tutorialEncountersLeft; // PandoraGrueTutorialEncountersLeft

@Override
public short getTrainingWheelEncountersLeft() {
return trainingWheelEncountersLeft;
public short getTutorialEncountersLeft() {
return tutorialEncountersLeft;
}

@Override
public void setTrainingWheelEncountersLeft(short trainingWheelEncountersLeft) {
this.trainingWheelEncountersLeft = trainingWheelEncountersLeft;
public void setTutorialEncountersLeft(short tutorialEncountersLeft) {
this.tutorialEncountersLeft = tutorialEncountersLeft;
}

@Override
public long getLastEncounterTime() {
return lastEncounterTime;
public long getLastTutorialEncounterTime() {
return lastTutorialEncounterTime;
}

@Override
public void setLastEncounterTime(long lastEncounterTime) {
this.lastEncounterTime = lastEncounterTime;
public void setLastTutorialEncounterTime(long lastTutorialEncounterTime) {
this.lastTutorialEncounterTime = lastTutorialEncounterTime;
}

@Inject(method = "readCustomDataFromNbt", at = @At(value = "RETURN"))
public void pandora_readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) {
this.trainingWheelEncountersLeft = nbt.contains("PandoraGrueTrainingWheelEncountersLeft", NbtElement.SHORT_TYPE)
? 7
/* TODO config this */ : nbt.getShort("PandoraGrueTrainingWheelEncountersLeft");
this.lastEncounterTime = nbt.contains("PandoraGrueLastEncounterTime", NbtElement.LONG_TYPE) ? 0
/* TODO config this */ : nbt.getLong("PandoraGrueLastEncounterTime");
// Pandora.log.info("READING {}", nbt);
this.tutorialEncountersLeft = nbt.contains("PandoraGrueTutorialEncountersLeft", NbtElement.SHORT_TYPE)
? nbt.getShort("PandoraGrueTutorialEncountersLeft")
: 7 /* TODO config this */ ;
this.lastTutorialEncounterTime = nbt.contains("PandoraGrueLastTutorialEncounterTime", NbtElement.LONG_TYPE)
? nbt.getLong("PandoraGrueLastTutorialEncounterTime")
: 0 /* TODO config this */ ;
}

@Inject(method = "writeCustomDataToNbt", at = @At(value = "RETURN"))
public void pandora_writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) {
nbt.putShort("PandoraGrueTrainingWheelEncountersLeft", trainingWheelEncountersLeft);
nbt.putLong("PandoraGrueLastEncounterTime", lastEncounterTime);
nbt.putShort("PandoraGrueTutorialEncountersLeft", tutorialEncountersLeft);
nbt.putLong("PandoraGrueLastTutorialEncounterTime", lastTutorialEncounterTime);
// Pandora.log.info("WRITING {}", nbt);
}
}
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pkg.deepCurse.pandora.core.util.callbacks;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents.AfterRespawn;
import net.minecraft.server.network.ServerPlayerEntity;

public class AfterServerPlayerRespawnCallback implements AfterRespawn {

private static Logger log = LoggerFactory.getLogger(AfterServerPlayerRespawnCallback.class);

@Override
public void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
log.info("{} {} {}", oldPlayer,newPlayer,alive);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.EndWorldTick;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import pkg.deepCurse.pandora.core.GrueDamageSource;
Expand All @@ -23,52 +25,12 @@
import pkg.deepCurse.pandora.core.util.managers.EntityCooldownManager;
import pkg.deepCurse.pandora.core.util.tools.PandoraTools;

public class EndServerTickCallback {
public class EndServerWorldTickCallback implements EndWorldTick {

private static Logger log = LoggerFactory.getLogger(EndServerTickCallback.class);
private static Logger log = LoggerFactory.getLogger(EndServerWorldTickCallback.class);

private static HashMap<ServerWorld, EntityCooldownManager> dimensionalCooldownManagerHashMap = new HashMap<>();

public static void run(ServerWorld world) {
var dimensionalCooldownManager = dimensionalCooldownManagerHashMap.get(world);

if (dimensionalCooldownManager == null) {
dimensionalCooldownManagerHashMap.put(world, new EntityCooldownManager());
return;
}

Iterator<Entity> entities = world.iterateEntities().iterator();
while (entities.hasNext()) {
Entity entity = entities.next();

if (shouldDoDamage(entity, world)) {
if (!dimensionalCooldownManager.isCoolingDown(entity)) {
var rand = PandoraConfig.Debug.GrueMaximumTickWait - Debug.GrueMinimumTickWait;

var wait = (rand == 0 ? 0 : world.getRandom().nextInt(rand))
+ PandoraConfig.Debug.GrueMinimumTickWait;

if (entity instanceof PlayerEntity) {
PlayerGrueDataInterface player = (PlayerGrueDataInterface) (PlayerEntity) entity;
log.info("{}, {}, {}", player.getLastEncounterTime(),
player.getTrainingWheelEncountersLeft());



}
doDarknessDamage(entity, 0.0F, world);
// dimensionalCooldownManager.remove(entity);
dimensionalCooldownManager.set(entity, wait);
}

dimensionalCooldownManager.update(entity);
}
// if (entity instanceof PlayerEntity) {
// log.info("{}", dimensionalCooldownManager.getCooldownProgress(entity, 0));
// }
}
}

private static boolean shouldDoDamage(Entity entity, ServerWorld world) {
if (!(entity instanceof LivingEntity)) {
return false;
Expand Down Expand Up @@ -192,4 +154,63 @@ private static void doDarknessDamage(Entity entity, float damageAmount, ServerWo
entity.damage(GrueDamageSource.GRUE, damageAmount); // TODO glow squids
}
}

@Override
public void onEndTick(ServerWorld world) {
var dimensionalCooldownManager = dimensionalCooldownManagerHashMap.get(world);

if (dimensionalCooldownManager == null) {
dimensionalCooldownManagerHashMap.put(world, new EntityCooldownManager());
return;
}

Iterator<Entity> entities = world.iterateEntities().iterator();
while (entities.hasNext()) {
Entity entity = entities.next();

if (shouldDoDamage(entity, world)) {
if (!dimensionalCooldownManager.isCoolingDown(entity)) {
var rand = PandoraConfig.Debug.GrueMaximumTickWait - Debug.GrueMinimumTickWait;

var wait = (rand == 0 ? 0 : world.getRandom().nextInt(rand))
+ PandoraConfig.Debug.GrueMinimumTickWait;

boolean tutorial = false;

if (entity instanceof PlayerEntity) {
var playerEntity = (PlayerEntity) entity;
PlayerGrueDataInterface playerDataInterface = (PlayerGrueDataInterface) playerEntity;

// playerDataInterface.setTutorialEncountersLeft((short) 7);
// playerDataInterface.setLastTutorialEncounterTime(0l);

log.info("{}, {}, {}", playerDataInterface.getLastTutorialEncounterTime(),
playerDataInterface.getTutorialEncountersLeft());

if (playerDataInterface.getTutorialEncountersLeft() > 0
&& playerDataInterface.getLastTutorialEncounterTime() + 24000 /* a day */ < world
.getTime()) { // TODO gamerule for grue tutorials
tutorial = true;
playerDataInterface.setTutorialEncountersLeft(
(short) (playerDataInterface.getTutorialEncountersLeft() - 1));
playerDataInterface.setLastTutorialEncounterTime(world.getTime());
playerEntity.sendMessage(Text.translatable("pandora.grue.tutorial"));
dimensionalCooldownManager.set(entity, wait + 200/* TODO make this configurable */);
}

}
if (!tutorial) {
doDarknessDamage(entity, 0.0F, world);
dimensionalCooldownManager.set(entity, wait);
}

}

dimensionalCooldownManager.update(entity);
}
// if (entity instanceof PlayerEntity) {
// log.info("{}", dimensionalCooldownManager.getCooldownProgress(entity, 0));
// }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package pkg.deepCurse.pandora.core.util.interfaces;

public interface PlayerGrueDataInterface {
short getTrainingWheelEncountersLeft();
short getTutorialEncountersLeft();

void setTrainingWheelEncountersLeft(short trainingWheelEncountersLeft);
void setTutorialEncountersLeft(short tutorialEncountersLeft);

long getLastEncounterTime();
long getLastTutorialEncounterTime();

void setLastEncounterTime(long lastEncounterTime);
void setLastTutorialEncounterTime(long lastTutorialEncounterTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class EntityCooldownManager {
private final Map<Entity, Entry> entries = Maps.newHashMap();

public boolean isCoolingDown(Entity entity) {
return this.getCooldownProgress(entity, 0.0f) > 0.0f;
return this.entries.containsKey(entity);
}

public float getCooldownProgress(Entity entity, float f) { // TODO use this for a screen effect when winding down to
Expand Down

0 comments on commit 2ecaecb

Please sign in to comment.