mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-01 14:12:59 +00:00
Allow placing items against some blocks
We define a tag which allows specifying which blocks can be used. Right now this is is just cauldrons and hives, as they have "placing into" semantics. Closes #1305. Many thanks to Lindsay-Needs-Sleep for their initial work on this! Fixes #1008. I believe also fixes #854.
This commit is contained in:
1
projects/fabric/src/generated/resources/data/computercraft/tags/blocks/turtle_can_use.json
generated
Normal file
1
projects/fabric/src/generated/resources/data/computercraft/tags/blocks/turtle_can_use.json
generated
Normal file
@@ -0,0 +1 @@
|
||||
{"replace": false, "values": ["#minecraft:cauldrons", "#minecraft:beehives"]}
|
||||
@@ -77,10 +77,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.*;
|
||||
|
||||
@AutoService(dan200.computercraft.impl.PlatformHelper.class)
|
||||
public class PlatformHelperImpl implements PlatformHelper {
|
||||
@@ -303,10 +300,16 @@ public class PlatformHelperImpl implements PlatformHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(ServerPlayer player, ItemStack stack, BlockHitResult hit) {
|
||||
public InteractionResult useOn(ServerPlayer player, ItemStack stack, BlockHitResult hit, Predicate<BlockState> canUseBlock) {
|
||||
var result = UseBlockCallback.EVENT.invoker().interact(player, player.level, InteractionHand.MAIN_HAND, hit);
|
||||
if (result != InteractionResult.PASS) return result;
|
||||
|
||||
var block = player.level.getBlockState(hit.getBlockPos());
|
||||
if (!block.isAir() && canUseBlock.test(block)) {
|
||||
var useResult = block.use(player.level, player, InteractionHand.MAIN_HAND, hit);
|
||||
if (useResult.consumesAction()) return useResult;
|
||||
}
|
||||
|
||||
return stack.useOn(new UseOnContext(player, InteractionHand.MAIN_HAND, hit));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user