Skip to content

Commit

Permalink
Port 3.2.0 to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ginsm committed Jul 3, 2023
1 parent bd55699 commit 9d3c5ff
Show file tree
Hide file tree
Showing 35 changed files with 530 additions and 403 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ name: Publish on Curseforge & Modrinth
on: [ workflow_dispatch ]

env:
MINECRAFT_VERSION: 1.20.1
JAVA_VERSION: 17
VERSION: 1.20.1-3.1.0
RELEASE_NAME: Forgotten Graves 1.20.1-3.1.0
VERSION: 1.20.1-3.2.0
RELEASE_NAME: Forgotten Graves 1.20.1-3.2.0
MODRINTH_TOKEN: ${{ secrets.PUBLISH_MODRINTH_TOKEN }}
CURSEFORGE_TOKEN: ${{ secrets.PUBLISH_CURSEFORGE_TOKEN }}

Expand Down Expand Up @@ -55,5 +54,4 @@ jobs:
changelog-file: CHANGELOG.md

loaders: fabric
game-versions: "${{env.MINECRAFT_VERSION}}"
java: "${{env.JAVA_VERSION}}"
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## 1.20.1-3.1.0
## 1.20.1-3.2.0

**Updated**
### IMPORTANT
This update largely revolves around sprucing up the config. As such, it would be a good idea to reconfigure the mod (especially for servers).

