1
0
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:
Jonathan Coates
2023-03-04 18:17:23 +00:00
parent 566315947b
commit 118d04f018
12 changed files with 65 additions and 33 deletions

View File

@@ -0,0 +1 @@
{"replace": false, "values": ["#minecraft:cauldrons", "#minecraft:beehives"]}

View File

@@ -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));
}