Skip to content

Commit 841c6a6

Browse files
committed
Pick Block finds block providers that can place blocks as well
1 parent 6c4c1de commit 841c6a6

File tree

7 files changed

+76
-0
lines changed

7 files changed

+76
-0
lines changed

Xplat/src/generated/resources/.cache/5e449fe289648869bd1f4d4d99715c8b4e0c057d

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Xplat/src/generated/resources/data/botania/tags/items/pickable_block_providers.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Xplat/src/main/java/vazkii/botania/common/lib/BotaniaTags.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public static class Items {
124124
public static final TagKey<Item> MANA_USING_ITEMS = tag("mana_using_items");
125125
public static final TagKey<Item> SEED_APOTHECARY_REAGENT = tag("seed_apothecary_reagent");
126126

127+
/**
128+
* Block provider items in this tag can be auto-selected via the vanilla "Pick Block" feature.
129+
* (Not every block provider makes sense here, e.g. the Hand of Ender cannot place blocks.)
130+
*/
131+
public static final TagKey<Item> PICKABLE_BLOCK_PROVIDER = tag("pickable_block_providers");
132+
127133
public static TagKey<Item> getPetalTag(DyeColor color) {
128134
return switch (color) {
129135
case WHITE -> PETALS_WHITE;

Xplat/src/main/java/vazkii/botania/data/ItemTagProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,8 @@ protected void addTags(HolderLookup.Provider provider) {
236236
this.tag(BotaniaTags.Items.SEED_APOTHECARY_REAGENT)
237237
.add(Items.WHEAT_SEEDS, Items.BEETROOT_SEEDS, Items.MELON_SEEDS, Items.PUMPKIN_SEEDS)
238238
.addOptionalTag(new ResourceLocation("forge", "seeds"));
239+
240+
this.tag(BotaniaTags.Items.PICKABLE_BLOCK_PROVIDER)
241+
.add(dirtRod, skyDirtRod, cobbleRod, blackHoleTalisman);
239242
}
240243
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package vazkii.botania.mixin;
2+
3+
import net.minecraft.core.NonNullList;
4+
import net.minecraft.world.entity.player.Inventory;
5+
import net.minecraft.world.entity.player.Player;
6+
import net.minecraft.world.item.BlockItem;
7+
import net.minecraft.world.item.ItemStack;
8+
import net.minecraft.world.level.block.Block;
9+
10+
import org.spongepowered.asm.mixin.Final;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Shadow;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
16+
17+
import vazkii.botania.common.lib.BotaniaTags;
18+
import vazkii.botania.xplat.XplatAbstractions;
19+
20+
@Mixin(Inventory.class)
21+
public class InventoryMixin {
22+
@Shadow
23+
@Final
24+
public Player player;
25+
26+
@Shadow
27+
@Final
28+
public NonNullList<ItemStack> items;
29+
30+
/**
31+
* Also look for block providers when picking a block, if the actual block item could not be found.
32+
*/
33+
@Inject(method = "findSlotMatchingItem", at = @At("RETURN"), cancellable = true)
34+
private void findBlockProviderItem(ItemStack searchStack, CallbackInfoReturnable<Integer> cir) {
35+
if (this.player.getAbilities().instabuild || cir.getReturnValue() != -1
36+
|| !(searchStack.getItem() instanceof BlockItem blockItem)) {
37+
// skip when in creative mode, when an exact match was already found, or when not looking for a block item
38+
return;
39+
}
40+
41+
Block block = blockItem.getBlock();
42+
for (int i = 0; i < this.items.size(); ++i) {
43+
ItemStack invStack = this.items.get(i);
44+
if (!invStack.is(BotaniaTags.Items.PICKABLE_BLOCK_PROVIDER)) {
45+
continue;
46+
}
47+
var provider = XplatAbstractions.INSTANCE.findBlockProvider(invStack);
48+
if (provider != null && provider.provideBlock(this.player, searchStack, block, false)) {
49+
cir.setReturnValue(i);
50+
return;
51+
}
52+
}
53+
}
54+
}

Xplat/src/main/resources/botania_xplat.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"HurtByTargetGoalAccessor",
3131
"HurtByTargetGoalMixin",
3232
"InventoryAccessor",
33+
"InventoryMixin",
3334
"ItemEntityAccessor",
3435
"ItemEntityMixin",
3536
"ItemMixin",

web/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ of time the maintainers are able to spend on this effort. For the time being, up
2424
* Add: Munchdew displays particles while in cooldown, similar to a Thermalily (this used to be a thing a long time ago already, but somehow got lost)
2525
* Change: Sparks can no longer be hit by projectiles other than mana bursts
2626
* Change: Fake players using a wand of the forest on either type of spark are now treated as if the player was sneaking, since that is likely the intended interaction
27+
* Add: While not in Creative mode, the "Pick Block" feature (usually middle mouse button) can also select certain block
28+
providers, such as the Rod of the Lands or Black Hole Talisman, if the targeted block's item itself is not available
2729
* Fix: The boss bar for the gaia ritual no longer starts full and quickly empties at the start of the spawn sequence
2830
* Fix: Potential NullPointerException in Bergamute's SoundEngineMixin (LostLuma)
2931
* Fix: Potential divide-by-zero error related to Runic Altar wand HUD rendering (YukkuriC)

0 commit comments

Comments
 (0)