Skip to content

Commit

Permalink
Finish up the 1.20.5 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Apr 18, 2024
1 parent b45d6c4 commit 5401ecc
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
# Use these Java versions
java: [
17 # Latest version
21 # Latest version
]
# and run on both Linux and Windows
os: [ubuntu-20.04, windows-latest]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=24w13a
yarn_mappings=24w13a+build.2
loader_version=0.15.7
minecraft_version=1.20.5-rc1
yarn_mappings=1.20.5-rc1+build.1
loader_version=0.15.10

#Fabric api
fabric_version=0.96.12+1.20.5
fabric_version=0.97.3+1.20.5


# Mod Properties
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 net.minecraft.component.DataComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
import net.minecraft.component.type.LoreComponent;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.item.Items;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import net.minecraft.util.Rarity;
import net.minecraft.util.Unit;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -98,7 +100,18 @@ public AnimatedGuiElementBuilder setItem(Item item) {
* @return this element builder
*/
public AnimatedGuiElementBuilder setName(Text name) {
this.itemStack.set(DataComponentTypes.CUSTOM_NAME, name.copy());
this.itemStack.set(DataComponentTypes.ITEM_NAME, name.copy());
return this;
}

/**
* Sets the rarity of the element.
*
* @param rarity to use
* @return this element builder
*/
public AnimatedGuiElementBuilder setRarity(Rarity rarity) {
this.itemStack.set(DataComponentTypes.RARITY, rarity);
return this;
}

Expand All @@ -113,6 +126,17 @@ public AnimatedGuiElementBuilder setCount(int count) {
return this;
}

/**
* Sets the max number of items in the element.
*
* @param count the number of items
* @return this element builder
*/
public AnimatedGuiElementBuilder setMaxCount(int count) {
this.itemStack.set(DataComponentTypes.MAX_STACK_SIZE, count);
return this;
}

/**
* Sets the lore lines of the element.
*
Expand Down Expand Up @@ -148,12 +172,53 @@ public AnimatedGuiElementBuilder setDamage(int damage) {
}

/**
* Hides all Tooltips added through this builder from the element display
* Set the max damage of the element.
*
* @param damage the amount of durability the item is missing
* @return this element builder
*/
public AnimatedGuiElementBuilder setMaxDamage(int damage) {
this.itemStack.set(DataComponentTypes.MAX_DAMAGE, damage);
return this;
}

/**
* Disables all default components on an item.
* @return this element builder
*/
public AnimatedGuiElementBuilder noDefaults() {
for (var x : this.itemStack.getItem().getComponents()) {
if (this.itemStack.get(x.type()) == x.value()) {
this.itemStack.set(x.type(), null);
}
}
return this;
}

@Nullable
public <T> T getComponent(DataComponentType<T> type) {
return this.itemStack.get(type);
}

public <T> AnimatedGuiElementBuilder setComponent(DataComponentType<T> type, @Nullable T value) {
this.itemStack.set(type, value);
return this;
}

/**
* Hides all component-item related tooltip added by item's or non name/lore components.
*
* @return this element builder
*/
public AnimatedGuiElementBuilder hideFlags() {
// TODO 1.20.5
public AnimatedGuiElementBuilder hideDefaultTooltip() {
this.itemStack.apply(DataComponentTypes.TRIM, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.UNBREAKABLE, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.ENCHANTMENTS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.STORED_ENCHANTMENTS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.ATTRIBUTE_MODIFIERS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.DYED_COLOR, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.CAN_BREAK, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.CAN_PLACE_ON, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.set(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);
return this;
}
Expand All @@ -180,6 +245,16 @@ public AnimatedGuiElementBuilder glow() {
return this;
}

/**
* Sets the element to have an enchantment glint.
*
* @return this element builder
*/
public AnimatedGuiElementBuilder glow(boolean value) {
this.itemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, value);
return this;
}

/**
* Sets the custom model data of the element.
*
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/eu/pb4/sgui/api/elements/BookElementBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public BookElementBuilder addPage(Text... lines) {
}

public BookElementBuilder addPage(Text text) {
this.getOrCreatePages().add(NbtString.of(Text.Serialization.toJsonString(text)));
this.itemStack.apply(DataComponentTypes.WRITTEN_BOOK_CONTENT, DEFAULT_WRITTEN_COMPONENT, original -> {
List<RawFilteredPair<Text>> updatedPages = new LinkedList<>(original.pages());
updatedPages.add(RawFilteredPair.of(text));
return new WrittenBookContentComponent(original.title(), original.author(), original.generation(), updatedPages, original.resolved());
});
return this;
}

Expand Down Expand Up @@ -101,7 +105,11 @@ public BookElementBuilder setPage(int index, Text... lines) {
}

public BookElementBuilder setPage(int index, Text text) {
this.getOrCreatePages().set(index, NbtString.of(Text.Serialization.toJsonString(text)));
this.itemStack.apply(DataComponentTypes.WRITTEN_BOOK_CONTENT, DEFAULT_WRITTEN_COMPONENT, original -> {
List<RawFilteredPair<Text>> updatedPages = new LinkedList<>(original.pages());
updatedPages.set(index, RawFilteredPair.of(text));
return new WrittenBookContentComponent(original.title(), original.author(), original.generation(), updatedPages, original.resolved());
});
return this;
}

Expand Down
102 changes: 96 additions & 6 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 net.minecraft.component.DataComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
import net.minecraft.component.type.LoreComponent;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.item.Items;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import net.minecraft.util.Rarity;
import net.minecraft.util.Unit;
import org.jetbrains.annotations.Nullable;

Expand All @@ -28,8 +30,8 @@
*
* @see GuiElementBuilderInterface
*/
@SuppressWarnings({"unused"})
public class GuiElementBuilder implements GuiElementBuilderInterface<GuiElementBuilder> {
@SuppressWarnings({"unused", "rawtypes"})
public class GuiElementBuilder implements GuiElementBuilderInterface {
protected ItemStack itemStack = new ItemStack(Items.STONE);
protected GuiElement.ClickCallback callback = GuiElementInterface.EMPTY_CALLBACK;

Expand Down Expand Up @@ -101,7 +103,18 @@ public GuiElementBuilder setItem(Item item) {
* @return this element builder
*/
public GuiElementBuilder setName(Text name) {
this.itemStack.set(DataComponentTypes.CUSTOM_NAME, name.copy());
this.itemStack.set(DataComponentTypes.ITEM_NAME, name.copy());
return this;
}

/**
* Sets the rarity of the element.
*
* @param rarity to use
* @return this element builder
*/
public GuiElementBuilder setRarity(Rarity rarity) {
this.itemStack.set(DataComponentTypes.RARITY, rarity);
return this;
}

Expand All @@ -116,6 +129,18 @@ public GuiElementBuilder setCount(int count) {
return this;
}


/**
* Sets the max number of items in the element.
*
* @param count the number of items
* @return this element builder
*/
public GuiElementBuilder setMaxCount(int count) {
this.itemStack.set(DataComponentTypes.MAX_STACK_SIZE, count);
return this;
}

/**
* Sets the lore lines of the element.
*
Expand Down Expand Up @@ -151,16 +176,66 @@ public GuiElementBuilder setDamage(int damage) {
}

/**
* Hides all Tooltips added through this builder from the element display
* Set the max damage of the element.
*
* @param damage the amount of durability the item is missing
* @return this element builder
*/
public GuiElementBuilder hideFlags() {
// TODO 1.20.5
public GuiElementBuilder setMaxDamage(int damage) {
this.itemStack.set(DataComponentTypes.MAX_DAMAGE, damage);
return this;
}

/**
* Disables all default components on an item.
* @return this element builder
*/
public GuiElementBuilder noDefaults() {
for (var x : this.itemStack.getItem().getComponents()) {
if (this.itemStack.get(x.type()) == x.value()) {
this.itemStack.set(x.type(), null);
}
}
return this;
}

@Nullable
public <T> T getComponent(DataComponentType<T> type) {
return this.itemStack.get(type);
}

public <T> GuiElementBuilder setComponent(DataComponentType<T> type, @Nullable T value) {
this.itemStack.set(type, value);
return this;
}

/**
* Hides all component-item related tooltip added by item's or non name/lore components.
*
* @return this element builder
*/
public GuiElementBuilder hideDefaultTooltip() {
this.itemStack.apply(DataComponentTypes.TRIM, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.UNBREAKABLE, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.ENCHANTMENTS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.STORED_ENCHANTMENTS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.ATTRIBUTE_MODIFIERS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.DYED_COLOR, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.CAN_BREAK, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.apply(DataComponentTypes.CAN_PLACE_ON, null, comp -> comp != null ? comp.withShowInTooltip(false) : null);
this.itemStack.set(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);
return this;
}

/**
* Hides tooltip completely, making it never show
* @return this element builder
*/
public GuiElementBuilder hideTooltip() {
this.itemStack.set(DataComponentTypes.HIDE_TOOLTIP, Unit.INSTANCE);
return this;
}

/**
* Give the element the specified enchantment.
*
Expand All @@ -183,6 +258,16 @@ public GuiElementBuilder glow() {
return this;
}

/**
* Sets the element to have an enchantment glint.
*
* @return this element builder
*/
public GuiElementBuilder glow(boolean value) {
this.itemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, value);
return this;
}

/**
* Sets the custom model data of the element.
*
Expand Down Expand Up @@ -287,4 +372,9 @@ public ItemStack asStack() {
public GuiElement build() {
return new GuiElement(this.itemStack, this.callback);
}

@Deprecated(forRemoval = true)
public GuiElementBuilder hideFlags() {
return this.hideDefaultTooltip();
}
}
2 changes: 1 addition & 1 deletion src/main/java/eu/pb4/sgui/api/gui/SlotGuiInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ default boolean insertItem(ItemStack stack, int startIndex, int endIndex, boolea
slot = this.getSlotRedirectOrPlayer(i);
if (slot != null && slot.canInsert(stack)) {
itemStack = slot.getStack();
if (!itemStack.isEmpty() && ItemStack.canCombine(stack, itemStack)) {
if (!itemStack.isEmpty() && ItemStack.areItemsAndComponentsEqual(stack, itemStack)) {
int j = itemStack.getCount() + stack.getCount();
if (j <= stack.getMaxCount()) {
stack.setCount(0);
Expand Down
Loading

0 comments on commit 5401ecc

Please sign in to comment.