-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bulk quiver is a quiver that supplies arrows after the main inventory empies of arrows. Lets you save some slots for arrows In the future two alternatives will be added, one for trick arrows to use before the inventory, and one infinity alternative
- Loading branch information
1 parent
3aee0c0
commit 2aa8e67
Showing
14 changed files
with
254 additions
and
24 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/generated/resources/data/tconstruct/recipes/tools/modifiers/ability/bulk_quiver.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,30 @@ | ||
{ | ||
"type": "tconstruct:modifier", | ||
"inputs": [ | ||
{ | ||
"item": "minecraft:leather" | ||
}, | ||
{ | ||
"item": "tconstruct:sky_slime_vine" | ||
}, | ||
{ | ||
"item": "minecraft:leather" | ||
}, | ||
{ | ||
"item": "tconstruct:sky_slime_vine" | ||
}, | ||
{ | ||
"item": "tconstruct:sky_slime_vine" | ||
} | ||
], | ||
"tools": { | ||
"tag": "tconstruct:modifiable/ranged/bows" | ||
}, | ||
"slots": { | ||
"abilities": 1 | ||
}, | ||
"result": { | ||
"name": "tconstruct:bulk_quiver", | ||
"level": 1 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...erated/resources/data/tconstruct/recipes/tools/modifiers/salvage/ability/bulk_quiver.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,11 @@ | ||
{ | ||
"type": "tconstruct:modifier_salvage", | ||
"tools": { | ||
"tag": "tconstruct:modifiable/ranged/bows" | ||
}, | ||
"slots": { | ||
"abilities": 1 | ||
}, | ||
"modifier": "tconstruct:bulk_quiver", | ||
"min_level": 1 | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/slimeknights/tconstruct/library/modifiers/hook/BowAmmoModifierHook.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,39 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Hook to find ammo on a bow | ||
*/ | ||
public interface BowAmmoModifierHook { | ||
/** Default instance */ | ||
BowAmmoModifierHook EMPTY = (tool, modifier, shooter, standardAmmo, ammoPredicate) -> ItemStack.EMPTY; | ||
|
||
/** | ||
* Finds the ammo. Does *not* modify the tool, this method may be called without loosing an arrow | ||
* @param tool Tool instance | ||
* @param modifier Modifier being called | ||
* @param shooter Entity using the bow | ||
* @param standardAmmo Arrows found in the player inventory. Will be empty if not found | ||
* @param ammoPredicate Predicate from the bow of types of ammo it accepts | ||
* @return Item stack of ammo found. If empty, will continue searching for ammo elsewhere until falling back to standard ammo | ||
*/ | ||
ItemStack findAmmo(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, ItemStack standardAmmo, Predicate<ItemStack> ammoPredicate); | ||
|
||
/** | ||
* Callback to shrink the ammo returned by {@link #findAmmo(IToolStackView, ModifierEntry, LivingEntity, ItemStack, Predicate)}. | ||
* Will only be called on the modifier that returned non-empty in the previous method | ||
* @param tool Tool instance | ||
* @param modifier Modifier instance | ||
* @param shooter Entity shooting the ammo | ||
* @param ammo Ammo that was found | ||
*/ | ||
default void shrinkAmmo(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, ItemStack ammo) { | ||
ammo.shrink(1); | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
src/main/java/slimeknights/tconstruct/tools/modifiers/ability/ranged/BulkQuiverModifier.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,76 @@ | ||
package slimeknights.tconstruct.tools.modifiers.ability.ranged; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ArrowItem; | ||
import net.minecraft.world.item.ItemStack; | ||
import slimeknights.tconstruct.TConstruct; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.BowAmmoModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.impl.InventoryModifier; | ||
import slimeknights.tconstruct.library.modifiers.util.ModifierHookMap.Builder; | ||
import slimeknights.tconstruct.library.recipe.partbuilder.Pattern; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
import slimeknights.tconstruct.library.tools.nbt.ModDataNBT; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.function.Predicate; | ||
|
||
public class BulkQuiverModifier extends InventoryModifier implements BowAmmoModifierHook { | ||
private static final ResourceLocation INVENTORY_KEY = TConstruct.getResource("bulk_quiver"); | ||
private static final ResourceLocation LAST_SLOT = TConstruct.getResource("quiver_last_selected"); | ||
private static final Pattern ARROW = new Pattern(TConstruct.getResource("arrow")); | ||
public BulkQuiverModifier() { | ||
super(INVENTORY_KEY, 2); | ||
} | ||
|
||
@Override | ||
protected void registerHooks(Builder hookBuilder) { | ||
super.registerHooks(hookBuilder); | ||
hookBuilder.addHook(this, TinkerHooks.BOW_AMMO); | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(IToolStackView tool, ModifierEntry modifier, int slot, ItemStack stack) { | ||
return stack.getItem() instanceof ArrowItem; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Pattern getPattern(IToolStackView tool, ModifierEntry modifier, int slot, boolean hasStack) { | ||
return hasStack ? null : ARROW; | ||
} | ||
|
||
@Override | ||
public ItemStack findAmmo(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, ItemStack standardAmmo, Predicate<ItemStack> ammoPredicate) { | ||
// skip if we have standard ammo, this quiver holds backup arrows | ||
if (!standardAmmo.isEmpty()) { | ||
return ItemStack.EMPTY; | ||
} | ||
ModDataNBT persistentData = tool.getPersistentData(); | ||
ResourceLocation key = getInventoryKey(); | ||
ListTag slots = persistentData.get(key, GET_COMPOUND_LIST); | ||
if (!slots.isEmpty()) { | ||
// search all slots for the first match | ||
for (int i = 0; i < slots.size(); i++) { | ||
CompoundTag compound = slots.getCompound(i); | ||
ItemStack stack = ItemStack.of(compound); | ||
if (!stack.isEmpty() && ammoPredicate.test(stack)) { | ||
persistentData.putInt(LAST_SLOT, compound.getInt(TAG_SLOT)); | ||
return stack; | ||
} | ||
} | ||
} | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
@Override | ||
public void shrinkAmmo(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, ItemStack ammo) { | ||
// we assume no one else touched the quiver inventory, this is a good assumption, do not make it a bad assumption by modifying the quiver in other modifiers | ||
ammo.shrink(1); | ||
setStack(tool, modifier, tool.getPersistentData().getInt((LAST_SLOT)), ammo); | ||
} | ||
} |
Oops, something went wrong.