Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate ba47d3a817d6e044b22a6d29d507c90e21e86a87 commit to 1.19.1 #24

Open
wants to merge 1 commit into
base: 1.19.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/eu/pb4/sgui/api/GuiHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Style;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;

import javax.annotation.Nullable;
import java.util.function.UnaryOperator;

public final class GuiHelpers {
public static final UnaryOperator<Style> STYLE_CLEARER = style -> style.withItalic(style.isItalic()).withColor(style.getColor() != null ? style.getColor() : TextColor.fromFormatting(Formatting.WHITE));

@Nullable
public static GuiInterface getCurrentGui(ServerPlayerEntity player) {
return player.currentScreenHandler instanceof VirtualScreenHandlerInterface v ? v.getGui() : null;
}

public static void ignoreNextGuiClosing(ServerPlayerEntity player) {
((PlayerExtensions) player).sgui_ignoreNextClose();
((PlayerExtensions) player).sgui$ignoreNextClose();
}

public static void sendSlotUpdate(ServerPlayerEntity player, int syncId, int slot, ItemStack stack, int revision) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.sgui.api.elements;

import com.mojang.authlib.GameProfile;
import eu.pb4.sgui.api.GuiHelpers;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item;
Expand All @@ -11,7 +12,6 @@
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Util;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -332,10 +332,9 @@ public ItemStack asStack() {
}

if (this.name != null) {
if (this.name instanceof MutableText) {
((MutableText) this.name).styled(style -> style.withItalic(style.isItalic()));
}
itemStack.setCustomName(this.name);
var name = this.name.copy().styled(GuiHelpers.STYLE_CLEARER);

itemStack.setCustomName(name);
}

if (this.item.isDamageable() && this.damage != -1) {
Expand All @@ -350,9 +349,7 @@ public ItemStack asStack() {
NbtCompound display = itemStack.getOrCreateSubNbt("display");
NbtList loreItems = new NbtList();
for (Text l : this.lore) {
if (l instanceof MutableText) {
((MutableText) l).styled(style -> style.withItalic(style.isItalic()));
}
l = l.copy().styled(GuiHelpers.STYLE_CLEARER);
loreItems.add(NbtString.of(Text.Serializer.toJson(l)));
}
display.put("Lore", loreItems);
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.sgui.api.elements;

import com.mojang.authlib.GameProfile;
import eu.pb4.sgui.api.GuiHelpers;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -76,7 +77,7 @@ public static GuiElementBuilder from(ItemStack stack) {
NbtCompound tag = stack.getOrCreateNbt().copy();

if (stack.hasCustomName()) {
builder.setName((MutableText) stack.getName());
builder.setName(stack.getName());
tag.getCompound("display").remove("Name");
}

Expand Down Expand Up @@ -349,10 +350,9 @@ public ItemStack asStack() {
}

if (this.name != null) {
if (this.name instanceof MutableText) {
((MutableText) this.name).styled(style -> style.withItalic(style.isItalic()));
}
itemStack.setCustomName(this.name);
MutableText name = this.name.copy().styled(GuiHelpers.STYLE_CLEARER);

itemStack.setCustomName(name);
}

if (this.item.isDamageable() && this.damage != -1) {
Expand All @@ -367,9 +367,7 @@ public ItemStack asStack() {
NbtCompound display = itemStack.getOrCreateSubNbt("display");
NbtList loreItems = new NbtList();
for (Text l : this.lore) {
if (l instanceof MutableText) {
((MutableText) l).styled(style -> style.withItalic(style.isItalic()));
}
l = l.copy().styled(GuiHelpers.STYLE_CLEARER);
loreItems.add(NbtString.of(Text.Serializer.toJson(l)));
}
display.put("Lore", loreItems);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/sgui/api/gui/BookGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import eu.pb4.sgui.virtual.SguiScreenHandlerFactory;
import eu.pb4.sgui.virtual.book.BookScreenHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.tag.ItemTags;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.tag.ItemTags;
import net.minecraft.text.Text;

import java.util.OptionalInt;
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/eu/pb4/sgui/api/gui/GuiInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,10 @@ default void close() {
this.close(false);
}

@Deprecated
default void onUpdate(boolean firstUpdate) {
}

/**
* Executes when the screen is opened
*/
default void onOpen() {
this.onUpdate(true);
}

/**
Expand All @@ -109,6 +104,14 @@ default void onClose() {
default void onTick() {
}

default boolean canPlayerClose() {
return true;
}

default void handleException(Throwable throwable) {
throwable.printStackTrace();
}

/**
* Send additional properties to the GUI.
*
Expand All @@ -126,6 +129,12 @@ default void sendProperty(ScreenProperty property, int value) {
}
}

default void sendRawProperty(int id, int value) {
if (this.isOpen()) {
this.getPlayer().networkHandler.sendPacket(new ScreenHandlerPropertyUpdateS2CPacket(this.getSyncId(), id, value));
}
}

default boolean resetMousePosition() {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/sgui/api/gui/SignGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket;
import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket;
import net.minecraft.tag.BlockTags;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.tag.BlockTags;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public void onTick() {
this.gui.onTick();
}

@Override
public void onUpdate(boolean firstUpdate) {
this.gui.onUpdate(firstUpdate);
}

@Override
public void onOpen() {
this.gui.onOpen();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/sgui/impl/PlayerExtensions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package eu.pb4.sgui.impl;

public interface PlayerExtensions {
void sgui_ignoreNextClose();
void sgui$ignoreNextClose();
}
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/sgui/mixin/ScreenHandlerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ScreenHandlerMixin {

@Inject(method = "canInsertItemIntoSlot", at = @At("HEAD"), cancellable = true)
private static void blockIfVirtual(Slot slot, ItemStack stack, boolean allowOverflow, CallbackInfoReturnable<Boolean> cir) {
private static void sgui$blockIfVirtual(Slot slot, ItemStack stack, boolean allowOverflow, CallbackInfoReturnable<Boolean> cir) {
if (slot.inventory instanceof VirtualInventory) {
cir.setReturnValue(false);
}
Expand Down
Loading