Skip to content

Commit

Permalink
Fix lore text not being cleared (was broken since 1.20.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Oct 22, 2024
1 parent bf4b1d3 commit ab71ed8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
6 changes: 3 additions & 3 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/versions.html
minecraft_version=1.21.2-rc1
yarn_mappings=1.21.2-rc1+build.1
minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
loader_version=0.16.7

#Fabric api
fabric_version=0.106.0+1.21.2


# Mod Properties
mod_version = 1.7.0+1.21.2
mod_version = 1.7.1+1.21.2
maven_group = eu.pb4
archives_base_name = sgui

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.authlib.minecraft.MinecraftProfileTextures;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import eu.pb4.sgui.api.GuiHelpers;
import net.minecraft.component.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.Unit;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -148,6 +150,22 @@ public AnimatedGuiElementBuilder setMaxCount(int count) {
* @return this element builder
*/
public AnimatedGuiElementBuilder setLore(List<Text> lore) {
var l = new ArrayList<Text>(lore.size());
for (var t : lore) {
l.add(t.copy().styled(GuiHelpers.STYLE_CLEARER));
}

this.itemStack.set(DataComponentTypes.LORE, new LoreComponent(l));
return this;
}

/**
* Sets the lore lines of the element, without clearing out formatting.
*
* @param lore a list of all the lore lines
* @return this element builder
*/
public AnimatedGuiElementBuilder setLoreRaw(List<Text> lore) {
this.itemStack.set(DataComponentTypes.LORE, new LoreComponent(lore));
return this;
}
Expand All @@ -159,6 +177,17 @@ public AnimatedGuiElementBuilder setLore(List<Text> lore) {
* @return this element builder
*/
public AnimatedGuiElementBuilder addLoreLine(Text lore) {
this.itemStack.apply(DataComponentTypes.LORE, LoreComponent.DEFAULT, lore.copy().styled(GuiHelpers.STYLE_CLEARER), LoreComponent::with);
return this;
}

/**
* Adds a line of lore to the element, without clearing out formatting.
*
* @param lore the line to add
* @return this element builder
*/
public AnimatedGuiElementBuilder addLoreLineRaw(Text lore) {
this.itemStack.apply(DataComponentTypes.LORE, LoreComponent.DEFAULT, lore, LoreComponent::with);
return this;
}
Expand Down Expand Up @@ -359,6 +388,23 @@ public AnimatedGuiElementBuilder setSkullOwner(String value, @Nullable String si
return this;
}

/**
* Sets the model of the element.
*
* @param model model to display item as
* @return this element builder
*/
public AnimatedGuiElementBuilder model(Identifier model) {
this.itemStack.set(DataComponentTypes.ITEM_MODEL, model);
return this;
}

public AnimatedGuiElementBuilder model(Item model) {
this.itemStack.set(DataComponentTypes.ITEM_MODEL, model.getComponents().get(DataComponentTypes.ITEM_MODEL));
return this;
}


@Override
public AnimatedGuiElementBuilder setCallback(GuiElement.ClickCallback callback) {
this.callback = callback;
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.authlib.minecraft.MinecraftProfileTextures;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import eu.pb4.sgui.api.GuiHelpers;
import net.minecraft.component.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
Expand Down Expand Up @@ -162,6 +163,22 @@ public GuiElementBuilder setMaxCount(int count) {
* @return this element builder
*/
public GuiElementBuilder setLore(List<Text> lore) {
var l = new ArrayList<Text>(lore.size());
for (var t : lore) {
l.add(t.copy().styled(GuiHelpers.STYLE_CLEARER));
}

this.itemStack.set(DataComponentTypes.LORE, new LoreComponent(l));
return this;
}

/**
* Sets the lore lines of the element, without clearing out formatting.
*
* @param lore a list of all the lore lines
* @return this element builder
*/
public GuiElementBuilder setLoreRaw(List<Text> lore) {
this.itemStack.set(DataComponentTypes.LORE, new LoreComponent(lore));
return this;
}
Expand All @@ -173,6 +190,17 @@ public GuiElementBuilder setLore(List<Text> lore) {
* @return this element builder
*/
public GuiElementBuilder addLoreLine(Text lore) {
this.itemStack.apply(DataComponentTypes.LORE, LoreComponent.DEFAULT, lore.copy().styled(GuiHelpers.STYLE_CLEARER), LoreComponent::with);
return this;
}

/**
* Adds a line of lore to the element, without clearing out formatting.
*
* @param lore the line to add
* @return this element builder
*/
public GuiElementBuilder addLoreLineRaw(Text lore) {
this.itemStack.apply(DataComponentTypes.LORE, LoreComponent.DEFAULT, lore, LoreComponent::with);
return this;
}
Expand Down

0 comments on commit ab71ed8

Please sign in to comment.