Skip to content

Commit

Permalink
[1.2.2] Small tweaks and fixes
Browse files Browse the repository at this point in the history
- World name overrides now support formatting
- You can now block creation of graves in selected worlds
- You can change max distance of grave placement compared to player position
- Fixed some bugs
  • Loading branch information
Patbox committed Dec 4, 2021
1 parent 11cf17d commit f3a9afd
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 72 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
modImplementation include("eu.pb4:sgui:1.0.0-rc6+1.18-pre5")
modImplementation include("eu.pb4:hologram-api:0.2.1+1.18-pre5")
modImplementation include("eu.pb4:placeholder-api:1.1.3+1.17.1")
modImplementation include("eu.pb4:polymer:0.2.0-beta.5+1.18-rc3")
modImplementation include("eu.pb4:polymer:0.2.0-beta.8+1.18")
modImplementation include("fr.catcore:server-translations-api:1.4.8+1.18-pre1")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.18-rc3
yarn_mappings=1.18-rc3+build.1
loader_version=0.12.5
minecraft_version=1.18
yarn_mappings=1.18+build.1
loader_version=0.12.8

#Fabric api
fabric_version=0.43.1+1.18

# Mod Properties
mod_version = 1.2.1+1.18
mod_version = 1.2.2+1.18
maven_group = eu.pb4
archives_base_name = graves

Expand Down
40 changes: 37 additions & 3 deletions src/main/java/eu/pb4/graves/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

