Skip to content
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}+$minecraft_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

include(implementation("com.electronwill.night-config:toml:3.6.0"))

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.4
minecraft_version=24w06a
parchment_version=2023.09.03
loader_version=0.15.6

Expand All @@ -14,4 +14,4 @@ maven_group=com.kirbosoftware
archives_base_name=poyolib

# Dependencies
fabric_version=0.95.4
fabric_version=0.96.1+1.20.5
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kirbosoftware.poyolib.api.item.armor;

import net.minecraft.core.Holder;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;

Expand All @@ -8,44 +9,44 @@ public class ArmorBuilder {
public static class Helmet extends ArmorItem {
/**
* Creates a helmet with the chosen materials.
* @param material The armor material.
* @param holder The armor material.
* @param properties Item properties.
*/
public Helmet(ArmorMaterial material, Properties properties) {
super(material, Type.HELMET, properties.stacksTo(1));
public Helmet(Holder<ArmorMaterial> holder, Properties properties) {
super(holder, Type.HELMET, properties.stacksTo(1));
}
}

public static class Chestplate extends ArmorItem {
/**
* Creates a chestplate with the chosen materials.
* @param material The armor material.
* @param holder The armor material.
* @param properties Item properties.
*/
public Chestplate(ArmorMaterial material, Properties properties) {
super(material, Type.CHESTPLATE, properties.stacksTo(1));
public Chestplate(Holder<ArmorMaterial> holder, Properties properties) {
super(holder, Type.CHESTPLATE, properties.stacksTo(1));
}
}

public static class Leggings extends ArmorItem {
/**
* Creates a pair of leggings with the chosen materials.
* @param material The armor material.
* @param holder The armor material.
* @param properties Item properties.
*/
public Leggings(ArmorMaterial material, Properties properties) {
super(material, Type.LEGGINGS, properties.stacksTo(1));
public Leggings(Holder<ArmorMaterial> holder, Properties properties) {
super(holder, Type.LEGGINGS, properties.stacksTo(1));
}
}

public static class Boots extends ArmorItem {
/**
* Creates a pair of boots with the chosen materials.
* @param material The armor material.
* @param holder The armor material.
* @param properties Item properties.
*/
public Boots(ArmorMaterial material, Properties properties) {
super(material, Type.BOOTS, properties.stacksTo(1));
public Boots(Holder<ArmorMaterial> holder, Properties properties) {
super(holder, Type.BOOTS, properties.stacksTo(1));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kirbosoftware.poyolib.api.item.craft;

import net.minecraft.util.RandomSource;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

Expand Down Expand Up @@ -38,11 +37,13 @@ public boolean canBeDepleted() {
*/
@Override
public ItemStack getRecipeRemainder(ItemStack stack) {
ItemStack copy = stack.copy();
if (copy.hurt(1, RandomSource.create(), null))
return ItemStack.EMPTY;
else
if (stack.getDamageValue() < stack.getMaxDamage() - 1) {
ItemStack copy = stack.copy();
copy.setDamageValue(stack.getDamageValue() + 1);
return copy;
} else {
return ItemStack.EMPTY;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kirbosoftware.poyolib.api.item.craft;

import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.TieredItem;
Expand Down Expand Up @@ -39,11 +38,13 @@ public boolean canBeDepleted() {
*/
@Override
public ItemStack getRecipeRemainder(ItemStack stack) {
ItemStack copy = stack.copy();
if (copy.hurt(1, RandomSource.create(), null))
return ItemStack.EMPTY;
else
if (stack.getDamageValue() < stack.getMaxDamage() - 1) {
ItemStack copy = stack.copy();
copy.setDamageValue(stack.getDamageValue() + 1);
return copy;
} else {
return ItemStack.EMPTY;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Villager Trade Helper

This is a simple helper method to adjust villager trades upon your need.

## Example

This is how you would alter a villager's trade based upon it's ItemListing. Super easy and useful to do!
```java
import com.kirbosoftware.poyolib.api.world.entity.npc.VillagerTradeHelper;
import net.minecraft.world.entity.npc.VillagerProfession;

public class ModifyTrades {
public static void init() {
VillagerTradeHelper.modifyTrades(villagerProfession, tier, tradeList -> {
tradeList.add("tradeList");
tradeList.add("tradeList");
});
// or
VillagerTradeHelper.modifyTrades(villagerProfession, tier, tradeId, "tradeList");
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.kirbosoftware.poyolib.api.world.entity.npc;

import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerTrades;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
* The {@code VillagerTradeHelper} class provides utility methods for modifying trades of villagers.
* These methods can be used to customize the trades offered by villagers based on their profession and tier.
*
* <p>Usage example:</p>
* <pre>
* {@code
* // Modify trades using a consumer
* VillagerTradeHelper.modifyTrades(VillagerProfession.FARMER, 1, tradeList -> {
* // Add or modify trades in the provided list
* tradeList.add(new VillagerTrades.ItemListing(...));
* // Additional trade modifications...
* });
*
* // Modify a specific trade using an ItemListing factory
* VillagerTradeHelper.modifyTrades(VillagerProfession.FISHERMAN, 2, 0, new VillagerTrades.ItemListing(...));
* }
* </pre>
*
* <p>Note: It is important to handle trades carefully to avoid unintended consequences.</p>
*/
@SuppressWarnings("unused")
public class VillagerTradeHelper {

/**
* Modifies the trades for a specific villager profession and tier using a consumer.
*
* @param profession The villager's profession.
* @param tier The tier of the trades to be modified.
* @param factory A consumer providing a list of {@code ItemListing} to be added or modified.
*/
public static void modifyTrades(VillagerProfession profession, int tier, Consumer<List<VillagerTrades.ItemListing>> factory) {
List<VillagerTrades.ItemListing> list = new ArrayList<>();
factory.accept(list);
VillagerTrades.ItemListing[] originalEntries = VillagerTrades.TRADES.get(profession).get(tier);
VillagerTrades.ItemListing[] modifiedEntries = list.toArray(new VillagerTrades.ItemListing[0]);
System.arraycopy(modifiedEntries, 0, originalEntries, 0, modifiedEntries.length);
}

/**
* Modifies a specific trade for a given villager profession, tier, and trade ID.
*
* @param profession The villager's profession.
* @param tier The tier of the trade to be modified.
* @param tradeId The ID of the trade within the specified tier.
* @param factory The {@code ItemListing} to replace the existing trade.
*/
public static void modifyTrades(VillagerProfession profession, int tier, int tradeId, VillagerTrades.ItemListing factory) {
VillagerTrades.TRADES.get(profession).get(tier)[tradeId] = factory;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"poyolib.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.21",
"fabricloader": ">=0.15.6",
"minecraft": ">=1.20",
"java": ">=17"
},
Expand Down