- Forgotten Graves has been updated to 1.20.1 (v3.1.0).
### Added
- New experience settings, see [here](https://github.com/ginsm/forgotten-graves/wiki/Config#experience-settings).
- New `decayEnabled` option. Allows you to toggle natural decay.
- New `decayRobbing` option. Allows you to set which stage of decay the graves need to be at before they can be robbed via `graveRobbing`.
- New `shiftSwapsDropType` option (default `true`). Allows you to briefly switch between `DROP` and `EQUIP` by sneaking whilst retrieving graves.

### Updated
- Floating settings have been renamed to sink settings; i.e. `floatInWater` is now `sinkInWater`.
- `decayModifier` now defaults to `60`.
- `dropType`'s `INVENTORY` value has been renamed to `EQUIP`.
- Chat messages should now be formatted consistently.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version=0.14.21
fabric_version=0.83.1+1.20.1

# Mod Properties
mod_version=1.20.1-3.1.0
mod_version=1.20.1-3.2.0
maven_group=me.mgin
archives_base_name=forgottengraves

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/mgin/graves/Graves.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.mgin.graves.api.InventoriesApi;
import me.mgin.graves.block.GraveBlocks;
import me.mgin.graves.command.Commands;
import me.mgin.graves.config.ConfigOptions;
import me.mgin.graves.config.GravesConfig;
import me.mgin.graves.event.Events;
import me.mgin.graves.inventory.BackSlot;
Expand All @@ -19,9 +20,7 @@
import net.fabricmc.loader.api.FabricLoader;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.*;

public class Graves implements ModInitializer {

Expand All @@ -35,6 +34,7 @@ public class Graves implements ModInitializer {
public void onInitialize() {
// Register Config
AutoConfig.register(GravesConfig.class, GsonConfigSerializer::new);
ConfigOptions.generateConfigOptions();

// Graves Registry
GraveBlocks.registerServerBlocks(MOD_ID, BRAND_BLOCK);
Expand All @@ -55,7 +55,7 @@ public void onInitialize() {

public void addInventory(String modID, Class<? extends InventoriesApi> modInventory) {
try {
if (modID.equals("vanilla") || FabricLoader.getInstance().isModLoaded(modID) && modInventory != null)
if (modID.equals("vanilla") || FabricLoader.getInstance().isModLoaded(modID))
inventories.add(modInventory.getDeclaredConstructor().newInstance());
else
unloadedInventories.add(modID);
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/me/mgin/graves/block/decay/Decayable.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.mgin.graves.block.decay;

import com.mojang.authlib.GameProfile;

import java.util.Optional;

import me.mgin.graves.Graves;
import me.mgin.graves.api.InventoriesApi;
import me.mgin.graves.block.entity.GraveBlockEntity;
Expand All @@ -19,15 +16,21 @@
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;

import java.util.Optional;

public interface Decayable<T extends Enum<T>> {
Optional<BlockState> getDecayResultState(BlockState state);

float getDecayChanceMultiplier();

default void tickDecay(BlockState state, ServerWorld world, BlockPos pos, Random random) {
float f = 0.05688889F;
if (random.nextFloat() < f) {
this.tryDecay(state, world, pos, random);
GravesConfig config = GravesConfig.getConfig();

if (config.decay.decayEnabled) {
float f = 0.05688889F;
if (random.nextFloat() < f) {
this.tryDecay(state, world, pos, random);
}
}
}

Expand All @@ -40,10 +43,12 @@ default void tryDecay(BlockState state, ServerWorld world, BlockPos pos, Random
}

static DefaultedList<ItemStack> decayItems(DefaultedList<ItemStack> items, GameProfile profile) {
float decayModifier = GravesConfig.resolveConfig("decayModifier", profile).itemDecay.decayModifier / 100f;
boolean decayBreaksItems = GravesConfig.resolveConfig("decayBreaksItems", profile).itemDecay.decayBreaksItems;
GravesConfig config = GravesConfig.getConfig();

float modifier = config.decay.decayModifier / 100f;
boolean decayBreaksItems = config.decay.decayBreaksItems;

if (decayModifier == 0.0f)
if (modifier == 0.0f)
return items;

for (int i = 0; i < items.size(); i++) {
Expand All @@ -62,7 +67,7 @@ static DefaultedList<ItemStack> decayItems(DefaultedList<ItemStack> items, GameP
currentItemDecay = 1f / (float) maxDamage;
}

float decayPercent = decayModifier * currentItemDecay;
float decayPercent = modifier * currentItemDecay;
float unbreakingModifier = ((100f / (unbreaking + 1f)) / 100f);
float decayChance = 0.35f * unbreakingModifier;

Expand Down
89 changes: 62 additions & 27 deletions src/main/java/me/mgin/graves/block/utility/Experience.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,60 @@
package me.mgin.graves.block.utility;

import com.mojang.authlib.GameProfile;

import me.mgin.graves.config.enums.GraveExpStoreType;
import me.mgin.graves.config.GravesConfig;
import me.mgin.graves.config.enums.GraveExpStoreType;
import me.mgin.graves.config.enums.ExperienceType;
import net.minecraft.entity.player.PlayerEntity;

public class Experience {
public static int calculatePlayerExperience(PlayerEntity player) {
int level = player.experienceLevel;
float progress = player.experienceProgress;
GameProfile profile = player.getGameProfile();
float progress = player.experienceProgress;
int level = player.experienceLevel;

GraveExpStoreType expStorageType = GravesConfig.resolveConfig("expStorageType", profile).main.expStorageType;
int maxCustomXPLevel = GravesConfig.resolveConfig("maxCustomXPLevel", profile).main.maxCustomXPLevel;
// Config settings
GraveExpStoreType storageType = GravesConfig.resolve("expStorageType", profile);
ExperienceType percentageType = GravesConfig.resolve("percentageType", profile);
ExperienceType capType = GravesConfig.resolve("capType", profile);
int cap = GravesConfig.resolve("cap", profile);
int percentage = GravesConfig.resolve("percentage", profile);

switch (expStorageType) {
case ALL -> {
return calculateTotalExperience(level, progress);


// Determine experience points based on configured type
float percentageModifier = ((float) percentage / 100);
int experience;

if (percentageType == ExperienceType.LEVELS) {
float levelAndProgress = (level + progress) * percentageModifier;
level = (int) levelAndProgress;
progress = levelAndProgress % 1;
}

switch (storageType) {
case VANILLA -> {
experience = calculateVanillaExperience(level);
}
case CUSTOM -> {
// Enforce a minimum threshold (0).
int maxLevel = Math.max(maxCustomXPLevel, 0);
return calculateTotalExperience(
Math.min(level, maxLevel),
maxLevel > level ? progress : 0
);
case ALL -> {
experience = calculateTotalExperience(level, progress);
}
default -> {
return calculateDefaultExperience(level);
experience = 0;
}
}

// Adjust experience based on set percentage
if (percentageType == ExperienceType.POINTS) experience = Math.round(experience * percentageModifier);

// Return amount, enforcing level cap.
int capValue = capType == ExperienceType.LEVELS ? calculateLevelExperience(cap) : cap;
return cap > -1 ? Math.min(capValue, experience) : experience;
}

// This leverages the default death experience equation found here:
// https://minecraft.fandom.com/wiki/Experience#Sources
public static int calculateVanillaExperience(int level) {
return 7 * level;
}

public static int calculateTotalExperience(int level, float progress) {
Expand All @@ -39,14 +63,14 @@ public static int calculateTotalExperience(int level, float progress) {
return levelExperience + progressExperience;
}

// This leverages the default death experience equation found here:
// https://minecraft.fandom.com/wiki/Experience#Sources
public static int calculateDefaultExperience(int level) {
return Math.min(7 * level, 100);
}

// This leverages the "total experience" equations found here:
// https://minecraft.fandom.com/wiki/Experience#Leveling_up

/**
* Calculates how many points
* @param level int
* @return int
*/
private static int calculateLevelExperience(int level) {
int levelSquared = level * level;
int levelExperience = 0;
Expand All @@ -61,8 +85,16 @@ private static int calculateLevelExperience(int level) {
return levelExperience;
}

// This leverages the "experience required" equation found here:
// https://minecraft.fandom.com/wiki/Experience#Leveling_up
/**
* <p>
* Calculates how many points the given progress. This leverages the
* "experience required" equation found <a href="https://minecraft.fandom.com/wiki/Experience#Leveling_up">here</a>.
* </p>
*
* @param level int
* @param progress float
* @return int
*/
private static int calculateProgressExperience(int level, float progress) {
float progressExperience = 0;

Expand All @@ -73,12 +105,15 @@ private static int calculateProgressExperience(int level, float progress) {
if (level > 30)
progressExperience = (9 * level - 158) * progress;

int result = Math.round(progressExperience);

/*
* The below conditional is in place to prevent an issue where Minecraft doesn't
* quite reach the level it should.. i.e. 17 might become 16.999 and so forth. I
* rather give 1 xp than have someone almost the level they were.
*/
int result = Math.round(progressExperience);
return level > 0 ? result + 1 : 0;
if (result == 0) result += 1;

return level > 0 ? result : 0;
}
}
25 changes: 18 additions & 7 deletions src/main/java/me/mgin/graves/block/utility/Permission.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.mgin.graves.block.utility;

import me.mgin.graves.block.GraveBlockBase;
import me.mgin.graves.block.entity.GraveBlockEntity;
import me.mgin.graves.config.enums.GraveRetrievalType;
import me.mgin.graves.config.GravesConfig;
Expand All @@ -19,10 +20,22 @@ public class Permission {
* @return boolean
*/
static public boolean playerCanAttemptRetrieve(PlayerEntity player, GraveBlockEntity graveEntity) {
boolean graveRobbing = GravesConfig.getConfig().server.graveRobbing;
if (graveEntity.getGraveOwner() == null) return true;

return graveEntity.getGraveOwner() == null || graveEntity.isGraveOwner(player) || graveRobbing
|| playerCanOverride(player);
// Config settings
GravesConfig config = GravesConfig.getConfig();
int decayRobbing = GravesConfig.getConfig().decay.decayRobbing.ordinal();

// Get the grave's current decay stage
int graveStageOrdinal = ((GraveBlockBase) graveEntity.getState().getBlock()).getDecayStage().ordinal();

// Conditionals
boolean isGraveOwner = graveEntity.isGraveOwner(player);
boolean canDecayRob = graveStageOrdinal >= decayRobbing;
boolean graveRobbing = config.server.graveRobbing;
boolean canOverride = playerCanOverride(player);

return isGraveOwner || canDecayRob && graveRobbing || canOverride;
}

/**
Expand Down Expand Up @@ -52,8 +65,7 @@ static public boolean playerCanOverride(PlayerEntity player) {
* @return boolean
*/
static public boolean playerCanBreakGrave(PlayerEntity player, GraveBlockEntity graveEntity) {
GraveRetrievalType retrievalType = GravesConfig.resolveConfig("retrievalType",
player.getGameProfile()).main.retrievalType;
GraveRetrievalType retrievalType = GravesConfig.resolve("retrievalType", player.getGameProfile());

if (playerCanAttemptRetrieve(player, graveEntity))
return retrievalType == GraveRetrievalType.BREAK || retrievalType == GraveRetrievalType.BOTH;
Expand All @@ -76,8 +88,7 @@ static public boolean playerCanBreakGrave(PlayerEntity player, GraveBlockEntity
* @return boolean
*/
static public boolean playerCanUseGrave(PlayerEntity player, GraveBlockEntity graveEntity) {
GraveRetrievalType retrievalType = GravesConfig.resolveConfig("retrievalType",
player.getGameProfile()).main.retrievalType;
GraveRetrievalType retrievalType = GravesConfig.resolve("retrievalType", player.getGameProfile());

if (playerCanAttemptRetrieve(player, graveEntity))
return retrievalType == GraveRetrievalType.USE || retrievalType == GraveRetrievalType.BOTH;
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/me/mgin/graves/block/utility/PlaceGrave.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.mgin.graves.block.entity.GraveBlockEntity;
import me.mgin.graves.config.GravesConfig;
import me.mgin.graves.state.ServerState;
import me.mgin.graves.util.Responder;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -98,9 +99,9 @@ public static boolean graveShouldSink(World world, BlockPos pos, PlayerEntity pl
Block block = world.getBlockState(pos).getBlock();

return switch (block.getName().getString()) {
case "Air" -> !GravesConfig.resolveConfig("floatInAir", profile).floating.floatInAir;
case "Water" -> !GravesConfig.resolveConfig("floatInWater", profile).floating.floatInWater;
case "Lava" -> !GravesConfig.resolveConfig("floatInLava", profile).floating.floatInLava;
case "Air" -> (boolean) GravesConfig.resolve("sinkInAir", profile);
case "Water" -> (boolean) GravesConfig.resolve("sinkInWater", profile);
case "Lava" -> (boolean) GravesConfig.resolve("sinkInLava", profile);
default -> false;
};
}
Expand Down Expand Up @@ -226,12 +227,19 @@ public static void spawnGrave(World world, BlockPos pos, PlayerEntity player) {
ServerState.storePlayerGrave(player, graveEntity);

// Alert user if graveCoordinates is enabled
GravesConfig config = GravesConfig.resolveConfig("graveCoordinates", player.getGameProfile());

if (config.main.graveCoordinates) {
player.sendMessage(
Text.translatable("event.death:send-player-coordinates", pos.getX(), pos.getY(), pos.getZ()),
false
boolean graveCoordinates = GravesConfig.resolve("graveCoordinates", player.getGameProfile());

if (graveCoordinates) {
Responder res = new Responder(player, player.getServer());
String dimension = String.valueOf(world.getDimensionKey().getValue());

res.sendInfo(
Text.translatable("event.death:send-player-coordinates",
res.dimension(pos.getX(), dimension),
res.dimension(pos.getY(), dimension),
res.dimension(pos.getZ(), dimension)
),
null
);
}

Expand Down

0 comments on commit 9d3c5ff

Please sign in to comment.