public final class Config {
public final ConfigData configData;
Expand Down Expand Up @@ -66,6 +66,10 @@ public final class Config {
public final BlockStyleEntry[] customBlockStateStylesLocked;
public final BlockStyleEntry[] customBlockStateStylesUnlocked;

public final Set<Identifier> skippedEnchantments;
public final Map<Identifier, Text> worldNameOverrides;
public final Set<Identifier> blacklistedWorlds;


public Config(ConfigData data) {
this.configData = data;
Expand Down Expand Up @@ -96,6 +100,34 @@ public Config(ConfigData data) {

this.guiProtectedItem = parseItems(this.configData.guiProtectedItem);
this.guiItem = parseItems(this.configData.guiItem);

this.skippedEnchantments = parseIds(data.skippedEnchantments);
this.blacklistedWorlds = parseIds(data.blacklistedWorlds);

this.worldNameOverrides = new HashMap<>();

for (var entry : data.worldNameOverrides.entrySet()) {
var id = Identifier.tryParse(entry.getKey());

if (id != null) {
this.worldNameOverrides.put(id, parse(entry.getValue()));
}
}
}

private static Set<Identifier> parseIds(List<String> ids) {
var set = new HashSet<Identifier>();
for (var id : ids) {
if (id != null) {
var identifier = Identifier.tryParse(id);

if (identifier != null) {
set.add(identifier);
}
}
}

return set;
}

@Nullable
Expand Down Expand Up @@ -198,7 +230,9 @@ private static Text[] parse(List<String> strings) {
List<Text> texts = new ArrayList<>();

for (String line : strings) {
if (line.isEmpty()) {
if (line == null) {
continue;
} else if (line.isEmpty()) {
texts.add(LiteralText.EMPTY);
} else {
texts.add(TextParser.parse(line));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/eu/pb4/graves/config/data/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ConfigData extends VersionedConfigData implements Cloneable {
public double xpPercentTypeValue = 100;

public boolean replaceAnyBlock = false;
public int maxPlacementDistance = 8;
//public boolean useRealTime = true;

public boolean createFromPvP = true;
Expand Down Expand Up @@ -85,11 +86,13 @@ public class ConfigData extends VersionedConfigData implements Cloneable {
public String infinityText = "∞";

public Map<String, String> worldNameOverrides = new HashMap<>();
public List<String> blacklistedWorlds = new ArrayList<>();

public boolean tryDetectionSoulbound = true;
public List<String> skippedEnchantments = new ArrayList<>();



private static List<String> getDefaultProtectedHologram() {
List<String> list = new ArrayList<>();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/graves/grave/GraveInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Map<String, Text> getPlaceholders(MinecraftServer server) {
values.put("xp", new LiteralText("" + this.xp));
values.put("item_count", new LiteralText("" + this.itemCount));
values.put("position", new LiteralText("" + this.position.toShortString()));
values.put("world", new LiteralText(GraveUtils.toWorldName(this.world)));
values.put("world", GraveUtils.toWorldName(this.world));
values.put("death_cause", this.deathCause);
return values;
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/eu/pb4/graves/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ private void graves_onKill(CallbackInfo ci) {
@Inject(method = "drop", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;dropInventory()V", shift = At.Shift.BEFORE), cancellable = true)
private void replaceWithGrave(DamageSource source, CallbackInfo ci) {
if (((Object) this) instanceof ServerPlayerEntity player) {
if (player.getWorld().getGameRules().getBoolean(GameRules.KEEP_INVENTORY)) {
return;
}

try {
Config config = ConfigManager.getConfig();

if (player.getWorld().getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || config.blacklistedWorlds.contains(player.getWorld().getRegistryKey().getValue())) {
return;
}

Text text = null;
Map<String, Text> placeholders = Map.of(
"position", new LiteralText("" + player.getBlockPos().toShortString()),
"world", new LiteralText(GraveUtils.toWorldName(player.getWorld().getRegistryKey().getValue()))
"world", GraveUtils.toWorldName(player.getWorld().getRegistryKey().getValue())
);


Expand All @@ -78,7 +79,7 @@ private void replaceWithGrave(DamageSource source, CallbackInfo ci) {
var eventResult = PlayerGraveCreationEvent.EVENT.invoker().shouldCreate(player);

if (eventResult.canCreate()) {
var result = GraveUtils.findGravePosition(player, player.getWorld(), player.getBlockPos(), config.configData.replaceAnyBlock);
var result = GraveUtils.findGravePosition(player, player.getWorld(), player.getBlockPos(), config.configData.maxPlacementDistance, config.configData.replaceAnyBlock);

if (result.result().canCreate()) {
BlockPos gravePos = result.pos();
Expand Down
80 changes: 47 additions & 33 deletions src/main/java/eu/pb4/graves/other/GraveUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.property.Property;
import net.minecraft.tag.Tag;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -46,44 +48,56 @@ private <T extends Comparable<T>> String nameValue(Property<T> property, Compara
}
};

public static BlockCheckResult findGravePosition(ServerPlayerEntity player, ServerWorld world, BlockPos blockPos, boolean anyBlock) {
int maxDistance = 8;
int line = 1;

public static BlockCheckResult findGravePosition(ServerPlayerEntity player, ServerWorld world, BlockPos blockPos, int maxDistance, boolean anyBlock) {
var border = world.getWorldBorder();
blockPos = new BlockPos(MathHelper.clamp(blockPos.getX(), border.getBoundWest() + 1, border.getBoundEast() - 1), MathHelper.clamp(blockPos.getY(), world.getBottomY(), world.getTopY() - 1), MathHelper.clamp(blockPos.getZ(), border.getBoundNorth() + 1, border.getBoundSouth() - 1));
BlockResult result = isValidPos(player, world, border, blockPos, anyBlock);
BlockResult tempResult;
var result = isValidPos(player, world, border, blockPos, false);
if (result.allow) {
return new BlockCheckResult(blockPos, result);
} else {
BlockPos.Mutable pos = new BlockPos.Mutable(blockPos.getX(), blockPos.getY(), blockPos.getZ());

while (line <= maxDistance) {
int side = line * 2 + 1;
for (int oY = 0; oY < side; oY++) {
for (int oX = 0; oX < side; oX++) {
for (int oZ = 0; oZ < side; oZ++) {
pos.set(blockPos.getX() - line + oX, blockPos.getY() - line + oY, blockPos.getZ() - line + oZ);

if ((oX > 0 && oX < side - 1) && (oY > 0 && oY < side - 1) && (oZ > 0 && oZ < side - 1)) {
continue;
}

tempResult = isValidPos(player, world, border, pos, anyBlock);
if (tempResult.priority >= result.priority) {
result = tempResult;
}
if (result.canCreate()) {
return new BlockCheckResult(pos.toImmutable(), result);
}
var checkResult = findPos(player, world, blockPos, maxDistance, false);

if (!checkResult.result.allow && anyBlock) {
checkResult = findPos(player, world, blockPos, maxDistance, true);
}

return checkResult;
}
}

private static BlockCheckResult findPos(ServerPlayerEntity player, ServerWorld world, BlockPos blockPos, int maxDistance, boolean allowAnyBlock) {
int line = 1;
var border = world.getWorldBorder();
BlockResult result = isValidPos(player, world, border, blockPos, allowAnyBlock);

BlockResult tempResult;
BlockPos.Mutable pos = new BlockPos.Mutable(blockPos.getX(), blockPos.getY(), blockPos.getZ());

while (line <= maxDistance) {
int side = line * 2 + 1;
for (int oY = 0; oY < side; oY++) {
for (int oX = 0; oX < side; oX++) {
for (int oZ = 0; oZ < side; oZ++) {
pos.set(blockPos.getX() - line + oX, blockPos.getY() - line + oY, blockPos.getZ() - line + oZ);

if ((oX > 0 && oX < side - 1) && (oY > 0 && oY < side - 1) && (oZ > 0 && oZ < side - 1)) {
continue;
}

tempResult = isValidPos(player, world, border, pos, allowAnyBlock);
if (tempResult.priority >= result.priority) {
result = tempResult;
}
if (result.canCreate()) {
return new BlockCheckResult(pos.toImmutable(), result);
}
}
}
line++;
}
return new BlockCheckResult(null, result);
line++;
}

return new BlockCheckResult(null, result);
}


Expand All @@ -108,8 +122,8 @@ public static String blockStateToString(BlockState state) {
return stringBuilder.toString();
}

public static String toWorldName(Identifier identifier) {
var override = ConfigManager.getConfig().configData.worldNameOverrides.get(identifier.toString());
public static Text toWorldName(Identifier identifier) {
var override = ConfigManager.getConfig().worldNameOverrides.get(identifier);
if (override != null) {
return override;
}
Expand All @@ -123,15 +137,15 @@ public static String toWorldName(Identifier identifier) {
parts.add(String.join("", s));
}
}
return String.join(" ", parts);
return new LiteralText(String.join(" ", parts));
}

public static boolean hasSkippedEnchantment(ItemStack stack) {
var config = ConfigManager.getConfig().configData;
var config = ConfigManager.getConfig();
for (var enchant : stack.getEnchantments()) {
if (enchant instanceof NbtCompound compound) {
var key = EnchantmentHelper.getIdFromNbt(compound);
if (key != null && config.skippedEnchantments.contains(key.toString()) || (config.tryDetectionSoulbound && (key.getPath().contains("soulbound") || key.getPath().contains("soul_bound")))) {
if (key != null && config.skippedEnchantments.contains(key) || (config.configData.tryDetectionSoulbound && (key.getPath().contains("soulbound") || key.getPath().contains("soul_bound")))) {
return true;
}
}
Expand Down
23 changes: 1 addition & 22 deletions src/main/resources/data/universal_graves/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,5 @@
"text.graves.creation_failed": "Couldn't create grave! Your items were dropped at %s (%s)",
"text.graves.creation_failed_void": "Grave wasn't created, because you died in void!",
"text.graves.creation_failed_pvp": "Grave wasn't created, because player killed you! Your items were dropped at %s (%s)",
"text.graves.creation_failed_claim": "Grave wasn't created, because you were in a claim! Your items were dropped at %s (%s)",

"options.universal_graves._comment": "v These are unused as for now, you can ignore them for now v",

"options.universal_graves.title": "Universal Graves Config",
"options.universal_grave.grave_type": "Grave style: ",
"options.universal_grave.grave_type.type.chest": "Chest",
"options.universal_grave.grave_type.type.barrel": "Barrel",
"options.universal_grave.grave_type.type.player_head": "Player Head",
"options.universal_grave.grave_type.type.preset_head": "Preset Head",


"options.universal_grave.xp_storage_type": "XP Storage: ",
"options.universal_grave.xp_storage_type.type.vanilla": "Vanilla",
"options.universal_grave.xp_storage_type.type.drop": "Drop (Ignore)",
"options.universal_grave.xp_storage_type.type.percent_points": "Percent (Points)",
"options.universal_grave.xp_storage_type.type.percent_levels": "Percent (Levels)",
"options.universal_grave.xp_storage_type.type.none": "None (Destroy)",

"options.universal_grave.breaking_time": "Break grave after (seconds)",
"options.universal_grave.protection_time": "Protect for (seconds)",
"options.universal_grave.is_protected": "Protect against players"
"text.graves.creation_failed_claim": "Grave wasn't created, because you were in a claim! Your items were dropped at %s (%s)"
}
1 change: 0 additions & 1 deletion src/main/resources/data/universal_graves/lang/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
"text.graves.creation_failed": "Nie można było stworzyć grobu! Twoje przedmioty leżą na %s (%s)",
"text.graves.creation_failed_pvp": "Nie stworzono grobu, ponieważ zostałeś zabity przez gracza! Twoje przedmioty leżą na %s (%s)",
"text.graves.creation_failed_claim": "Nie stworzono grobu, ponieważ byłeś na działce! Twoje przedmioty leżą na %s (%s)"

}
1 change: 0 additions & 1 deletion src/main/resources/data/universal_graves/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
"text.graves.creation_failed": "坟墓生成失败!你的物品洒在了%s(%s)",
"text.graves.creation_failed_pvp": "玩家击杀不生成坟墓!你的物品洒在了%s(%s)",
"text.graves.creation_failed_claim": "领地内不生成坟墓!你的物品洒在了%s(%s)"

}

0 comments on commit f3a9afd

Please sign in to comment.