1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-09-02 02:27:56 +00:00

Merge branch 'mc-1.20.x' into mc-1.21.x

This commit is contained in:
Jonathan Coates
2025-03-16 16:28:53 +00:00
131 changed files with 571 additions and 9186 deletions

View File

@@ -106,7 +106,6 @@ public class ComputerCraft {
ServerChunkEvents.CHUNK_UNLOAD.register((l, c) -> CommonHooks.onServerChunkUnload(c));
PlayerBlockBreakEvents.BEFORE.register(FabricCommonHooks::onBlockDestroy);
UseBlockCallback.EVENT.register(FabricCommonHooks::useOnBlock);
UseBlockCallback.EVENT.register(CommonHooks::onUseBlock);
LootTableEvents.MODIFY.register((id, tableBuilder, source, registries) -> {

View File

@@ -4,51 +4,16 @@
package dan200.computercraft.shared;
import dan200.computercraft.shared.media.items.DiskItem;
import dan200.computercraft.shared.peripheral.modem.wired.CableBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jspecify.annotations.Nullable;
public class FabricCommonHooks {
public static boolean onBlockDestroy(Level level, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity) {
return !(state.getBlock() instanceof CableBlock cable) || !cable.onCustomDestroyBlock(state, level, pos, player);
}
/**
* Allow placing disks/treasure disks into disk drives by clicking on them.
*
* @param player The player placing the block.
* @param level The current level.
* @param hand The player's hand.
* @param hitResult The hit collision.
* @return Whether this interaction succeeded.
* @see ServerPlayerGameMode#useItemOn(ServerPlayer, Level, ItemStack, InteractionHand, BlockHitResult) The original source of this logic.
*/
public static InteractionResult useOnBlock(Player player, Level level, InteractionHand hand, BlockHitResult hitResult) {
if (player.isSpectator()) return InteractionResult.PASS;
var block = level.getBlockState(hitResult.getBlockPos());
if (block.getBlock() != ModRegistry.Blocks.DISK_DRIVE.get()) return InteractionResult.PASS;
if (player.isSecondaryUseActive() && doesSneakBypassUse(player.getMainHandItem()) && doesSneakBypassUse(player.getOffhandItem())) {
var result = block.useItemOn(player.getMainHandItem(), level, player, hand, hitResult);
if (result.consumesAction()) return result.result();
}
return InteractionResult.PASS;
}
private static boolean doesSneakBypassUse(ItemStack stack) {
return stack.isEmpty() || stack.getItem() instanceof DiskItem;
}
}