Add BlockItemProvider capability to allow alternative sources of blocks for modifiers like Exchanging#5568
Conversation
.../slimeknights/tconstruct/library/tools/capability/inventory/BlockItemProviderCapability.java
Outdated
Show resolved
Hide resolved
This could always be done by putting the capability in charge of placing the block to some degree. Default impl runs block item placement, but you could do an impl for placement from other sources. Related, if we are going to place in exchanging here, we should place from ichors fluid effect in the same way. We do not, however, need to use this capability for the fixed block forms of fluid effects, just the one that selects block from the offhand. |
After implementing this I have realised that theres nowhere in Tinkers (or in the compat I had planned for Botania) where this would actually be used, as they all consume from the inventory anyway. This means I can't test it without some annoying additional useless code. I've committed and pushed this code to my fork on a different branch in case its useful to anyone, but will leave it out of this PR. |
|
Should be ready to go now. If the default BlockItem cap does end up being a performance issue then additional context could be added to the |
|
Actually turns out that the Botania integration I am thinking of requires some extra context like that, so time to rewrite it a bit. |
…an be used and player context can be provided
|
One thing to consider here is if tools such as those with glowing should implement this capability to provide glows. |
…more sense than inventory I think
…ith exchanging and ichor.
There was a problem hiding this comment.
Apart from cosmetics, just have three concerns:
- If two different modifiers implement the new hook, the merging will simply ignore the second. It should try each hook until it finds the first with a nonnull block item.
- Place block fluid effect has some issues with how it handles
placeRestricted. - Seems you need a rebase, as when you implemented the glowing changes it conflicted with an older feature related to the tooltips.
Otherwise looks pretty good as a way to bring back that behavior with exchanging.
src/main/java/slimeknights/tconstruct/library/modifiers/ModifierHooks.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/modifiers/fluid/block/PlaceBlockFluidEffect.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/modifiers/fluid/block/PlaceBlockFluidEffect.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/modifiers/fluid/block/PlaceBlockFluidEffect.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/modifiers/fluid/block/PlaceBlockFluidEffect.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/tools/capability/ToolBlockItemProviderHook.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/shared/TinkerCommons.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/tools/data/ModifierProvider.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/tools/modifiers/ability/tool/ExchangingModifier.java
Outdated
Show resolved
Hide resolved
...java/slimeknights/tconstruct/library/modifiers/modules/behavior/BlockItemProviderModule.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/tools/modifiers/BlockItemProviderModule.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/tools/capability/ToolBlockItemProviderHook.java
Outdated
Show resolved
Hide resolved
# Conflicts: # src/generated/resources/data/tconstruct/tinkering/modifiers/glowing.json # src/main/java/slimeknights/tconstruct/tools/TinkerModifiers.java # src/main/java/slimeknights/tconstruct/tools/data/ModifierProvider.java # src/main/java/slimeknights/tconstruct/tools/modules/interaction/PlaceGlowModule.java # src/main/java/slimeknights/tconstruct/tools/modules/ranged/common/ProjectilePlaceGlowModule.java
…to provide a backing stack.
Important due to it now having a BlockItem that uses canSurvive to determine suitable placement places.
src/main/java/slimeknights/tconstruct/library/tools/capability/BlockItemProviderCapability.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/tools/capability/ToolBlockItemProviderHook.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/shared/TinkerCommons.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/tools/capability/ToolBlockItemProviderHook.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/tools/capability/ToolBlockItemProviderHook.java
Outdated
Show resolved
Hide resolved
src/main/java/slimeknights/tconstruct/library/tools/capability/ToolBlockItemProviderHook.java
Outdated
Show resolved
Hide resolved
| ToolBlockItemProviderHook provider = entry.getModifier().getHooks().getOrNull(ModifierHooks.BLOCK_ITEM_PROVIDER); | ||
| if (provider != null && provider.consumeBlockItem(tool, capStack, entry, backingStack, entity)) { |
There was a problem hiding this comment.
if (entry.getHook(ModifierHooks.BLOCK_ITEM_PROVIDER).consumeBlockItem(...))
| BlockPos pos = context.getPos(); | ||
| if (offhand.isEmpty() || !(offhand.getItem() instanceof BlockItem blockItem)) { | ||
| LivingEntity entity = context.getLiving(); | ||
| if (item.isEmpty()) return null; |
There was a problem hiding this comment.
This causes an issue where empty offhand blocks us from using mainhand's glowing.
This adds a capability
BlockItemProviderCapabilitythat can be added to ItemStacks to let them provide block items. This is intended for compatibility with other mods like Botania that add items that place blocks at the cost of things such as Mana, or hold large numbers of a single block.BlockItem rather than Block was chosen as the current exchanging logic works off BlockItem, however looking into other places that use
instanceof BlockItemthere are alternatives for placing the block 'manually' which may be added to Exchanging and the capability swapped to directly use Blocks.Additionally a new modifier hook has been added to provide a blockitem (at the cost of durability), which glowing uses to provide glows.
TODO: