Skip to content

Commit

Permalink
Some new features (configs), some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jul 25, 2024
1 parent cad34c3 commit 2563f3c
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
run: ./gradlew downloadTranslations build
- name: capture build artifacts
if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS
uses: actions/upload-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build
run: ./gradlew downloadTranslations build
env:
MODRINTH: ${{ secrets.MODRINTH }}
CURSEFORGE: ${{ secrets.CURSEFORGE }}
Expand Down
29 changes: 25 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
buildscript {
dependencies {
classpath "de.guntram.mcmod:crowdin-translate:1.4+1.19.3"
}
repositories {
maven {
name = 'CrowdinTranslate source'
url = "https://minecraft.guntram.de/maven/"
}
}
}


plugins {
id 'fabric-loom' version '1.6.+'
id 'maven-publish'
Expand All @@ -12,6 +25,14 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group


apply plugin: 'de.guntram.mcmod.crowdin-translate'
crowdintranslate.crowdinProjectName = 'patbox-mods'
crowdintranslate.jsonSourceName = 'universal_graves'
crowdintranslate.minecraftProjectName = '../data/universal_graves'
crowdintranslate.verbose = false


repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
Expand Down Expand Up @@ -61,11 +82,11 @@ dependencies {


modImplementation include("eu.pb4:sgui:1.6.0+1.21")
modImplementation include("eu.pb4:placeholder-api:2.4.0-pre.2+1.21")
modImplementation include("eu.pb4:placeholder-api:2.4.1+1.21")
modImplementation include('xyz.nucleoid:server-translations-api:2.3.1+1.21-pre2')
modImplementation include('eu.pb4:polymer-core:0.9.2+1.21')
modImplementation include('eu.pb4:polymer-resource-pack:0.9.2+1.21')
modImplementation include('eu.pb4:polymer-virtual-entity:0.9.2+1.21')
modImplementation include('eu.pb4:polymer-core:0.9.7+1.21')
modImplementation include('eu.pb4:polymer-resource-pack:0.9.7+1.21')
modImplementation include('eu.pb4:polymer-virtual-entity:0.9.7+1.21')
modImplementation include('eu.pb4:predicate-api:0.5.1+1.21')
modImplementation include("eu.pb4:common-protection-api:1.0.0")

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fabric_version=0.100.1+1.21


# Mod Properties
mod_version = 3.4.1+1.21
mod_version = 3.4.2+1.21
maven_group = eu.pb4
archives_base_name = graves

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/eu/pb4/graves/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import eu.pb4.predicate.api.PredicateContext;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.component.ComponentMap;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -52,7 +52,7 @@ public static class Protection {
@SerializedName("non_owner_protection_time")
public int protectionTime = 900;
@SerializedName("self_destruction_time")
public int breakingTime = 1800;
public int breakingTime = -1;
@SerializedName("drop_items_on_expiration")
public boolean dropItemsAfterExpiring = true;
@SerializedName("attackers_bypass_protection")
Expand Down Expand Up @@ -80,7 +80,7 @@ public static class Interactions {
@SerializedName("allow_remote_breaking")
public boolean allowRemoteGraveBreaking = true;
@SerializedName("allow_remote_unlocking")
public boolean allowRemoteGraveUnlocking;
public boolean allowRemoteGraveUnlocking = false;
}

@ConfigCategory
Expand Down Expand Up @@ -129,6 +129,12 @@ public static class Placement {
@SerializedName("restore_replaced_block_after_player_breaking")
public boolean restoreBlockAfterPlayerBreaking = true;

@SerializedName("move_inside_world_border")
public boolean moveInsideBorder = true;

@SerializedName("actively_move_inside_world_border")
public boolean activelyMoveInsideBorder = false;

@SerializedName("cancel_creation_for_damage_types")
public HashMap<Identifier, WrappedText> ignoredDamageTypes = new HashMap<>();
@SerializedName("cancel_creation_for_ignored_attacker_types")
Expand Down Expand Up @@ -300,7 +306,7 @@ public static class Ui {

public static class Texts {
@SerializedName("grave_created")
public WrappedText messageGraveCreated = ofText("<white><lang:'text.graves.created_at_expire':'<yellow>${position}':'<gray>${world}':'<red>${break_time}'>");
public WrappedText messageGraveCreated = ofText("<white><lang:'text.graves.created_at':'<yellow>${position}':'<gray>${world}':'<red>${break_time}'>");
@SerializedName("protection_ended")
public WrappedText messageProtectionEnded = ofText("<red><lang:'text.graves.no_longer_protected':'<gold>${position}':'<white>${world}':'<yellow>${item_count}'>");
@SerializedName("grave_expired")
Expand Down
34 changes: 12 additions & 22 deletions src/main/java/eu/pb4/graves/config/data/WrappedText.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
package eu.pb4.graves.config.data;

import eu.pb4.graves.other.DynamicNode;
import eu.pb4.placeholders.api.ParserContext;
import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.PatternPlaceholderParser;
import eu.pb4.placeholders.api.parsers.StaticPreParser;
import eu.pb4.placeholders.api.parsers.TextParserV1;
import eu.pb4.placeholders.api.parsers.*;
import net.minecraft.text.Text;
import net.minecraft.text.TextContent;

import java.util.Map;
import java.util.function.Function;

public record WrappedText(String input, TextNode textNode, Text text) {
public static final NodeParser CONTEXTLESS = NodeParser.merge(
TextParserV1.DEFAULT, Placeholders.DEFAULT_PLACEHOLDER_PARSER,
new PatternPlaceholderParser(PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN, DynamicNode::of),
StaticPreParser.INSTANCE
);

public static final NodeParser PARSER = NodeParser.merge(
TextParserV1.DEFAULT, Placeholders.DEFAULT_PLACEHOLDER_PARSER,
Placeholders.DEFAULT_PLACEHOLDER_PARSER,
new PatternPlaceholderParser(PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN, DynamicNode::of),
StaticPreParser.INSTANCE
);
public static final ParserContext.Key<Function<String, Text>> DYNAMIC_NODES = ParserContext.Key.of("graves:dynamic");

public static final NodeParser PARSER = NodeParser.builder()
.simplifiedTextFormat()
.quickText()
.placeholders(TagLikeParser.PLACEHOLDER_USER, DYNAMIC_NODES)
.staticPreParsing()
.build();

public static final WrappedText EMPTY = new WrappedText("", TextNode.empty(), Text.empty());

Expand All @@ -36,20 +26,20 @@ public static WrappedText of(String input) {
return EMPTY;
}

return new WrappedText(input, CONTEXTLESS.parseNode(input), CONTEXTLESS.parseNode(input).toText());
return new WrappedText(input, PARSER.parseNode(input), PARSER.parseNode(input).toText());
}

public Text with(Map<String, Text> textMap) {
return with(textMap::get);
}
public Text with(Function<String, Text> textMap) {
return this.textNode.toText(ParserContext.of(DynamicNode.NODES, textMap));
return this.textNode.toText(ParserContext.of(DYNAMIC_NODES, textMap));
}
public Text with(PlaceholderContext context, Map<String, Text> textMap) {
return with(context, textMap::get);
}
public Text with(PlaceholderContext context, Function<String, Text> textMap) {
return this.textNode.toText(ParserContext.of(DynamicNode.NODES, textMap).with(PlaceholderContext.KEY, context));
return this.textNode.toText(ParserContext.of(DYNAMIC_NODES, textMap).with(PlaceholderContext.KEY, context));
}

public boolean isEmpty() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.pb4.graves.event;

import com.mojang.authlib.GameProfile;
import eu.pb4.graves.other.GraveUtils;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
Expand All @@ -23,5 +24,5 @@ public interface GraveValidPosCheckEvent {
return result;
});

GraveUtils.BlockResult isValid(ServerPlayerEntity player, ServerWorld world, BlockPos pos);
GraveUtils.BlockResult isValid(GameProfile player, ServerWorld world, BlockPos pos);
}
10 changes: 10 additions & 0 deletions src/main/java/eu/pb4/graves/grave/Grave.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,16 @@ public void updateSelf(MinecraftServer server) {
return;
}

if (config.placement.activelyMoveInsideBorder && config.placement.moveInsideBorder) {
var world = server.getWorld(RegistryKey.of(RegistryKeys.WORLD, this.getLocation().world()));
if (world != null && !world.getWorldBorder().contains(this.location.blockPos())) {
var newPos = GraveUtils.findGravePosition(this.gameProfile, null, world, this.location.blockPos(), config.placement.maxPlacementDistance, config.placement.replaceAnyBlock);
if (newPos.result().canCreate()) {
this.moveTo(server, this.location.withPos(newPos.pos()));
}
}
}

if (!this.utilProtectionChangeMessage && !this.isProtected()) {
this.utilProtectionChangeMessage = true;
if (!config.texts.messageProtectionEnded.isEmpty()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/eu/pb4/graves/grave/GraveManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.graves.grave;

import com.mojang.datafixers.DataFixer;
import eu.pb4.graves.GravesMod;
import eu.pb4.graves.other.Location;
import eu.pb4.graves.registry.GraveGameRules;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
Expand All @@ -22,13 +23,12 @@

public final class GraveManager extends PersistentState {
public static GraveManager INSTANCE;

private final HashMap<UUID, Set<Grave>> byUuid = new HashMap<>();
private final HashMap<Location, Grave> byLocation = new HashMap<>();
private final Long2ObjectMap<Grave> byId = new Long2ObjectOpenHashMap<>();
private final HashSet<Grave> graves = new HashSet<>();
private long ticker;
private long currentGameTime;
private long currentGameTime = 0;
private long currentGraveId = 0;
private int protectionTime;
private int breakingTime;
Expand Down Expand Up @@ -149,7 +149,7 @@ public void tick(MinecraftServer server) {
grave.tick(server);
}
} catch (Exception e) {
e.printStackTrace();
GravesMod.LOGGER.error("Failed to tick grave!", e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/graves/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {

@Inject(method = "drop", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;dropInventory()V", shift = At.Shift.BEFORE), cancellable = true)
@Inject(method = "drop", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;dropInventory()V", shift = At.Shift.BEFORE))
private void replaceWithGrave(ServerWorld world, DamageSource damageSource, CallbackInfo ci) {
if (((Object) this) instanceof ServerPlayerEntity player) {
try {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/eu/pb4/graves/model/GraveModelHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import eu.pb4.graves.model.parts.ItemDisplayModelPart;
import eu.pb4.graves.model.parts.ModelPart;
import eu.pb4.graves.model.parts.TextDisplayModelPart;
import eu.pb4.graves.other.DynamicNode;
import eu.pb4.graves.registry.AbstractGraveBlock;
import eu.pb4.graves.registry.GraveBlock;
import eu.pb4.placeholders.api.ParserContext;
Expand All @@ -21,9 +20,6 @@
import net.minecraft.component.type.ProfileComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PlayerHeadItem;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -138,7 +134,7 @@ private void addPart(ModelPart<?, ?> part) {

this.textsWithPlaceholders.add(new TextsWithPlaceholders(node, textDisplayElement));

textDisplayElement.setText(node.toText(ParserContext.of(DynamicNode.NODES, this.dataPrivider::getGravePlaceholder)));
textDisplayElement.setText(node.toText(ParserContext.of(WrappedText.DYNAMIC_NODES, this.dataPrivider::getGravePlaceholder)));
}

if (part instanceof ItemDisplayModelPart itemDisplayModelPart && element instanceof ItemDisplayElement itemDisplayElement) {
Expand Down Expand Up @@ -249,7 +245,7 @@ protected void onTick() {

var placeholders = (Function<String, Text>) this.dataPrivider::getGravePlaceholder;
for (var text : textsWithPlaceholders) {
text.displayElement.setText(text.node().toText(ParserContext.of(DynamicNode.NODES, placeholders)));
text.displayElement.setText(text.node().toText(ParserContext.of(WrappedText.DYNAMIC_NODES, placeholders)));
}

for (int i = 0; i < this.itemDisplays.size(); i++) {
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/eu/pb4/graves/other/DynamicNode.java

This file was deleted.

Loading

0 comments on commit 2563f3c

Please sign in to comment.