Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Update to latest Fabric Waystones, fix some port-specific bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed May 16, 2022
1 parent dca80bc commit 56a658b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 36 deletions.
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/wraith/waystones/gui/UniversalWaystoneGui.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
};
}
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/wraith/waystones/gui/WaystoneSettingsGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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;
import net.minecraft.text.TranslatableText;
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;
Expand All @@ -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);
Expand All @@ -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);
})
);

Expand All @@ -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());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/wraith/waystones/item/VoidTotem.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
}
}
9 changes: 3 additions & 6 deletions src/main/java/wraith/waystones/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -64,8 +62,7 @@ public void revive(DamageSource source, CallbackInfoReturnable<Boolean> 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) {
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/wraith/waystones/util/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 56a658b

Please sign in to comment.