Shift-right-click a block in improved_aerodynamics:flappable to make it a flap. G/H step the node's flap lever UP/TAKEOFF/LANDING; flaps slew to the configured angle, add lift and drag and raise the stall angle, and retract above a max speed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVREx3uo7nz1FEhzveWTUh
67 lines
2.9 KiB
Java
67 lines
2.9 KiB
Java
package dev.lumareth.improvedAerodynamics.flight;
|
|
|
|
import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.registries.Registries;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.tags.TagKey;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
/**
|
|
* Shift-right-click on a block in the {@code improved_aerodynamics:flappable} tag (Warium's horizontal control
|
|
* surfaces) with empty hands makes it a flap, or a normal control surface again. A flap follows the flap lever of the
|
|
* control node it is linked to, on top of the pilot's input.
|
|
*/
|
|
public final class FlapInteraction {
|
|
public static final TagKey<Block> FLAPPABLE = TagKey.create(Registries.BLOCK,
|
|
new ResourceLocation(ImprovedAerodynamics.MOD_ID, "flappable"));
|
|
|
|
private FlapInteraction() {
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
|
|
Player player = event.getEntity();
|
|
if (event.getHand() != InteractionHand.MAIN_HAND || !player.isShiftKeyDown() || player.isPassenger()
|
|
|| !player.getMainHandItem().isEmpty() || !player.getOffhandItem().isEmpty()) {
|
|
return;
|
|
}
|
|
Level level = event.getLevel();
|
|
BlockPos pos = event.getPos();
|
|
BlockState state = level.getBlockState(pos);
|
|
if (!state.is(FLAPPABLE)) {
|
|
return;
|
|
}
|
|
// Handled on both sides so the block's own right-click action does not run on either
|
|
event.setCanceled(true);
|
|
event.setCancellationResult(InteractionResult.sidedSuccess(level.isClientSide));
|
|
if (level.isClientSide) {
|
|
return;
|
|
}
|
|
BlockEntity blockEntity = level.getBlockEntity(pos);
|
|
if (blockEntity == null) {
|
|
return;
|
|
}
|
|
CompoundTag tag = blockEntity.getPersistentData();
|
|
boolean flap = !tag.getBoolean(WariumCapture.FLAP_TAG);
|
|
tag.putBoolean(WariumCapture.FLAP_TAG, flap);
|
|
blockEntity.setChanged();
|
|
if (flap && !tag.contains("ControlX")) {
|
|
player.displayClientMessage(Component.translatable("message.improved_aerodynamics.flap.unlinked"), true);
|
|
} else {
|
|
player.displayClientMessage(Component.translatable(flap
|
|
? "message.improved_aerodynamics.flap.on" : "message.improved_aerodynamics.flap.off"), true);
|
|
}
|
|
}
|
|
}
|