diff --git a/build.gradle b/build.gradle index 56a2c98..d001821 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ group = project.maven_group repositories { maven { url = "https://www.cursemaven.com" } maven { url = "https://maven.nucleoid.xyz" } + maven { url = "https://oss.sonatype.org/content/repositories/snapshots" } } dependencies { @@ -28,10 +29,11 @@ dependencies { modCompileOnly 'curse.maven:repurposed-structures-fabric-391366:3542863' - modImplementation include("eu.pb4:sgui:1.0.1+1.18.2") + modImplementation include("eu.pb4:sgui:1.0.2+1.18.2") modImplementation include("eu.pb4:hologram-api:0.2.1+1.18-pre5") - modImplementation include("eu.pb4:polymer:0.2.0-beta.36+1.18.2") - modImplementation include("fr.catcore:server-translations-api:1.4.9+1.18.2-rc1") + modImplementation include("eu.pb4:polymer:0.2.0-pre.4+1.18.2") + modImplementation include("fr.catcore:server-translations-api:1.4.12+1.18.2") + modImplementation include("me.lucko:fabric-permissions-api:0.1-SNAPSHOT") } loom { @@ -106,7 +108,7 @@ if (System.getenv("MODRINTH")) { // On fabric, use 'remapJar' instead of 'jar' uploadFile = remapJar gameVersions = [((String) project.minecraft_version)] - loaders = ["fabric"] + loaders = ["fabric", "quilt"] } remapJar { diff --git a/src/main/java/wraith/waystones/gui/UniversalWaystoneGui.java b/src/main/java/wraith/waystones/gui/UniversalWaystoneGui.java index 74553fb..7037129 100644 --- a/src/main/java/wraith/waystones/gui/UniversalWaystoneGui.java +++ b/src/main/java/wraith/waystones/gui/UniversalWaystoneGui.java @@ -1,11 +1,10 @@ package wraith.waystones.gui; import eu.pb4.sgui.api.ClickType; -import eu.pb4.sgui.api.elements.GuiElement; import eu.pb4.sgui.api.elements.GuiElementBuilder; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.enchantment.Enchantments; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.server.network.ServerPlayerEntity; @@ -28,7 +27,6 @@ import java.util.ArrayList; import java.util.Comparator; -import java.util.Objects; import java.util.function.Consumer; import java.util.function.Predicate; @@ -78,14 +76,14 @@ protected DisplayElement getNavElement(int id) { case 1 -> DisplayElement.previousPage(this); case 3 -> DisplayElement.nextPage(this); case 5 -> getCost(); - case 7 -> DisplayElement.of( + case 7 -> Permissions.check(this.player, "waystones.can_edit_any", 3) || this.player.getUuid().equals(waystone.getOwner()) ? DisplayElement.of( new GuiElementBuilder(Items.REDSTONE) .setName(new TranslatableText("waystones.config.tooltip.config")) .setCallback((x, y, z) -> { playClickSound(this.player); WaystoneSettingsGui.open(user, waystone); }) - ); + ) : DisplayElement.filler(); default -> DisplayElement.filler(); }; } diff --git a/src/main/java/wraith/waystones/gui/WaystoneSettingsGui.java b/src/main/java/wraith/waystones/gui/WaystoneSettingsGui.java index 131f8b8..e9cd88f 100644 --- a/src/main/java/wraith/waystones/gui/WaystoneSettingsGui.java +++ b/src/main/java/wraith/waystones/gui/WaystoneSettingsGui.java @@ -3,6 +3,7 @@ import eu.pb4.sgui.api.elements.GuiElementBuilder; import eu.pb4.sgui.api.gui.AnvilInputGui; import eu.pb4.sgui.api.gui.SimpleGui; +import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.network.ServerPlayerEntity; @@ -10,6 +11,7 @@ import net.minecraft.util.Formatting; import wraith.waystones.Waystones; import wraith.waystones.block.WaystoneBlockEntity; +import wraith.waystones.util.Config; public class WaystoneSettingsGui extends SimpleGui { private final WaystoneBlockEntity waystone; @@ -28,16 +30,20 @@ public void onTick() { } protected void updateDisplay() { - this.setSlot(0, new GuiElementBuilder(waystone.isGlobal() ? Items.ENDER_EYE : Items.ENDER_PEARL) - .setName(new TranslatableText("waystones.config.global")) - .setCallback((x, y, z) -> { - Waystones.WAYSTONE_STORAGE.toggleGlobal(waystone.getHash()); - PagedGui.playClickSound(this.player); - this.updateDisplay(); - }) - ); + int i = 0; + + if (Config.getInstance().canPlayersToggleGlobal() || Permissions.check(this.player, "waystones.set_global", 3)) { + this.setSlot(i++, new GuiElementBuilder(waystone.isGlobal() ? Items.ENDER_EYE : Items.ENDER_PEARL) + .setName(new TranslatableText("waystones.config.global")) + .setCallback((x, y, z) -> { + Waystones.WAYSTONE_STORAGE.toggleGlobal(waystone.getHash()); + PagedGui.playClickSound(this.player); + this.updateDisplay(); + }) + ); + } - this.setSlot(1, new GuiElementBuilder(Items.SKELETON_SKULL) + this.setSlot(i++, new GuiElementBuilder(Items.SKELETON_SKULL) .setName(new TranslatableText("waystones.config.tooltip.revoke_ownership").formatted(Formatting.WHITE)) .setCallback((x, y, z) -> { Waystones.WAYSTONE_STORAGE.setOwner(waystone.getHash(), null); @@ -46,11 +52,11 @@ protected void updateDisplay() { }) ); - this.setSlot(2, new GuiElementBuilder(Items.NAME_TAG) + this.setSlot(i++, new GuiElementBuilder(Items.NAME_TAG) .setName(new TranslatableText("polyport.waystones.rename").formatted(Formatting.WHITE)) .setCallback((x, y, z) -> { PagedGui.playClickSound(this.player); - openRanaming(this.player, this.waystone); + openRenaming(this.player, this.waystone); }) ); @@ -63,7 +69,7 @@ protected void updateDisplay() { ); } - private static void openRanaming(ServerPlayerEntity player, WaystoneBlockEntity waystone) { + private static void openRenaming(ServerPlayerEntity player, WaystoneBlockEntity waystone) { var ui = new AnvilInputGui(player, false); ui.setTitle(new TranslatableText("polyport.waystones.rename")); ui.setDefaultInputValue(waystone.getWaystoneName()); diff --git a/src/main/java/wraith/waystones/item/VoidTotem.java b/src/main/java/wraith/waystones/item/VoidTotem.java index f9f2166..1f115cf 100644 --- a/src/main/java/wraith/waystones/item/VoidTotem.java +++ b/src/main/java/wraith/waystones/item/VoidTotem.java @@ -1,5 +1,11 @@ package wraith.waystones.item; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.server.network.ServerPlayerEntity; +import org.jetbrains.annotations.Nullable; + public class VoidTotem extends LocalVoidItem { public VoidTotem(Settings settings) { @@ -8,4 +14,8 @@ public VoidTotem(Settings settings) { this.translationName = "void_totem"; } + @Override + public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) { + return Items.TOTEM_OF_UNDYING; + } } diff --git a/src/main/java/wraith/waystones/mixin/LivingEntityMixin.java b/src/main/java/wraith/waystones/mixin/LivingEntityMixin.java index 539c7ca..6a62582 100644 --- a/src/main/java/wraith/waystones/mixin/LivingEntityMixin.java +++ b/src/main/java/wraith/waystones/mixin/LivingEntityMixin.java @@ -1,14 +1,13 @@ package wraith.waystones.mixin; -import io.netty.buffer.Unpooled; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.entity.EntityStatuses; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Hand; import org.spongepowered.asm.mixin.Mixin; @@ -22,7 +21,6 @@ import wraith.waystones.registry.ItemRegistry; import wraith.waystones.util.TeleportSources; import wraith.waystones.util.Utils; -import wraith.waystones.util.WaystonePacketHandler; import java.util.ArrayList; @@ -64,8 +62,7 @@ public void revive(DamageSource source, CallbackInfoReturnable cir) { addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 800, 0)); var teleported = false; if (player instanceof ServerPlayerEntity serverPlayer) { - PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer()); - ServerPlayNetworking.send(serverPlayer, WaystonePacketHandler.VOID_REVIVE, packet); + serverPlayer.networkHandler.sendPacket(new EntityStatusS2CPacket(serverPlayer, EntityStatuses.USE_TOTEM_OF_UNDYING)); // Try to get the stored waystone var hash = VoidTotem.getBoundWaystone(stack); if (hash == null) { diff --git a/src/main/java/wraith/waystones/util/Utils.java b/src/main/java/wraith/waystones/util/Utils.java index 051faf7..cc67ff5 100644 --- a/src/main/java/wraith/waystones/util/Utils.java +++ b/src/main/java/wraith/waystones/util/Utils.java @@ -1,6 +1,8 @@ package wraith.waystones.util; import com.mojang.datafixers.util.Pair; +import eu.pb4.sgui.api.gui.SlotGuiInterface; +import eu.pb4.sgui.virtual.VirtualScreenHandlerInterface; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -18,11 +20,9 @@ import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; import wraith.waystones.Waystones; +import wraith.waystones.gui.UniversalWaystoneGui; import wraith.waystones.item.LocalVoidItem; import wraith.waystones.mixin.StructurePoolAccessor; -import wraith.waystones.screen.AbyssScreenHandler; -import wraith.waystones.screen.PocketWormholeScreenHandler; -import wraith.waystones.screen.WaystoneBlockScreenHandler; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; @@ -287,12 +287,8 @@ public static String getDimensionName(World world) { } public static TeleportSources getTeleportSource(PlayerEntity player) { - if (player.currentScreenHandler instanceof AbyssScreenHandler) { - return TeleportSources.ABYSS_WATCHER; - } else if (player.currentScreenHandler instanceof PocketWormholeScreenHandler) { - return TeleportSources.POCKET_WORMHOLE; - } else if (player.currentScreenHandler instanceof WaystoneBlockScreenHandler) { - return TeleportSources.WAYSTONE; + if (player.currentScreenHandler instanceof VirtualScreenHandlerInterface e && e.getGui() instanceof UniversalWaystoneGui gui) { + return gui.getSource(); } else { for (var hand : Hand.values()) { if (!(player.getStackInHand(hand).getItem() instanceof LocalVoidItem)) continue;