mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-16 13:17:10 +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/forge/src/generated/resources/data/computercraft/tags/blocks/turtle_can_use.json
generated
Normal file
1
projects/forge/src/generated/resources/data/computercraft/tags/blocks/turtle_can_use.json
generated
Normal file
@@ -0,0 +1 @@
|
||||
{"values": ["#minecraft:cauldrons", "#minecraft:beehives"]}
|
||||
@@ -74,10 +74,7 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
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 {
|
||||
@@ -318,17 +315,25 @@ 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 level = player.level;
|
||||
var pos = hit.getBlockPos();
|
||||
var event = ForgeHooks.onRightClickBlock(player, InteractionHand.MAIN_HAND, pos, hit);
|
||||
if (event.isCanceled()) return event.getCancellationResult();
|
||||
|
||||
var context = new UseOnContext(player, InteractionHand.MAIN_HAND, hit);
|
||||
if (event.getUseItem() == Event.Result.DENY) return InteractionResult.PASS;
|
||||
if (event.getUseItem() != Event.Result.DENY) {
|
||||
var result = stack.onItemUseFirst(context);
|
||||
if (result != InteractionResult.PASS) return result;
|
||||
}
|
||||
|
||||
var result = stack.onItemUseFirst(context);
|
||||
return result != InteractionResult.PASS ? result : stack.useOn(context);
|
||||
var block = level.getBlockState(hit.getBlockPos());
|
||||
if (event.getUseBlock() != Event.Result.DENY && !block.isAir() && canUseBlock.test(block)) {
|
||||
var useResult = block.use(level, player, InteractionHand.MAIN_HAND, hit);
|
||||
if (useResult.consumesAction()) return useResult;
|
||||
}
|
||||
|
||||
return event.getUseItem() == Event.Result.DENY ? InteractionResult.PASS : stack.useOn(context);
|
||||
}
|
||||
|
||||
private record RegistryWrapperImpl<T>(
|
||||
|
||||
Reference in New Issue
Block a user