Skip to content

Commit

Permalink
Add some features and fix some bugs
Browse files Browse the repository at this point in the history
- Added config option to set limit for number of graves existing at the same time
- Fix setting for grave creation in claims being cleared every time config loaded
- Guis no longer resets mouse position
- Added back button for list ui
- You can now fetch/move grave to players position by clicking new button in ui (requires `universal_graves.fetch_grave` permission for self, or `universal_graves.fetch_grave.others` for other players, op-only by default)
  • Loading branch information
Patbox committed Oct 1, 2022
1 parent 8207b7d commit 0e572a2
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 179 deletions.
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"


modImplementation include("eu.pb4:sgui:1.1.3+1.19.1")
modImplementation include("eu.pb4:sgui:1.1.5+1.19.1")
modImplementation include("eu.pb4:hologram-api:0.2.2+1.19")
modImplementation include("eu.pb4:placeholder-api:2.0.0-beta.7+1.19")
modImplementation include("eu.pb4:polymer:0.2.10+1.19.1")
modImplementation include("eu.pb4:polymer:0.2.16+1.19.2")
modImplementation include("eu.pb4:common-protection-api:1.0.0")
modImplementation include("fr.catcore:server-translations-api:1.4.16+1.19")
modImplementation include("fr.catcore:server-translations-api:1.4.17+1.19.2")
modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT")

modCompileOnly "dev.emi:trinkets:3.0.4"
Expand Down Expand Up @@ -106,6 +106,10 @@ jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}

from("src/main/resources/data/universal_graves/lang") {
into("assets/universal_graves/lang")
}
}

// configure the maven publication
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.19.1
yarn_mappings=1.19.1+build.1
loader_version=0.14.8
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.1
loader_version=0.14.9

#Fabric api
fabric_version=0.58.4+1.19.1
fabric_version=0.60.0+1.19.2


