diff --git a/src/main/java/plus/dragons/createintegratedfarming/common/CIFCommon.java b/src/main/java/plus/dragons/createintegratedfarming/common/CIFCommon.java index 73bcd45..9661e1e 100644 --- a/src/main/java/plus/dragons/createintegratedfarming/common/CIFCommon.java +++ b/src/main/java/plus/dragons/createintegratedfarming/common/CIFCommon.java @@ -37,6 +37,7 @@ import plus.dragons.createintegratedfarming.common.farming.harvest.GlowBerryHarvestBehaviour; import plus.dragons.createintegratedfarming.common.fishing.net.FishingNetCatchProviders; import plus.dragons.createintegratedfarming.common.fishing.net.FishingNetMedium; +import plus.dragons.createintegratedfarming.common.fishing.net.FishingNetSailAttachment; import plus.dragons.createintegratedfarming.common.network.CIFPackets; import plus.dragons.createintegratedfarming.common.ranching.roost.display.RoostingDisplaySync; import plus.dragons.createintegratedfarming.common.registry.CIFArmInteractionPoints; @@ -108,6 +109,7 @@ public CIFCommon(IEventBus modBus, ModContainer modContainer) { REGISTRATE.registerEventListeners(modBus); CIFCreativeModeTabs.register(modBus); CIFBlocks.register(modBus); + FishingNetSailAttachment.register(); CIFBlockEntities.register(modBus); CIFArmInteractionPoints.register(modBus); CIFDataMaps.register(modBus); diff --git a/src/main/java/plus/dragons/createintegratedfarming/common/fishing/net/FishingNetSailAttachment.java b/src/main/java/plus/dragons/createintegratedfarming/common/fishing/net/FishingNetSailAttachment.java new file mode 100644 index 0000000..853783a --- /dev/null +++ b/src/main/java/plus/dragons/createintegratedfarming/common/fishing/net/FishingNetSailAttachment.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2025 DragonsPlus + * SPDX-License-Identifier: LGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package plus.dragons.createintegratedfarming.common.fishing.net; + +import com.simibubi.create.api.contraption.BlockMovementChecks; +import com.simibubi.create.api.contraption.BlockMovementChecks.CheckResult; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; + +/** Allows fishing nets to attach to contraptions like windmill sails, without needing super glue. */ +public final class FishingNetSailAttachment { + private FishingNetSailAttachment() {} + + public static void register() { + BlockMovementChecks.registerAttachedCheck(FishingNetSailAttachment::isAttachedTowards); + BlockMovementChecks.registerNotSupportiveCheck(FishingNetSailAttachment::isNotSupportive); + } + + private static CheckResult isAttachedTowards(BlockState state, Level level, BlockPos pos, Direction direction) { + if (!isFishingNet(state)) + return CheckResult.PASS; + return CheckResult.of(direction.getAxis() != state.getValue(DirectionalBlock.FACING).getAxis()); + } + + private static CheckResult isNotSupportive(BlockState state, Direction direction) { + if (!isFishingNet(state)) + return CheckResult.PASS; + return CheckResult.of(direction.getAxis() == state.getValue(DirectionalBlock.FACING).getAxis()); + } + + private static boolean isFishingNet(BlockState state) { + return state.getBlock() instanceof FishingNetBlock || state.getBlock() instanceof LavaFishingNetBlock; + } +}