Skip to content

Commit

Permalink
broken commit for review and testing, ducking doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
lever1209 committed Jan 26, 2024
1 parent 9a9da08 commit 9e62c57
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 98 deletions.
6 changes: 6 additions & 0 deletions NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

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

hip lantern?

Expand Down
28 changes: 16 additions & 12 deletions src/main/java/pkg/deepCurse/pandora/core/Pandora.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package pkg.deepCurse.pandora.core;

import java.util.Map.*;
import java.util.Map.Entry;

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

import com.llamalad7.mixinextras.*;
import com.llamalad7.mixinextras.MixinExtrasBootstrap;

import net.fabricmc.api.*;
import net.fabricmc.fabric.api.event.lifecycle.v1.*;
import net.fabricmc.fabric.api.event.registry.*;
import net.fabricmc.loader.api.entrypoint.*;
import net.minecraft.block.*;
import net.minecraft.util.registry.*;
import pkg.deepCurse.pandora.core.util.callbacks.*;
import pkg.deepCurse.pandora.core.util.tools.*;
import net.fabricmc.api.ModInitializer;
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.tools.PandoraTools;

public class Pandora implements ModInitializer, PreLaunchEntrypoint {

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

@Override
public void onPreLaunch() {
Expand Down Expand Up @@ -45,6 +47,7 @@ public void onInitialize() {

public static void registerHooks() {
ServerTickEvents.END_WORLD_TICK.register((world) -> {
// try catch throwable this?
EndServerTickCallback.run(world);
});
for (Entry<RegistryKey<Block>, Block> entry : Registry.BLOCK.getEntrySet()) {
Expand All @@ -53,6 +56,7 @@ public static void registerHooks() {
RegistryEntryAddedCallback.event(Registry.BLOCK).register((rawId, id, block) -> {
PandoraTools.overrideLuminance(id, block);
});

}

}
3 changes: 2 additions & 1 deletion src/main/java/pkg/deepCurse/pandora/core/PandoraConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.snakeyaml.engine.v2.api.Load;
Expand Down Expand Up @@ -114,7 +115,7 @@ public static File getConfigFile() {
public static void loadConfig() { // TODO write yaml parser to get spans and line numbers, and to add more user
// friendly errors

log.info("start");
// log.info("start");

General.DimensionSettings = new HashMap<>();
General.MobSettings = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package pkg.deepCurse.pandora.core.items;

import java.util.*;

import org.slf4j.*;

import com.mojang.brigadier.exceptions.*;

import net.minecraft.block.*;
import net.minecraft.entity.player.*;
import net.minecraft.item.*;
import net.minecraft.nbt.*;
import net.minecraft.network.message.*;
import net.minecraft.server.network.*;
import net.minecraft.state.property.*;
import net.minecraft.text.*;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.world.*;
import java.util.Collection;

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

import com.mojang.brigadier.exceptions.CommandSyntaxException;

import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.network.message.MessageType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.property.Property;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;

public class PandoraDebugStickItem extends Item {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

package pkg.deepCurse.pandora.core.mixins.client;

import org.slf4j.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.*;

import net.minecraft.client.texture.*;
import pkg.deepCurse.pandora.core.util.interfaces.*;
import pkg.deepCurse.pandora.core.util.tools.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import pkg.deepCurse.pandora.core.util.interfaces.TextureAccess;
import pkg.deepCurse.pandora.core.util.tools.DarknessTools;

@Mixin(NativeImageBackedTexture.class)
public class NativeImageBackedTextureMixin implements TextureAccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ai.goal.GoalSelector;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import pkg.deepCurse.pandora.core.PandoraConfig;
import pkg.deepCurse.pandora.core.util.ai.goals.EscapeGrueGoal;

@Mixin(MobEntity.class) // TODO modify all wander goals to prioritize light over dark, but not to make it a requirement
@Mixin(MobEntity.class) // TODO modify all wander goals to prioritize light over dark, but not to make
// it a requirement
public class MobEntityMixin {

@SuppressWarnings("unused")
Expand All @@ -30,8 +30,13 @@ public class MobEntityMixin {
@Shadow
private BlockPos positionTarget;

@Inject(method = "<init>*", at = @At(value = "RETURN")) // TODO fix this, using the constructor does not guarantee the goal will stay if a custom entity clears its goals
private void pandora_constructorReturn(EntityType<? extends MobEntity> entityType, World world, CallbackInfo ci) { // portal to SheepEntity and VillagerEntity
@Inject(method = "<init>*", at = @At(value = "RETURN")) // TODO fix this, using the constructor does not guarantee
// the goal will stay if a custom entity clears its goals
private void pandora_constructorReturn(EntityType<? extends MobEntity> entityType, World world, CallbackInfo ci) { // portal
// to
// SheepEntity
// and
// VillagerEntity
MobEntity self = (MobEntity) (Object) this;
// TODO give a slight regen effect when near light?
var type = self.getType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package pkg.deepCurse.pandora.core.mixins.shared;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.mojang.authlib.GameProfile;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.network.encryption.PlayerPublicKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import pkg.deepCurse.pandora.core.util.interfaces.PlayerGrueDataInterface;

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

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends PlayerEntity implements PlayerGrueDataInterface {
public PlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile, PlayerPublicKey publicKey) {
super(world, pos, yaw, gameProfile, publicKey);
}

private long lastEncounterTime; // PandoraGrueLastEncounterTime
private short trainingWheelEncountersLeft; // PandoraGrueTrainingWheelEncountersLeft

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

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

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

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

@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");
}

@Inject(method = "writeCustomDataToNbt", at = @At(value = "RETURN"))
public void pandora_writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) {
nbt.putShort("PandoraGrueTrainingWheelEncountersLeft", trainingWheelEncountersLeft);
nbt.putLong("PandoraGrueLastEncounterTime", lastEncounterTime);
}
}
/*
*
*/
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import org.slf4j.LoggerFactory;

import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package pkg.deepCurse.pandora.core.util.callbacks;

import java.util.*;

import org.slf4j.*;

import net.minecraft.entity.*;
import net.minecraft.entity.effect.*;
import net.minecraft.entity.player.*;
import net.minecraft.item.*;
import net.minecraft.server.world.*;
import net.minecraft.util.math.*;
import java.util.HashMap;
import java.util.Iterator;

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

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.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import pkg.deepCurse.pandora.core.*;
import pkg.deepCurse.pandora.core.GrueDamageSource;
import pkg.deepCurse.pandora.core.PandoraConfig;
import pkg.deepCurse.pandora.core.PandoraConfig.Debug;
import pkg.deepCurse.pandora.core.PandoraConfig.General;
import pkg.deepCurse.pandora.core.util.managers.*;
import pkg.deepCurse.pandora.core.util.tools.*;
import pkg.deepCurse.pandora.core.util.interfaces.PlayerGrueDataInterface;
import pkg.deepCurse.pandora.core.util.managers.EntityCooldownManager;
import pkg.deepCurse.pandora.core.util.tools.PandoraTools;

public class EndServerTickCallback {

Expand All @@ -37,14 +43,16 @@ public static void run(ServerWorld world) {

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) {
log.info("{} in {} for {}", entity.getEntityName(), entity.getWorld().getDimensionKey(), ((float) wait) / 20f);
PlayerEntity player = (PlayerEntity) entity;
log.info("{}, {}", ((PlayerGrueDataInterface) player).getLastEncounterTime(),
((PlayerGrueDataInterface) player).getTrainingWheelEncountersLeft());
// log.info("{} in {} for {}", entity.getEntityName(), entity.getWorld().getDimensionKey(), ((float) wait) / 20f);
}
doDarknessDamage(entity, 0.0F, world);
dimensionalCooldownManager.set(entity, wait);
Expand Down Expand Up @@ -96,12 +104,33 @@ private static boolean shouldDoDamage(Entity entity, ServerWorld world) {
return false;
}

boolean blockFound = false;
for (BlockPos location : new BlockPos[] { entityLocation.north().east(), entityLocation.north(),
entityLocation.north().west(), entityLocation.east(), entityLocation, entityLocation.west(),
entityLocation.south().east(), entityLocation.south(), entityLocation.south().west(), }) {
for (short i = 5 /* TODO config value "height immunity" or something */; --i > 0;) {
location = location.down();
if (!world.getBlockState(location).isAir()) {
blockFound = true;
break;
}
}
if (blockFound)
break;
}

if (!blockFound) {
// dont deal damage
return false;
}

// deal damage
return true;
}

private static void doDarknessDamage(Entity entity, float damageAmount, ServerWorld world) {
if (damageAmount <= 0.0F) {
switch (world.getDifficulty()) {
switch (world.getDifficulty()) { // TODO add difficulty settings to the config
case HARD:
damageAmount = 8.0F;
break;
Expand Down Expand Up @@ -154,7 +183,7 @@ private static void doDarknessDamage(Entity entity, float damageAmount, ServerWo

if (world.getServer().isHardcore()
&& (PandoraConfig.General.HardcoreAffectsOtherMobs || entity instanceof PlayerEntity))
damageAmount = Float.MAX_VALUE;
damageAmount = Float.MAX_VALUE; // TODO make this configurable

if (world.random.nextFloat() > wardPotency && damageAmount != 0f) {
entity.damage(GrueDamageSource.GRUE, damageAmount); // TODO glow squids
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pkg.deepCurse.pandora.core.util.interfaces;

public interface PlayerGrueDataInterface {
short getTrainingWheelEncountersLeft();

void setTrainingWheelEncountersLeft(short trainingWheelEncountersLeft);

long getLastEncounterTime();

void setLastEncounterTime(long lastEncounterTime);
}
Loading

1 comment on commit 9e62c57

@lever1209
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ducking in the commit name is not meant to be crass, its referring to duck interfaces

Please sign in to comment.