forked from Anvil-Dev/AnvilCraft
-
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.
Merge pull request Anvil-Dev#928 from Gu-ZT/seeds_pack
种子袋
- Loading branch information
Showing
21 changed files
with
195 additions
and
0 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
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
38 changes: 38 additions & 0 deletions
38
common/src/main/java/dev/dubhe/anvilcraft/item/SeedsPackItem.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,38 @@ | ||
package dev.dubhe.anvilcraft.item; | ||
|
||
import dev.dubhe.anvilcraft.init.ModItemTags; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class SeedsPackItem extends Item { | ||
public SeedsPackItem(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public @NotNull InteractionResultHolder<ItemStack> use( | ||
@NotNull Level level, @NotNull Player player, @NotNull InteractionHand usedHand | ||
) { | ||
ItemStack stack = player.getItemInHand(usedHand); | ||
RandomSource random = level.getRandom(); | ||
List<Item> items = BuiltInRegistries.ITEM.getOrCreateTag(ModItemTags.SEEDS_PACK_CONTENT) | ||
.stream() | ||
.filter(Holder::isBound) | ||
.map(Holder::value) | ||
.toList(); | ||
if (items.isEmpty()) return InteractionResultHolder.fail(stack); | ||
player.getInventory().placeItemBackInInventory(new ItemStack(items.get(random.nextInt(items.size())))); | ||
stack.shrink(1); | ||
return InteractionResultHolder.consume(stack); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
fabric/src/generated/resources/assets/anvilcraft/models/item/seeds_pack.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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "anvilcraft:item/seeds_pack" | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
fabric/src/generated/resources/data/anvilcraft/tags/items/seeds_pack_content.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,29 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
{ | ||
"id": "#c:seeds", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#c:berries", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#c:vegetables", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#forge:seeds", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#forge:berries", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#forge:vegetables", | ||
"required": false | ||
} | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
fabric/src/generated/resources/data/c/tags/items/berries.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:sweet_berries", | ||
"minecraft:glow_berries" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
fabric/src/generated/resources/data/c/tags/items/vegetables.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:potato", | ||
"minecraft:carrot" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
fabric/src/generated/resources/data/forge/tags/items/berries.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:sweet_berries", | ||
"minecraft:glow_berries" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
fabric/src/generated/resources/data/forge/tags/items/vegetables.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:potato", | ||
"minecraft:carrot" | ||
] | ||
} |
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
6 changes: 6 additions & 0 deletions
6
forge/src/generated/resources/assets/anvilcraft/models/item/seeds_pack.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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "anvilcraft:item/seeds_pack" | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
forge/src/generated/resources/data/anvilcraft/tags/items/seeds_pack_content.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,29 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
{ | ||
"id": "#c:seeds", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#c:berries", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#c:vegetables", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#forge:seeds", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#forge:berries", | ||
"required": false | ||
}, | ||
{ | ||
"id": "#forge:vegetables", | ||
"required": false | ||
} | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:sweet_berries", | ||
"minecraft:glow_berries" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
forge/src/generated/resources/data/c/tags/items/vegetables.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:potato", | ||
"minecraft:carrot" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
forge/src/generated/resources/data/forge/tags/items/berries.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:sweet_berries", | ||
"minecraft:glow_berries" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
forge/src/generated/resources/data/forge/tags/items/vegetables.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,7 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:potato", | ||
"minecraft:carrot" | ||
] | ||
} |