Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jun 5, 2024
1 parent a475d1c commit 28fd570
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 17 deletions.
12 changes: 6 additions & 6 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.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.10
minecraft_version=1.21-pre2
yarn_mappings=1.21-pre2+build.2
loader_version=0.15.11

#Fabric api
fabric_version=0.97.8+1.20.5
# Fabric API
fabric_version=0.99.4+1.21


# Mod Properties
mod_version = 1.5.1+1.20.5
mod_version = 1.6.0+1.21
maven_group = eu.pb4
archives_base_name = sgui

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
import net.minecraft.component.type.LoreComponent;
Expand All @@ -14,6 +14,10 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import net.minecraft.util.Rarity;
Expand Down Expand Up @@ -196,11 +200,11 @@ public AnimatedGuiElementBuilder noDefaults() {
}

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

public <T> AnimatedGuiElementBuilder setComponent(DataComponentType<T> type, @Nullable T value) {
public <T> AnimatedGuiElementBuilder setComponent(ComponentType<T> type, @Nullable T value) {
this.itemStack.set(type, value);
return this;
}
Expand Down Expand Up @@ -230,11 +234,35 @@ public AnimatedGuiElementBuilder hideDefaultTooltip() {
* @param level the level of the specified enchantment
* @return this element builder
*/
public AnimatedGuiElementBuilder enchant(Enchantment enchantment, int level) {
public AnimatedGuiElementBuilder enchant(RegistryEntry<Enchantment> enchantment, int level) {
this.itemStack.addEnchantment(enchantment, level);
return this;
}

/**
* Give the element the specified enchantment.
*
* @param server MinecraftServer
* @param enchantment the enchantment to apply
* @param level the level of the specified enchantment
* @return this element builder
*/
public AnimatedGuiElementBuilder enchant(MinecraftServer server, RegistryKey<Enchantment> enchantment, int level) {
return enchant(server.getRegistryManager(), enchantment, level);
}

/**
* Give the element the specified enchantment.
*
* @param lookup WrapperLookup
* @param enchantment the enchantment to apply
* @param level the level of the specified enchantment
* @return this element builder
*/
public AnimatedGuiElementBuilder enchant(RegistryWrapper.WrapperLookup lookup, RegistryKey<Enchantment> enchantment, int level) {
return enchant(lookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(enchantment), level);
}

/**
* Sets the element to have an enchantment glint.
*
Expand Down
36 changes: 32 additions & 4 deletions src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.CustomModelDataComponent;
import net.minecraft.component.type.LoreComponent;
Expand All @@ -14,6 +14,10 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.Text;
import net.minecraft.util.Rarity;
Expand Down Expand Up @@ -200,11 +204,11 @@ public GuiElementBuilder noDefaults() {
}

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

public <T> GuiElementBuilder setComponent(DataComponentType<T> type, @Nullable T value) {
public <T> GuiElementBuilder setComponent(ComponentType<T> type, @Nullable T value) {
this.itemStack.set(type, value);
return this;
}
Expand Down Expand Up @@ -243,11 +247,35 @@ public GuiElementBuilder hideTooltip() {
* @param level the level of the specified enchantment
* @return this element builder
*/
public GuiElementBuilder enchant(Enchantment enchantment, int level) {
public GuiElementBuilder enchant(RegistryEntry<Enchantment> enchantment, int level) {
this.itemStack.addEnchantment(enchantment, level);
return this;
}

/**
* Give the element the specified enchantment.
*
* @param server MinecraftServer
* @param enchantment the enchantment to apply
* @param level the level of the specified enchantment
* @return this element builder
*/
public GuiElementBuilder enchant(MinecraftServer server, RegistryKey<Enchantment> enchantment, int level) {
return enchant(server.getRegistryManager(), enchantment, level);
}

/**
* Give the element the specified enchantment.
*
* @param lookup WrapperLookup
* @param enchantment the enchantment to apply
* @param level the level of the specified enchantment
* @return this element builder
*/
public GuiElementBuilder enchant(RegistryWrapper.WrapperLookup lookup, RegistryKey<Enchantment> enchantment, int level) {
return enchant(lookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(enchantment), level);
}

/**
* Sets the element to have an enchantment glint.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co
private void sgui$catchRecipeRequests(CraftRequestC2SPacket packet, CallbackInfo ci) {
if (this.player.currentScreenHandler instanceof VirtualScreenHandler handler && handler.getGui() instanceof SimpleGui gui) {
try {
gui.onCraftRequest(packet.getRecipe(), packet.shouldCraftAll());
gui.onCraftRequest(packet.getRecipeId(), packet.shouldCraftAll());
} catch (Throwable e) {
handler.getGui().handleException(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/testmod/java/eu/pb4/sgui/testmod/SGuiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean canPlayerClose() {
.setItem(Items.NETHERITE_AXE).setDamage(150).saveItemStack()
.setItem(Items.DIAMOND_AXE).setDamage(150).unbreakable().saveItemStack()
.setItem(Items.GOLDEN_AXE).glow().saveItemStack()
.setItem(Items.IRON_AXE).enchant(Enchantments.AQUA_AFFINITY, 1).hideDefaultTooltip().saveItemStack()
.setItem(Items.IRON_AXE).enchant(objectCommandContext.getSource().getRegistryManager(), Enchantments.AQUA_AFFINITY, 1).hideDefaultTooltip().saveItemStack()
.setItem(Items.STONE_AXE).noDefaults().saveItemStack()
.setItem(Items.WOODEN_AXE).saveItemStack()
.setInterval(10).setRandom(true)
Expand Down Expand Up @@ -535,7 +535,7 @@ public boolean onSelectedSlotChange(int slot) {
.setItem(Items.NETHERITE_AXE).setDamage(150).saveItemStack()
.setItem(Items.DIAMOND_AXE).setDamage(150).unbreakable().saveItemStack()
.setItem(Items.GOLDEN_AXE).glow().saveItemStack()
.setItem(Items.IRON_AXE).enchant(Enchantments.AQUA_AFFINITY, 1).saveItemStack()
.setItem(Items.IRON_AXE).enchant(objectCommandContext.getSource().getRegistryManager(), Enchantments.AQUA_AFFINITY, 1).saveItemStack()
.setItem(Items.STONE_AXE).saveItemStack()
.setItem(Items.WOODEN_AXE).saveItemStack()
.setInterval(10).setRandom(true)
Expand Down

0 comments on commit 28fd570

Please sign in to comment.