# Mod Properties
mod_version = 2.1.1+1.19.1
mod_version = 2.1.2+1.19.2
maven_group = eu.pb4
archives_base_name = graves

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/graves/GenericModInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void build(ModContainer container) {
Collections.addAll(output, icon);
output.addAll(about);
}
} catch (Exception e) {
} catch (Throwable e) {
e.printStackTrace();
var invalid = Text.literal("/!\\ [ Invalid about mod info ] /!\\").setStyle(Style.EMPTY.withColor(0xFF0000).withItalic(true));

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/eu/pb4/graves/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public final class Config {
public final Text guiQuickPickupText;
public final Text guiCantReverseAction;
public final Text guiClickToConfirm;
public final Text guiBackText;

public final Text guiTeleportActiveText;
public final Text guiTeleportNotEnoughText;
Expand All @@ -110,6 +111,7 @@ public final class Config {
public final Text teleportCancelledText;

public final ItemStack guiInfoIcon;
public final Text guiFetchText;

public final ItemStack guiPreviousPageIcon;
public final ItemStack guiPreviousPageBlockedIcon;
Expand All @@ -124,9 +126,12 @@ public final class Config {

public final ItemStack guiQuickPickupIcon;
public final ItemStack guiBarItem;
public final ItemStack guiBackIcon;
public final ItemStack guiFetchIcon;
public final SimpleDateFormat fullDateFormat;
public final HashMap<Identifier, List<Box>> blacklistedAreas;
public final Object2BooleanMap<Identifier> blacklistedProtectedAreas = new Object2BooleanOpenHashMap<>();
public final Text guiFetchFailedText;

public Config(ConfigData data) {
this.configData = data;
Expand Down Expand Up @@ -171,6 +176,10 @@ public Config(ConfigData data) {
this.guiTeleportActiveText = parseText(data.guiTeleportActiveText);
this.guiTeleportNotEnoughText = parseText(data.guiTeleportNotEnoughText);

this.guiBackText = parseText(data.guiBackText);
this.guiFetchText = parseText(data.guiFetchText);
this.guiFetchFailedText = parseText(data.guiFetchFailedText);

this.teleportLocationText = parse(data.teleportLocationText);
this.teleportTimerText = parse(data.teleportTimerText);
this.teleportTimerAllowMovingText = parse(data.teleportTimerTextAllowMoving);
Expand All @@ -187,6 +196,8 @@ public Config(ConfigData data) {
this.guiBreakGraveIcon = parseItem(data.guiBreakGraveIcon);
this.guiQuickPickupIcon = parseItem(data.guiQuickPickupIcon);
this.guiTeleportIcon = parseItem(data.guiTeleportIcon);
this.guiBackIcon = parseItem(data.guiBackItem);
this.guiFetchIcon = parseItem(data.guiFetchIcon);

this.teleportationCost = TeleportationCost.decode(data.teleportationCostType, data.teleportationCostConsumable, data.teleportationCostCount);

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/eu/pb4/graves/config/data/ConfigData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.Blocks;
import net.minecraft.block.WallBlock;
import net.minecraft.block.enums.WallShape;
import net.minecraft.text.Text;

import java.util.*;

Expand Down Expand Up @@ -43,6 +44,8 @@ public class ConfigData extends VersionedConfigData {
public int invincibleTime = 2;
public boolean keepBlockAfterBreaking = false;
public boolean restoreBlockAfterPlayerBreaking = true;
public int maxGraveCount = -1;


public String xpStorageType = GravesXPCalculation.PERCENT_POINTS.name;
public double xpPercentTypeValue = 100;
Expand Down Expand Up @@ -133,6 +136,9 @@ public class ConfigData extends VersionedConfigData {
public String guiQuickPickupText = "<yellow><lang:'text.graves.gui.quick_pickup'>";
public String guiCantReverseAction = "<dark_red><bold><lang:'text.graves.gui.cant_reverse'>";
public String guiClickToConfirm = "<white><lang:'text.graves.gui.click_to_confirm'>";
public String guiFetchText = "<yellow><lang:'text.graves.gui.fetch'>";
public String guiBackText = "<red><lang:'gui.back'>";
public String guiFetchFailedText = "<red><lang:'text.graves.gui.fetch_failed'>";


public String guiTeleportActiveText = "<#a52dfa><lang:'text.graves.gui.teleport'>";
Expand All @@ -153,9 +159,11 @@ public class ConfigData extends VersionedConfigData {
public String guiRemoveProtectionIcon = "universal_graves:icon{Texture:\"remove_protection\"}";
public String guiBreakGraveIcon = "universal_graves:icon{Texture:\"break_grave\"}";
public String guiTeleportIcon = "minecraft:ender_pearl";
public String guiFetchIcon = "minecraft:lead";


public String guiQuickPickupIcon = "universal_graves:icon{Texture:\"quick_pickup\"}";
public String guiBackItem = "minecraft:barrier";

private static List<String> getDefaultProtectedHologram() {
List<String> list = new ArrayList<>();
Expand Down Expand Up @@ -248,7 +256,7 @@ private static List<String> getDefaultSign() {

public void fillMissing() {
for (var id : CommonProtection.getProviderIds()) {
if (!id.getNamespace().equals("universal_graves")) {
if (!id.getNamespace().equals("universal_graves") && !this.createInProtectedArea.containsKey(id.toString())) {
this.createInProtectedArea.put(id.toString(), false);
}
}
Expand Down
48 changes: 44 additions & 4 deletions src/main/java/eu/pb4/graves/grave/Grave.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.pb4.graves.config.Config;
import eu.pb4.graves.config.ConfigManager;
import eu.pb4.graves.other.*;
import eu.pb4.graves.registry.GraveBlock;
import eu.pb4.graves.registry.GraveBlockEntity;
import eu.pb4.graves.ui.GraveGui;
import eu.pb4.placeholders.api.Placeholders;
Expand All @@ -16,14 +17,12 @@
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.nbt.NbtList;
import net.minecraft.network.message.MessageType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.Util;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkSectionPos;
Expand Down Expand Up @@ -277,9 +276,46 @@ public Location getLocation() {
}

public void setLocation(Location location) {
GraveManager.INSTANCE.moveToLocation(this, location);
this.location = location;
}

public boolean moveTo(MinecraftServer server, Location location) {
var world = server.getWorld(RegistryKey.of(Registry.WORLD_KEY, location.world()));

if (world != null) {
var state = world.getBlockState(location.blockPos());

if (GraveUtils.canReplaceState(state, ConfigManager.getConfig().configData.replaceAnyBlock)
&& world.getWorldBorder().contains(location.blockPos()) && location.y() >= world.getBottomY() && location.y() < world.getTopY()) {

var old = this.location;
this.setLocation(location);

{
var oldWorld = server.getWorld(RegistryKey.of(Registry.WORLD_KEY, old.world()));

if (oldWorld != null) {
var oldChunk = oldWorld.getChunk(ChunkSectionPos.getSectionCoord(old.x()), ChunkSectionPos.getSectionCoord(old.z()));

if (oldChunk.getBlockEntity(old.blockPos()) instanceof GraveBlockEntity grave) {
grave.setGrave(null);
grave.breakBlock(false);
}
}
}

world.setBlockState(location.blockPos(), GraveBlock.INSTANCE.getDefaultState());

if (world.getBlockEntity(location.blockPos()) instanceof GraveBlockEntity entity) {
entity.setGrave(this, state);
}
return true;
}
}
return false;
}

public void setLocation(Identifier identifier, BlockPos pos) {
setLocation(new Location(identifier, pos));
}
Expand All @@ -288,9 +324,13 @@ public List<PositionedItemStack> getItems() {
return this.items;
}

public void openUi(ServerPlayerEntity player, boolean canTake) {
public void openUi(ServerPlayerEntity player, boolean canTake, boolean catFetch, @Nullable Runnable runnable) {
new GraveGui(player, this, canTake, this.canTakeFrom(player)
&& (ConfigManager.getConfig().teleportationCost.type() != TeleportationCost.Type.CREATIVE || player.isCreative())).open();
&& (ConfigManager.getConfig().teleportationCost.type() != TeleportationCost.Type.CREATIVE || player.isCreative()), catFetch, runnable).open();
}

public void openUi(ServerPlayerEntity player, boolean canTake) {
openUi(player, canTake, false, null);
}

public Inventory asInventory() {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/eu/pb4/graves/grave/GraveManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import org.jetbrains.annotations.ApiStatus;

import java.util.*;

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

private HashMap<UUID, Set<Grave>> byUuid = new HashMap<>();
Expand Down Expand Up @@ -109,6 +111,12 @@ public Grave getByLocation(Location location) {
return this.byLocation.get(location);
}

@ApiStatus.Internal
public void moveToLocation(Grave grave, Location location) {
this.byLocation.remove(grave.location);
this.byLocation.put(location, grave);
}

public Grave getByLocation(Identifier world, BlockPos pos) {
return this.getByLocation(new Location(world, pos.toImmutable()));
}
Expand Down Expand Up @@ -159,4 +167,8 @@ public boolean isProtectionEnabled() {
public int getBreakingTime() {
return this.breakingTime;
}

public Collection<Grave> getByPlayer(ServerPlayerEntity player) {
return this.getByUuid(player.getUuid());
}
}
Loading

0 comments on commit 0e572a2

Please sign in to comment.