Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"minecraft:detector_rail",
"minecraft:powered_rail",
"minecraft:note_block",
"minecraft:jukebox",
"minecraft:observer",
"minecraft:hopper",
"minecraft:dropper",
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/dev/dubhe/anvilcraft/block/HeavyIronBeamBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class HeavyIronBeamBlock extends Block implements IHammerRemovable, HammerRotateBehavior {

Expand All @@ -33,7 +36,6 @@ public HeavyIronBeamBlock(Properties properties) {
registerDefaultState(getStateDefinition().any().setValue(AXIS, Direction.Axis.X));
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState()
Expand Down Expand Up @@ -61,6 +63,19 @@ public VoxelShape getShape(
};
}

@Override
public boolean change(Player player, BlockPos blockPos, Level level, ItemStack anvilHammer) {
BlockState state = level.getBlockState(blockPos);
Direction.Axis newAxis = state.getValue(AXIS) == Direction.Axis.X ? Direction.Axis.Z : Direction.Axis.X;
level.setBlockAndUpdate(blockPos, state.setValue(AXIS, newAxis));
return true;
}

@Override
public Property<?> getChangeableProperty(BlockState blockState) {
return AXIS;
}

@Override
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class WheelLifecycleEventListener {

private static long multiphaseKeyTime = -1L;
private static boolean multiphaseKeyWasDown = false;
private static boolean multiphaseKeyPressAccepted = false;
private static @Nullable Optional<WheelMenuModel> multiphaseWheelCache = null;

private static long resonatorKeyTime = -1L;
Expand Down Expand Up @@ -620,6 +621,10 @@ public static void onKeyInput(InputEvent.MouseButton.Post event) {
private static void processMultiphasePress(Minecraft client, int action) {
if (client.level == null) return;
if (action == GLFW.GLFW_RELEASE) {
if (!WheelLifecycleEventListener.multiphaseKeyPressAccepted) {
return;
}
WheelLifecycleEventListener.multiphaseKeyPressAccepted = false;
if (WheelLifecycleEventListener.multiphaseKeyWasDown) {
CONTROLLER.onHoldKeyReleased();
} else {
Expand All @@ -632,6 +637,7 @@ private static void processMultiphasePress(Minecraft client, int action) {
}
if (Minecraft.getInstance().screen != null) return;
if (action == GLFW.GLFW_PRESS) {
WheelLifecycleEventListener.multiphaseKeyPressAccepted = true;
if (!WheelLifecycleEventListener.multiphaseKeyWasDown) {
WheelLifecycleEventListener.multiphaseKeyTime = client.level.getGameTime();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static void init(RegistrumTagsProvider<Block> provider) {
.add(findResourceKey(Blocks.DETECTOR_RAIL))
.add(findResourceKey(Blocks.POWERED_RAIL))
.add(findResourceKey(Blocks.NOTE_BLOCK))
.add(findResourceKey(Blocks.JUKEBOX))
.add(findResourceKey(Blocks.OBSERVER))
.add(findResourceKey(Blocks.HOPPER))
.add(findResourceKey(Blocks.DROPPER))
Expand Down