Skip to content

Commit

Permalink
add recipes and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
IAFEnvoy committed Dec 24, 2024
1 parent c1395a7 commit 1070319
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 19 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Not Enough Economy

This mod add an item based economy system.

## Usage

### Coins

<img src="https://raw.githubusercontent.com/CodeOfArdonia/NotEnoughEconomy/refs/heads/master/img/1.webp" style="width:256px" alt="">

Coins are tools for trade.

### Exchange Station

<img src="https://raw.githubusercontent.com/CodeOfArdonia/NotEnoughEconomy/refs/heads/master/img/2.webp" style="width:256px" alt="">

Exchange Station is a place to exchange small charges.

### Cheque Table

<img src="https://raw.githubusercontent.com/CodeOfArdonia/NotEnoughEconomy/refs/heads/master/img/3.webp" style="width:256px" alt="">

You can make cheques with Cheque Table.
Place coins and empty cheque then click checkin can make cheques.
Put fulfilled cheques in the upper slot then click checkout can extract cheques.

### Trade Station

Who place the block will be the owner and have the following GUI where you can manage it.

<img src="https://raw.githubusercontent.com/CodeOfArdonia/NotEnoughEconomy/refs/heads/master/img/4.webp" style="width:256px" alt="">

The others will have another gui for trade.

<img src="https://raw.githubusercontent.com/CodeOfArdonia/NotEnoughEconomy/refs/heads/master/img/5.webp" style="width:256px" alt="">

There's another block named `System Trade Station`, which provide infinite goods. You can use it to make server shops.
Binary file added img/1.webp
Binary file not shown.
Binary file added img/2.webp
Binary file not shown.
Binary file added img/3.webp
Binary file not shown.
Binary file added img/4.webp
Binary file not shown.
Binary file added img/5.webp
Binary file not shown.
38 changes: 21 additions & 17 deletions src/main/java/com/iafenvoy/nee/util/InventoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ public static boolean hasAllItems(Inventory target, Inventory items) {
target = copy(target);
Map<ItemStack, Integer> itemsMap = new HashMap<>();
for (int i = 0; i < items.size(); i++) {
ItemStack stack = items.getStack(i);
ItemStack stack = items.getStack(i).copy();
itemsMap.put(stack, itemsMap.getOrDefault(stack, 0) + stack.getCount());
}
for (int i = 0; i < target.size(); i++) {
ItemStack targetStack = target.getStack(i);
for (Map.Entry<ItemStack, Integer> entry : itemsMap.entrySet()) {
ItemStack stack = entry.getKey();
int neededCount = entry.getValue();
if (ItemStack.canCombine(stack, targetStack) && targetStack.getCount() >= neededCount) {
itemsMap.put(stack, 0);
if (ItemStack.canCombine(stack, targetStack)) {
int count = targetStack.getCount();
if (count >= neededCount)
itemsMap.put(stack, 0);
else
itemsMap.put(stack, neededCount - count);
break;
}
}
Expand All @@ -46,7 +50,7 @@ public static void removeItems(Inventory target, Inventory items) {
if (ItemStack.canCombine(stack, targetStack)) {
int count = targetStack.getCount();
if (count >= neededCount) {
targetStack.setCount(count - neededCount);
targetStack.decrement(neededCount);
itemsMap.put(stack, 0);
break;
} else {
Expand Down Expand Up @@ -87,34 +91,34 @@ private static int getAvailableSpaceForItem(Inventory inventory, ItemStack stack
return availableSpace;
}

public static boolean insertItems(Inventory inventory, Inventory insert) {
public static void insertItems(Inventory inventory, Inventory insert) {
for (int i = 0; i < insert.size(); i++) {
ItemStack insertStack = insert.getStack(i);
if (insertStack != null) {
ItemStack copy = insertStack.copy();
if (!tryAddItemToInventory(inventory, copy))
return false;
}
if (insertStack != null)
tryAddItemToInventory(inventory, insertStack.copy());
}
return true;
}

private static boolean tryAddItemToInventory(Inventory inventory, ItemStack stack) {
if (stack.isEmpty()) return true;
private static void tryAddItemToInventory(Inventory inventory, ItemStack stack) {
if (stack.isEmpty()) return;
for (int i = 0; i < inventory.size(); i++) {
ItemStack inventoryStack = inventory.getStack(i);
if (inventoryStack == null || ItemStack.canCombine(inventoryStack, stack)) {
if (stack.getMaxCount() - (inventoryStack != null ? inventoryStack.getCount() : 0) > 0) {
int countToAdd = Math.min(stack.getCount(), stack.getMaxCount() - (inventoryStack != null ? inventoryStack.getCount() : 0));
if (inventoryStack == null) inventory.setStack(i, stack.copy());
else inventoryStack.setCount(inventoryStack.getCount() + countToAdd);
stack.setCount(stack.getCount() - countToAdd);
else inventoryStack.increment(countToAdd);
stack.decrement(countToAdd);
if (stack.getCount() == 0)
return true;
return;
}
}
}
return false;
for (int i = 0; i < inventory.size(); i++)
if (inventory.getStack(i).isEmpty()) {
inventory.setStack(i, stack);
break;
}
}

public static Inventory copy(Inventory another) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"credit": "Made with Blockbench",
"textures": {
"4": "not_enough_economy:block/exchange_station_1",
"6": "not_enough_economy:block/exchange_station_2"
"6": "not_enough_economy:block/exchange_station_2",
"particle": "not_enough_economy:block/exchange_station_2"
},
"elements": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"credit": "Made with Blockbench",
"textures": {
"4": "not_enough_economy:block/system_station_1",
"5": "not_enough_economy:block/system_station_2"
"5": "not_enough_economy:block/system_station_2",
"particle": "not_enough_economy:block/system_station_2"
},
"elements": [
{
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/data/not_enough_economy/recipes/cheque.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"item": "minecraft:paper"
},
{
"item": "minecraft:paper"
},
{
"item": "minecraft:paper"
},
{
"item": "minecraft:ink_sac"
},
{
"item": "minecraft:feather"
}
],
"result": {
"item": "not_enough_economy:cheque",
"count": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"SSS",
"SLS",
"S S"
],
"key": {
"S": {
"tag": "minecraft:stone_crafting_materials"
},
"L": {
"tag": "c:lapis"
}
},
"result": {
"item": "not_enough_economy:cheque_table"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"PEP",
"P P"
],
"key": {
"P": {
"tag": "minecraft:planks"
},
"E": {
"tag": "c:emeralds"
}
},
"result": {
"item": "not_enough_economy:exchange_station"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"SSS",
"SAS",
"S S"
],
"key": {
"S": {
"tag": "minecraft:stone_crafting_materials"
},
"A": {
"item": "minecraft:amethyst_shard"
}
},
"result": {
"item": "not_enough_economy:trade_station"
}
}

0 comments on commit 1070319

Please sign in to comment.