Allow rotating stuff with wrench.
This commit is contained in:
@@ -8,11 +8,32 @@ import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class WrenchItem extends ModItem {
|
||||
@Override
|
||||
public ActionResultType onItemUseFirst(final ItemStack stack, final ItemUseContext context) {
|
||||
final World level = context.getLevel();
|
||||
final BlockPos pos = context.getClickedPos();
|
||||
final Direction face = context.getClickedFace();
|
||||
if (face == Direction.UP || face == Direction.DOWN) {
|
||||
final BlockState blockState = level.getBlockState(pos);
|
||||
final BlockState rotatedState = blockState.rotate(level, pos, face == Direction.UP ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90);
|
||||
if (!Objects.equals(blockState, rotatedState)) {
|
||||
level.setBlockAndUpdate(pos, rotatedState);
|
||||
return ActionResultType.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
}
|
||||
|
||||
return super.onItemUseFirst(stack, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType useOn(final ItemUseContext context) {
|
||||
final PlayerEntity player = context.getPlayer();
|
||||
|
||||
Reference in New Issue
Block a user