-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to make sure that the BOWL is returned to the player after being cons…
…umed
- Loading branch information
Showing
9 changed files
with
137 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/megatrex4/ukrainian_dlight/item/BowlReturningFoodItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.megatrex4.ukrainian_dlight.item; | ||
|
||
import com.megatrex4.ukrainian_dlight.UkrainianDelight; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.world.World; | ||
|
||
public class BowlReturningFoodItem extends ToolTipHelper { | ||
|
||
public BowlReturningFoodItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) { | ||
// Use the item as usual | ||
ItemStack resultStack = super.finishUsing(stack, world, user); | ||
|
||
if (user instanceof PlayerEntity) { | ||
PlayerEntity player = (PlayerEntity) user; | ||
ItemStack bowlStack = new ItemStack(Items.BOWL); | ||
|
||
// Check if the player's inventory can accept the bowl | ||
boolean addedToInventory = player.getInventory().insertStack(bowlStack); | ||
|
||
// Log inventory addition attempt | ||
// UkrainianDelight.LOGGER.info("Attempting to add bowl to inventory: " + addedToInventory); | ||
|
||
// If not added to inventory, drop the bowl near the player | ||
if (!addedToInventory) { | ||
player.dropItem(bowlStack, false); | ||
// UkrainianDelight.LOGGER.info("Dropping bowl near player"); | ||
} | ||
} | ||
|
||
return stack.isEmpty() ? ItemStack.EMPTY : stack; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/megatrex4/ukrainian_dlight/item/ItemBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.megatrex4.ukrainian_dlight.item; | ||
|
||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; | ||
import net.minecraft.item.FoodComponent; | ||
import net.minecraft.item.Item; | ||
|
||
public class ItemBuilder { | ||
private FoodComponent foodComponent; | ||
private int maxCount = 64; | ||
private Boolean returnsBowl = null; | ||
|
||
public ItemBuilder food(FoodComponent foodComponent) { | ||
this.foodComponent = foodComponent; | ||
return this; | ||
} | ||
|
||
public ItemBuilder maxCount(int maxCount) { | ||
this.maxCount = maxCount; | ||
return this; | ||
} | ||
|
||
public ItemBuilder returnsBowl() { | ||
this.returnsBowl = true; | ||
return this; | ||
} | ||
|
||
public ItemBuilder returnsBowl(boolean returnsBowl) { | ||
this.returnsBowl = returnsBowl; | ||
return this; | ||
} | ||
|
||
public Item build() { | ||
FabricItemSettings settings = new FabricItemSettings().maxCount(maxCount); | ||
if (foodComponent != null) { | ||
settings.food(foodComponent); | ||
} | ||
if (returnsBowl == null || returnsBowl) { | ||
return new BowlReturningFoodItem(settings); | ||
} else { | ||
return new ToolTipHelper(settings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rainian_dlight/item/StatusEffectUtil.java → ...rainian_dlight/util/StatusEffectUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/resources/data/ukrainian_delight/advancements/borscht.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"display": { | ||
"icon": { | ||
"item": "ukrainian_delight:borscht" | ||
}, | ||
"title": { | ||
"translate": "ukrainian_delight.advancement.borscht" | ||
}, | ||
"description": { | ||
"translate": "ukrainian_delight.advancement.borscht.desc" | ||
}, | ||
"frame": "task", | ||
"show_toast": true, | ||
"announce_to_chat": true | ||
}, | ||
"parent": "ukrainian_delight:ukrainian_delight", | ||
"criteria": { | ||
"requirement": { | ||
"trigger": "minecraft:inventory_changed", | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"items": [ | ||
"ukrainian_delight:borscht" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters